Alexander Potapenko
165a007e51
ipv4, ipv6: ensure raw socket message is big enough to hold an IP header
...
[ Upstream commit 86f4c90a1c5c1493f07f2d12c1079f5bf01936f2 ]
raw_send_hdrinc() and rawv6_send_hdrinc() expect that the buffer copied
from the userspace contains the IPv4/IPv6 header, so if too few bytes are
copied, parts of the header may remain uninitialized.
This bug has been detected with KMSAN.
For the record, the KMSAN report:
==================================================================
BUG: KMSAN: use of unitialized memory in nf_ct_frag6_gather+0xf5a/0x44a0
inter: 0
CPU: 0 PID: 1036 Comm: probe Not tainted 4.11.0-rc5+ #2455
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:16
dump_stack+0x143/0x1b0 lib/dump_stack.c:52
kmsan_report+0x16b/0x1e0 mm/kmsan/kmsan.c:1078
__kmsan_warning_32+0x5c/0xa0 mm/kmsan/kmsan_instr.c:510
nf_ct_frag6_gather+0xf5a/0x44a0 net/ipv6/netfilter/nf_conntrack_reasm.c:577
ipv6_defrag+0x1d9/0x280 net/ipv6/netfilter/nf_defrag_ipv6_hooks.c:68
nf_hook_entry_hookfn ./include/linux/netfilter.h:102
nf_hook_slow+0x13f/0x3c0 net/netfilter/core.c:310
nf_hook ./include/linux/netfilter.h:212
NF_HOOK ./include/linux/netfilter.h:255
rawv6_send_hdrinc net/ipv6/raw.c:673
rawv6_sendmsg+0x2fcb/0x41a0 net/ipv6/raw.c:919
inet_sendmsg+0x3f8/0x6d0 net/ipv4/af_inet.c:762
sock_sendmsg_nosec net/socket.c:633
sock_sendmsg net/socket.c:643
SYSC_sendto+0x6a5/0x7c0 net/socket.c:1696
SyS_sendto+0xbc/0xe0 net/socket.c:1664
do_syscall_64+0x72/0xa0 arch/x86/entry/common.c:285
entry_SYSCALL64_slow_path+0x25/0x25 arch/x86/entry/entry_64.S:246
RIP: 0033:0x436e03
RSP: 002b:00007ffce48baf38 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 00000000004002b0 RCX: 0000000000436e03
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 00007ffce48baf90 R08: 00007ffce48baf50 R09: 000000000000001c
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000401790 R14: 0000000000401820 R15: 0000000000000000
origin: 00000000d9400053
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
kmsan_save_stack_with_flags mm/kmsan/kmsan.c:362
kmsan_internal_poison_shadow+0xb1/0x1a0 mm/kmsan/kmsan.c:257
kmsan_poison_shadow+0x6d/0xc0 mm/kmsan/kmsan.c:270
slab_alloc_node mm/slub.c:2735
__kmalloc_node_track_caller+0x1f4/0x390 mm/slub.c:4341
__kmalloc_reserve net/core/skbuff.c:138
__alloc_skb+0x2cd/0x740 net/core/skbuff.c:231
alloc_skb ./include/linux/skbuff.h:933
alloc_skb_with_frags+0x209/0xbc0 net/core/skbuff.c:4678
sock_alloc_send_pskb+0x9ff/0xe00 net/core/sock.c:1903
sock_alloc_send_skb+0xe4/0x100 net/core/sock.c:1920
rawv6_send_hdrinc net/ipv6/raw.c:638
rawv6_sendmsg+0x2918/0x41a0 net/ipv6/raw.c:919
inet_sendmsg+0x3f8/0x6d0 net/ipv4/af_inet.c:762
sock_sendmsg_nosec net/socket.c:633
sock_sendmsg net/socket.c:643
SYSC_sendto+0x6a5/0x7c0 net/socket.c:1696
SyS_sendto+0xbc/0xe0 net/socket.c:1664
do_syscall_64+0x72/0xa0 arch/x86/entry/common.c:285
return_from_SYSCALL_64+0x0/0x6a arch/x86/entry/entry_64.S:246
==================================================================
, triggered by the following syscalls:
socket(PF_INET6, SOCK_RAW, IPPROTO_RAW) = 3
sendto(3, NULL, 0, 0, {sa_family=AF_INET6, sin6_port=htons(0), inet_pton(AF_INET6, "ff00::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = -1 EPERM
A similar report is triggered in net/ipv4/raw.c if we use a PF_INET socket
instead of a PF_INET6 one.
Signed-off-by: Alexander Potapenko <glider@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-14 14:06:02 +02:00
..
2017-01-22 16:46:13 -05:00
2017-04-17 14:23:20 -04:00
2016-12-24 11:46:01 -08:00
2017-02-06 11:25:57 -05:00
2017-02-27 18:43:47 -08:00
2017-03-09 18:23:27 -08:00
2017-03-09 18:23:27 -08:00
2017-03-16 12:05:38 -07:00
2017-03-09 18:23:27 -08:00
2017-04-25 14:02:39 -04:00
2017-03-02 08:42:29 +01:00
2017-01-30 11:05:04 +01:00
2017-03-23 12:03:36 +01:00
2017-04-28 16:06:47 -04:00
2016-12-03 23:54:25 -05:00
2017-03-13 22:00:42 -07:00
2017-03-09 18:23:27 -08:00
2017-03-03 10:16:38 -08:00
2017-02-11 02:31:11 -05:00
2017-02-16 21:25:49 -05:00
2017-02-21 13:25:22 -05:00
2017-02-27 18:43:47 -08:00
2017-02-03 15:16:45 -05:00
2017-05-14 14:06:02 +02:00
2017-05-14 14:06:02 +02:00
2016-12-25 17:21:22 +01:00
2017-03-09 18:23:27 -08:00
2017-03-09 18:23:27 -08:00
2017-03-24 13:13:53 -07:00
2017-04-18 08:26:03 +02:00
2017-04-08 08:29:04 -07:00
2016-09-10 23:12:53 -07:00
2016-12-24 11:46:01 -08:00
2017-03-09 18:23:27 -08:00
2017-04-20 15:37:46 -04:00
2017-03-02 08:42:38 +01:00
2017-03-16 20:22:18 -07:00
2016-10-20 11:23:08 -04:00
2017-04-13 23:20:13 +02:00
2017-01-06 22:20:45 -05:00
2017-03-22 15:38:43 -07:00
2017-03-09 18:23:27 -08:00
2017-03-09 18:23:27 -08:00
2017-04-01 12:16:46 -07:00
2017-04-25 14:05:52 -04:00
2017-03-09 18:23:27 -08:00
2017-01-24 13:44:28 -05:00
2017-04-21 15:19:27 -04:00
2017-03-09 18:23:27 -08:00
2017-01-24 11:07:35 +01:00
2017-03-09 18:23:27 -08:00
2017-03-16 21:27:57 -07:00
2017-04-20 16:32:07 -04:00
2017-04-06 13:55:51 -07:00
2017-03-09 18:23:27 -08:00
2017-03-03 20:43:26 -08:00
2017-04-01 10:43:37 -07:00
2016-10-30 12:42:58 -04:00
2017-04-28 12:20:42 -04:00
2017-03-21 15:25:10 -07:00
2017-03-21 14:41:47 -07:00
2016-10-27 16:16:09 -04:00
2017-03-29 09:11:29 +02:00
2017-03-09 18:23:27 -08:00
2017-04-27 12:20:19 +02:00
2017-02-22 10:15:09 -08:00
2017-02-17 13:40:05 -05:00
2017-02-03 15:16:45 -05:00
2017-03-21 18:44:17 -07:00
2016-10-06 09:52:23 -07:00