Alexander Potapenko
b1f5bfc27a
sctp: don't dereference ptr before leaving _sctp_walk_{params, errors}()
If the length field of the iterator (|pos.p| or |err|) is past the end
of the chunk, we shouldn't access it.
This bug has been detected by KMSAN. For the following pair of system
calls:
socket(PF_INET6, SOCK_STREAM, 0x84 /* IPPROTO_??? */) = 3
sendto(3, "A", 1, MSG_OOB, {sa_family=AF_INET6, sin6_port=htons(0),
inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=0,
sin6_scope_id=0}, 28) = 1
the tool has reported a use of uninitialized memory:
==================================================================
BUG: KMSAN: use of uninitialized memory in sctp_rcv+0x17b8/0x43b0
CPU: 1 PID: 2940 Comm: probe Not tainted 4.11.0-rc5+ #2926
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs
01/01/2011
Call Trace:
<IRQ>
__dump_stack lib/dump_stack.c:16
dump_stack+0x172/0x1c0 lib/dump_stack.c:52
kmsan_report+0x12a/0x180 mm/kmsan/kmsan.c:927
__msan_warning_32+0x61/0xb0 mm/kmsan/kmsan_instr.c:469
__sctp_rcv_init_lookup net/sctp/input.c:1074
__sctp_rcv_lookup_harder net/sctp/input.c:1233
__sctp_rcv_lookup net/sctp/input.c:1255
sctp_rcv+0x17b8/0x43b0 net/sctp/input.c:170
sctp6_rcv+0x32/0x70 net/sctp/ipv6.c:984
ip6_input_finish+0x82f/0x1ee0 net/ipv6/ip6_input.c:279
NF_HOOK ./include/linux/netfilter.h:257
ip6_input+0x239/0x290 net/ipv6/ip6_input.c:322
dst_input ./include/net/dst.h:492
ip6_rcv_finish net/ipv6/ip6_input.c:69
NF_HOOK ./include/linux/netfilter.h:257
ipv6_rcv+0x1dbd/0x22e0 net/ipv6/ip6_input.c:203
__netif_receive_skb_core+0x2f6f/0x3a20 net/core/dev.c:4208
__netif_receive_skb net/core/dev.c:4246
process_backlog+0x667/0xba0 net/core/dev.c:4866
napi_poll net/core/dev.c:5268
net_rx_action+0xc95/0x1590 net/core/dev.c:5333
__do_softirq+0x485/0x942 kernel/softirq.c:284
do_softirq_own_stack+0x1c/0x30 arch/x86/entry/entry_64.S:902
</IRQ>
do_softirq kernel/softirq.c:328
__local_bh_enable_ip+0x25b/0x290 kernel/softirq.c:181
local_bh_enable+0x37/0x40 ./include/linux/bottom_half.h:31
rcu_read_unlock_bh ./include/linux/rcupdate.h:931
ip6_finish_output2+0x19b2/0x1cf0 net/ipv6/ip6_output.c:124
ip6_finish_output+0x764/0x970 net/ipv6/ip6_output.c:149
NF_HOOK_COND ./include/linux/netfilter.h:246
ip6_output+0x456/0x520 net/ipv6/ip6_output.c:163
dst_output ./include/net/dst.h:486
NF_HOOK ./include/linux/netfilter.h:257
ip6_xmit+0x1841/0x1c00 net/ipv6/ip6_output.c:261
sctp_v6_xmit+0x3b7/0x470 net/sctp/ipv6.c:225
sctp_packet_transmit+0x38cb/0x3a20 net/sctp/output.c:632
sctp_outq_flush+0xeb3/0x46e0 net/sctp/outqueue.c:885
sctp_outq_uncork+0xb2/0xd0 net/sctp/outqueue.c:750
sctp_side_effects net/sctp/sm_sideeffect.c:1773
sctp_do_sm+0x6962/0x6ec0 net/sctp/sm_sideeffect.c:1147
sctp_primitive_ASSOCIATE+0x12c/0x160 net/sctp/primitive.c:88
sctp_sendmsg+0x43e5/0x4f90 net/sctp/socket.c:1954
inet_sendmsg+0x498/0x670 net/ipv4/af_inet.c:762
sock_sendmsg_nosec net/socket.c:633
sock_sendmsg net/socket.c:643
SYSC_sendto+0x608/0x710 net/socket.c:1696
SyS_sendto+0x8a/0xb0 net/socket.c:1664
do_syscall_64+0xe6/0x130 arch/x86/entry/common.c:285
entry_SYSCALL64_slow_path+0x25/0x25 arch/x86/entry/entry_64.S:246
RIP: 0033:0x401133
RSP: 002b:00007fff6d99cd38 EFLAGS: 00000246 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 00000000004002b0 RCX: 0000000000401133
RDX: 0000000000000001 RSI: 0000000000494088 RDI: 0000000000000003
RBP: 00007fff6d99cd90 R08: 00007fff6d99cd50 R09: 000000000000001c
R10: 0000000000000001 R11: 0000000000000246 R12: 0000000000000000
R13: 00000000004063d0 R14: 0000000000406460 R15: 0000000000000000
origin:
save_stack_trace+0x37/0x40 arch/x86/kernel/stacktrace.c:59
kmsan_save_stack_with_flags mm/kmsan/kmsan.c:302
kmsan_internal_poison_shadow+0xb1/0x1a0 mm/kmsan/kmsan.c:198
kmsan_poison_shadow+0x6d/0xc0 mm/kmsan/kmsan.c:211
slab_alloc_node mm/slub.c:2743
__kmalloc_node_track_caller+0x200/0x360 mm/slub.c:4351
__kmalloc_reserve net/core/skbuff.c:138
__alloc_skb+0x26b/0x840 net/core/skbuff.c:231
alloc_skb ./include/linux/skbuff.h:933
sctp_packet_transmit+0x31e/0x3a20 net/sctp/output.c:570
sctp_outq_flush+0xeb3/0x46e0 net/sctp/outqueue.c:885
sctp_outq_uncork+0xb2/0xd0 net/sctp/outqueue.c:750
sctp_side_effects net/sctp/sm_sideeffect.c:1773
sctp_do_sm+0x6962/0x6ec0 net/sctp/sm_sideeffect.c:1147
sctp_primitive_ASSOCIATE+0x12c/0x160 net/sctp/primitive.c:88
sctp_sendmsg+0x43e5/0x4f90 net/sctp/socket.c:1954
inet_sendmsg+0x498/0x670 net/ipv4/af_inet.c:762
sock_sendmsg_nosec net/socket.c:633
sock_sendmsg net/socket.c:643
SYSC_sendto+0x608/0x710 net/socket.c:1696
SyS_sendto+0x8a/0xb0 net/socket.c:1664
do_syscall_64+0xe6/0x130 arch/x86/entry/common.c:285
return_from_SYSCALL_64+0x0/0x6a arch/x86/entry/entry_64.S:246
==================================================================
Signed-off-by: Alexander Potapenko <glider@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-07-15 14:39:41 -07:00
..
2017-01-12 04:01:17 -05:00
2017-05-18 13:52:49 +02:00
2017-03-09 17:01:09 -08:00
2015-09-21 16:03:04 -07:00
2017-07-01 07:39:07 -07:00
2017-06-08 10:53:29 -04:00
2017-04-05 10:15:20 +02:00
2016-02-11 03:54:14 -05:00
2017-07-15 14:39:41 -07:00
2017-06-06 12:45:23 -04:00
2017-04-12 22:02:36 +02:00
2017-05-17 15:22:13 -04:00
2017-07-04 01:29:04 -07:00
2015-09-17 13:20:05 +02:00
2017-06-07 17:15:46 +01:00
2017-07-05 12:31:59 -07:00
2017-04-24 12:35:56 -04:00
2017-07-01 07:39:07 -07:00
2017-07-04 22:35:19 +01:00
2016-02-09 04:45:49 -05:00
2017-05-27 18:51:41 -04:00
2017-04-21 15:28:37 -04:00
2017-03-24 20:49:31 -07:00
2017-07-04 22:35:16 +01:00
2017-06-13 11:04:37 +02:00
2016-07-08 12:20:57 +02:00
2017-01-20 12:12:13 -05:00
2017-07-04 01:29:04 -07:00
2016-04-19 20:09:25 -04:00
2016-04-25 16:44:27 -04:00
2016-06-25 12:19:35 -04:00
2016-04-25 16:44:27 -04:00
2016-06-09 23:41:03 -07:00
2017-04-22 20:26:37 +03:00
2017-07-04 22:35:15 +01:00
2015-09-17 17:18:37 -07:00
2017-06-13 16:35:03 -04:00
2016-02-16 20:21:48 -05:00
2017-06-25 11:42:01 -04:00
2017-02-07 13:07:46 -05:00
2017-06-17 22:54:01 -04:00
2017-04-14 10:06:42 +02:00
2015-09-23 15:33:15 -07:00
2017-07-01 07:39:09 -07:00
2017-06-04 18:12:23 -04:00
2017-04-03 19:04:48 -07:00
2017-04-03 19:04:48 -07:00
2016-05-20 18:03:16 -04:00
2016-09-30 13:29:21 +02:00
2016-09-30 13:29:21 +02:00
2016-12-05 15:21:59 -05:00
2017-06-05 10:54:55 -04:00
2016-06-17 20:23:32 -07:00
2016-08-18 01:17:32 -04:00
2017-02-08 14:38:18 -05:00
2016-07-25 17:55:43 -07:00
2016-03-14 12:19:46 -04:00
2016-04-27 22:48:25 -04:00
2017-01-25 16:00:33 +01:00
2016-01-04 20:40:41 +01:00
2017-07-04 01:29:04 -07:00
2017-02-03 15:16:45 -05:00
2015-12-15 23:25:20 -05:00
2017-01-18 13:04:28 -05:00
2016-04-04 22:11:20 -04:00
2017-03-09 18:23:27 -08:00
2017-06-15 12:12:40 -04:00
2016-08-13 15:08:00 -07:00
2017-07-06 08:59:41 -07:00
2017-07-03 03:29:14 -07:00
2017-01-25 14:04:38 -05:00
2016-12-29 11:38:31 -05:00
2017-07-01 07:39:07 -07:00
2016-03-13 23:55:13 -04:00
2017-06-17 22:54:01 -04:00
2017-07-06 10:48:01 +01:00
2017-04-21 13:21:30 -04:00
2017-07-04 01:29:04 -07:00
2017-04-21 13:21:31 -04:00
2017-04-28 12:00:10 +02:00
2017-04-13 13:19:48 -04:00
2017-07-04 01:29:03 -07:00
2017-07-04 22:35:17 +01:00
2017-01-13 09:38:42 +01:00
2016-08-17 19:36:23 -04:00
2016-10-13 12:05:26 -04:00
2017-07-04 22:35:16 +01:00
2015-05-11 10:50:17 -04:00
2017-07-04 22:35:15 +01:00
2017-05-30 11:55:32 -04:00
2017-06-08 14:16:29 +02:00
2016-07-08 13:23:12 +02:00
2017-04-01 20:21:44 -07:00
2016-10-03 02:00:22 -04:00
2016-10-04 02:11:51 -04:00
2017-07-01 07:39:07 -07:00
2017-07-01 07:39:07 -07:00
2017-07-01 07:39:09 -07:00
2016-07-05 09:06:29 -07:00
2017-07-01 07:39:09 -07:00
2017-07-13 09:26:27 -07:00
2015-12-08 22:02:33 -05:00
2017-07-04 22:35:17 +01:00
2016-07-08 12:20:57 +02:00
2016-03-23 22:09:58 -04:00
2017-05-31 17:58:13 -04:00
2017-05-17 15:22:13 -04:00
2016-08-15 10:55:53 -07:00
2017-03-24 13:17:07 -07:00
2017-01-24 13:44:28 -05:00
2016-10-23 19:35:24 -04:00
2016-10-23 19:35:24 -04:00
2016-12-25 17:21:22 +01:00
2017-07-01 07:39:08 -07:00
2017-06-17 22:54:00 -04:00
2017-06-26 23:13:22 -04:00
2017-07-04 22:35:16 +01:00
2017-03-02 08:42:31 +01:00
2017-06-08 10:53:29 -04:00
2016-11-09 20:40:06 -05:00
2016-11-09 20:40:06 -05:00
2017-01-09 16:07:41 -05:00
2016-04-28 11:49:45 -04:00
2016-01-19 14:44:23 -05:00
2017-07-12 14:39:43 -07:00
2016-08-28 23:32:41 -04:00
2017-07-01 08:51:32 -07:00
2017-07-01 16:15:14 -07:00
2015-07-09 15:12:20 -07:00
2017-06-15 12:12:40 -04:00
2016-05-03 16:08:14 -04:00
2015-10-26 22:24:22 -07:00
2016-06-17 20:23:32 -07:00
2017-06-27 15:43:56 -04:00
2017-05-16 15:41:29 -04:00
2017-07-04 22:35:15 +01:00
2017-06-14 13:52:44 +02:00
2017-07-04 22:35:18 +01:00
2017-07-04 22:35:18 +01:00