Eric Dumazet
c92e8c02fe
tcp/dccp: fix ireq->opt races
syzkaller found another bug in DCCP/TCP stacks [1]
For the reasons explained in commit ce1050089c96 ("tcp/dccp: fix
ireq->pktopts race"), we need to make sure we do not access
ireq->opt unless we own the request sock.
Note the opt field is renamed to ireq_opt to ease grep games.
[1]
BUG: KASAN: use-after-free in ip_queue_xmit+0x1687/0x18e0 net/ipv4/ip_output.c:474
Read of size 1 at addr ffff8801c951039c by task syz-executor5/3295
CPU: 1 PID: 3295 Comm: syz-executor5 Not tainted 4.14.0-rc4+ #80
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:16 [inline]
dump_stack+0x194/0x257 lib/dump_stack.c:52
print_address_description+0x73/0x250 mm/kasan/report.c:252
kasan_report_error mm/kasan/report.c:351 [inline]
kasan_report+0x25b/0x340 mm/kasan/report.c:409
__asan_report_load1_noabort+0x14/0x20 mm/kasan/report.c:427
ip_queue_xmit+0x1687/0x18e0 net/ipv4/ip_output.c:474
tcp_transmit_skb+0x1ab7/0x3840 net/ipv4/tcp_output.c:1135
tcp_send_ack.part.37+0x3bb/0x650 net/ipv4/tcp_output.c:3587
tcp_send_ack+0x49/0x60 net/ipv4/tcp_output.c:3557
__tcp_ack_snd_check+0x2c6/0x4b0 net/ipv4/tcp_input.c:5072
tcp_ack_snd_check net/ipv4/tcp_input.c:5085 [inline]
tcp_rcv_state_process+0x2eff/0x4850 net/ipv4/tcp_input.c:6071
tcp_child_process+0x342/0x990 net/ipv4/tcp_minisocks.c:816
tcp_v4_rcv+0x1827/0x2f80 net/ipv4/tcp_ipv4.c:1682
ip_local_deliver_finish+0x2e2/0xba0 net/ipv4/ip_input.c:216
NF_HOOK include/linux/netfilter.h:249 [inline]
ip_local_deliver+0x1ce/0x6e0 net/ipv4/ip_input.c:257
dst_input include/net/dst.h:464 [inline]
ip_rcv_finish+0x887/0x19a0 net/ipv4/ip_input.c:397
NF_HOOK include/linux/netfilter.h:249 [inline]
ip_rcv+0xc3f/0x1820 net/ipv4/ip_input.c:493
__netif_receive_skb_core+0x1a3e/0x34b0 net/core/dev.c:4476
__netif_receive_skb+0x2c/0x1b0 net/core/dev.c:4514
netif_receive_skb_internal+0x10b/0x670 net/core/dev.c:4587
netif_receive_skb+0xae/0x390 net/core/dev.c:4611
tun_rx_batched.isra.50+0x5ed/0x860 drivers/net/tun.c:1372
tun_get_user+0x249c/0x36d0 drivers/net/tun.c:1766
tun_chr_write_iter+0xbf/0x160 drivers/net/tun.c:1792
call_write_iter include/linux/fs.h:1770 [inline]
new_sync_write fs/read_write.c:468 [inline]
__vfs_write+0x68a/0x970 fs/read_write.c:481
vfs_write+0x18f/0x510 fs/read_write.c:543
SYSC_write fs/read_write.c:588 [inline]
SyS_write+0xef/0x220 fs/read_write.c:580
entry_SYSCALL_64_fastpath+0x1f/0xbe
RIP: 0033:0x40c341
RSP: 002b:00007f469523ec10 EFLAGS: 00000293 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000718000 RCX: 000000000040c341
RDX: 0000000000000037 RSI: 0000000020004000 RDI: 0000000000000015
RBP: 0000000000000086 R08: 0000000000000000 R09: 0000000000000000
R10: 00000000000f4240 R11: 0000000000000293 R12: 00000000004b7fd1
R13: 00000000ffffffff R14: 0000000020000000 R15: 0000000000025000
Allocated by task 3295:
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
save_stack+0x43/0xd0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_kmalloc+0xad/0xe0 mm/kasan/kasan.c:551
__do_kmalloc mm/slab.c:3725 [inline]
__kmalloc+0x162/0x760 mm/slab.c:3734
kmalloc include/linux/slab.h:498 [inline]
tcp_v4_save_options include/net/tcp.h:1962 [inline]
tcp_v4_init_req+0x2d3/0x3e0 net/ipv4/tcp_ipv4.c:1271
tcp_conn_request+0xf6d/0x3410 net/ipv4/tcp_input.c:6283
tcp_v4_conn_request+0x157/0x210 net/ipv4/tcp_ipv4.c:1313
tcp_rcv_state_process+0x8ea/0x4850 net/ipv4/tcp_input.c:5857
tcp_v4_do_rcv+0x55c/0x7d0 net/ipv4/tcp_ipv4.c:1482
tcp_v4_rcv+0x2d10/0x2f80 net/ipv4/tcp_ipv4.c:1711
ip_local_deliver_finish+0x2e2/0xba0 net/ipv4/ip_input.c:216
NF_HOOK include/linux/netfilter.h:249 [inline]
ip_local_deliver+0x1ce/0x6e0 net/ipv4/ip_input.c:257
dst_input include/net/dst.h:464 [inline]
ip_rcv_finish+0x887/0x19a0 net/ipv4/ip_input.c:397
NF_HOOK include/linux/netfilter.h:249 [inline]
ip_rcv+0xc3f/0x1820 net/ipv4/ip_input.c:493
__netif_receive_skb_core+0x1a3e/0x34b0 net/core/dev.c:4476
__netif_receive_skb+0x2c/0x1b0 net/core/dev.c:4514
netif_receive_skb_internal+0x10b/0x670 net/core/dev.c:4587
netif_receive_skb+0xae/0x390 net/core/dev.c:4611
tun_rx_batched.isra.50+0x5ed/0x860 drivers/net/tun.c:1372
tun_get_user+0x249c/0x36d0 drivers/net/tun.c:1766
tun_chr_write_iter+0xbf/0x160 drivers/net/tun.c:1792
call_write_iter include/linux/fs.h:1770 [inline]
new_sync_write fs/read_write.c:468 [inline]
__vfs_write+0x68a/0x970 fs/read_write.c:481
vfs_write+0x18f/0x510 fs/read_write.c:543
SYSC_write fs/read_write.c:588 [inline]
SyS_write+0xef/0x220 fs/read_write.c:580
entry_SYSCALL_64_fastpath+0x1f/0xbe
Freed by task 3306:
save_stack_trace+0x16/0x20 arch/x86/kernel/stacktrace.c:59
save_stack+0x43/0xd0 mm/kasan/kasan.c:447
set_track mm/kasan/kasan.c:459 [inline]
kasan_slab_free+0x71/0xc0 mm/kasan/kasan.c:524
__cache_free mm/slab.c:3503 [inline]
kfree+0xca/0x250 mm/slab.c:3820
inet_sock_destruct+0x59d/0x950 net/ipv4/af_inet.c:157
__sk_destruct+0xfd/0x910 net/core/sock.c:1560
sk_destruct+0x47/0x80 net/core/sock.c:1595
__sk_free+0x57/0x230 net/core/sock.c:1603
sk_free+0x2a/0x40 net/core/sock.c:1614
sock_put include/net/sock.h:1652 [inline]
inet_csk_complete_hashdance+0xd5/0xf0 net/ipv4/inet_connection_sock.c:959
tcp_check_req+0xf4d/0x1620 net/ipv4/tcp_minisocks.c:765
tcp_v4_rcv+0x17f6/0x2f80 net/ipv4/tcp_ipv4.c:1675
ip_local_deliver_finish+0x2e2/0xba0 net/ipv4/ip_input.c:216
NF_HOOK include/linux/netfilter.h:249 [inline]
ip_local_deliver+0x1ce/0x6e0 net/ipv4/ip_input.c:257
dst_input include/net/dst.h:464 [inline]
ip_rcv_finish+0x887/0x19a0 net/ipv4/ip_input.c:397
NF_HOOK include/linux/netfilter.h:249 [inline]
ip_rcv+0xc3f/0x1820 net/ipv4/ip_input.c:493
__netif_receive_skb_core+0x1a3e/0x34b0 net/core/dev.c:4476
__netif_receive_skb+0x2c/0x1b0 net/core/dev.c:4514
netif_receive_skb_internal+0x10b/0x670 net/core/dev.c:4587
netif_receive_skb+0xae/0x390 net/core/dev.c:4611
tun_rx_batched.isra.50+0x5ed/0x860 drivers/net/tun.c:1372
tun_get_user+0x249c/0x36d0 drivers/net/tun.c:1766
tun_chr_write_iter+0xbf/0x160 drivers/net/tun.c:1792
call_write_iter include/linux/fs.h:1770 [inline]
new_sync_write fs/read_write.c:468 [inline]
__vfs_write+0x68a/0x970 fs/read_write.c:481
vfs_write+0x18f/0x510 fs/read_write.c:543
SYSC_write fs/read_write.c:588 [inline]
SyS_write+0xef/0x220 fs/read_write.c:580
entry_SYSCALL_64_fastpath+0x1f/0xbe
Fixes: e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Fixes: 079096f103fa ("tcp/dccp: install syn_recv requests into ehash table")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-10-21 01:33:19 +01:00
..
2017-07-11 06:08:58 -04:00
2017-09-01 22:49:47 +02:00
2015-02-20 17:35:14 -05:00
2015-09-21 16:03:04 -07:00
2017-09-08 18:55:50 +02:00
2017-09-03 17:08:42 -07:00
2017-04-05 10:15:20 +02:00
2016-02-11 03:54:14 -05:00
2017-09-15 14:47:49 -07:00
2017-08-23 20:44:32 -07:00
2017-04-12 22:02:36 +02:00
2017-09-12 20:41:02 -07:00
2017-08-15 17:06:34 -07:00
2015-09-17 13:20:05 +02:00
2017-08-29 10:55:20 +01:00
2017-07-21 03:38:43 +01: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-08-11 14:21:42 -07:00
2017-08-11 14:59:24 -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
2015-03-06 21:50:02 -05:00
2017-08-31 14:42:19 -07:00
2017-07-04 22:35:15 +01:00
2015-09-17 17:18:37 -07:00
2017-09-05 11:53:34 -07: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-09-21 20:42:15 -07:00
2017-08-22 14:29:30 -07:00
2017-04-14 10:06:42 +02:00
2015-09-23 15:33:15 -07:00
2017-09-01 20:33:42 -07:00
2017-08-03 15:35:59 -07:00
2017-09-05 11:40:08 -07:00
2017-08-24 18:21:17 -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
2017-08-07 11:39:22 -07: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-09-03 11:01:05 -07:00
2017-08-07 11:39:21 -07:00
2017-10-21 01:33:19 +01:00
2016-12-29 11:38:31 -05:00
2017-07-17 08:59:01 -07:00
2016-03-13 23:55:13 -04:00
2017-09-01 17:42:05 -07:00
2017-08-29 15:32:25 -07:00
2017-04-21 13:21:30 -04:00
2017-08-03 15:35:59 -07:00
2017-08-28 15:04:52 -07:00
2017-04-28 12:00:10 +02:00
2017-08-21 17:06:42 -07: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
2014-12-10 15:21:24 -05:00
2015-05-11 10:50:17 -04:00
2014-12-10 15:21:24 -05:00
2017-07-04 22:35:15 +01:00
2017-05-30 11:55:32 -04:00
2017-09-05 11:28:43 +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
2017-09-05 09:11:45 -07:00
2017-07-01 07:39:07 -07:00
2017-07-19 08:55:18 -07:00
2017-08-03 15:35:59 -07:00
2016-07-05 09:06:29 -07:00
2017-07-01 07:39:09 -07:00
2017-09-25 20:18: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
2017-08-29 15:16:52 -07:00
2016-03-23 22:09:58 -04:00
2017-08-11 13:47:01 -07:00
2017-08-11 13:47:00 -07:00
2016-08-15 10:55:53 -07:00
2017-10-01 03:55:47 +01:00
2017-01-24 13:44:28 -05:00
2017-08-07 11:39:21 -07:00
2017-08-07 11:39:22 -07:00
2016-12-25 17:21:22 +01:00
2014-12-17 11:49:55 +01:00
2017-07-01 07:39:08 -07:00
2017-10-01 03:55:47 +01:00
2017-08-09 16:57:38 -07:00
2017-09-01 17:42:05 -07: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
2017-08-25 17:10:23 -07: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-09-21 20:42:15 -07:00
2017-08-24 21:57:50 -07:00
2017-08-07 14:48:48 -07:00
2015-03-12 22:58:12 -04:00
2017-10-20 13:01:29 +01: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
2017-08-23 20:42:09 -07:00
2017-08-29 15:16:52 -07:00
2017-07-24 13:52:59 -07:00
2017-10-01 03:55:47 +01:00
2017-05-16 15:41:29 -04:00
2017-08-29 15:16:52 -07:00
2017-06-14 13:52:44 +02:00
2017-07-04 22:35:18 +01:00
2017-08-31 09:04:03 +02:00