Eric Dumazet
0377416ce1
tcp: deny tcp_disconnect() when threads are waiting
...
[ Upstream commit 4faeee0cf8a5d88d63cdbc3bab124fb0e6aed08c ]
Historically connect(AF_UNSPEC) has been abused by syzkaller
and other fuzzers to trigger various bugs.
A recent one triggers a divide-by-zero [1], and Paolo Abeni
was able to diagnose the issue.
tcp_recvmsg_locked() has tests about sk_state being not TCP_LISTEN
and TCP REPAIR mode being not used.
Then later if socket lock is released in sk_wait_data(),
another thread can call connect(AF_UNSPEC), then make this
socket a TCP listener.
When recvmsg() is resumed, it can eventually call tcp_cleanup_rbuf()
and attempt a divide by 0 in tcp_rcv_space_adjust() [1]
This patch adds a new socket field, counting number of threads
blocked in sk_wait_event() and inet_wait_for_connect().
If this counter is not zero, tcp_disconnect() returns an error.
This patch adds code in blocking socket system calls, thus should
not hurt performance of non blocking ones.
Note that we probably could revert commit 499350a5a6e7 ("tcp:
initialize rcv_mss to TCP_MIN_MSS instead of 0") to restore
original tcpi_rcv_mss meaning (was 0 if no payload was ever
received on a socket)
[1]
divide error: 0000 [#1 ] PREEMPT SMP KASAN
CPU: 0 PID: 13832 Comm: syz-executor.5 Not tainted 6.3.0-rc4-syzkaller-00224-g00c7b5f4ddc5 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/02/2023
RIP: 0010:tcp_rcv_space_adjust+0x36e/0x9d0 net/ipv4/tcp_input.c:740
Code: 00 00 00 00 fc ff df 4c 89 64 24 48 8b 44 24 04 44 89 f9 41 81 c7 80 03 00 00 c1 e1 04 44 29 f0 48 63 c9 48 01 e9 48 0f af c1 <49> f7 f6 48 8d 04 41 48 89 44 24 40 48 8b 44 24 30 48 c1 e8 03 48
RSP: 0018:ffffc900033af660 EFLAGS: 00010206
RAX: 4a66b76cbade2c48 RBX: ffff888076640cc0 RCX: 00000000c334e4ac
RDX: 0000000000000000 RSI: dffffc0000000000 RDI: 0000000000000001
RBP: 00000000c324e86c R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: ffff8880766417f8
R13: ffff888028fbb980 R14: 0000000000000000 R15: 0000000000010344
FS: 00007f5bffbfe700(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b32f25000 CR3: 000000007ced0000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
tcp_recvmsg_locked+0x100e/0x22e0 net/ipv4/tcp.c:2616
tcp_recvmsg+0x117/0x620 net/ipv4/tcp.c:2681
inet6_recvmsg+0x114/0x640 net/ipv6/af_inet6.c:670
sock_recvmsg_nosec net/socket.c:1017 [inline]
sock_recvmsg+0xe2/0x160 net/socket.c:1038
____sys_recvmsg+0x210/0x5a0 net/socket.c:2720
___sys_recvmsg+0xf2/0x180 net/socket.c:2762
do_recvmmsg+0x25e/0x6e0 net/socket.c:2856
__sys_recvmmsg net/socket.c:2935 [inline]
__do_sys_recvmmsg net/socket.c:2958 [inline]
__se_sys_recvmmsg net/socket.c:2951 [inline]
__x64_sys_recvmmsg+0x20f/0x260 net/socket.c:2951
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f5c0108c0f9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f5bffbfe168 EFLAGS: 00000246 ORIG_RAX: 000000000000012b
RAX: ffffffffffffffda RBX: 00007f5c011ac050 RCX: 00007f5c0108c0f9
RDX: 0000000000000001 RSI: 0000000020000bc0 RDI: 0000000000000003
RBP: 00007f5c010e7b39 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000122 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f5c012cfb1f R14: 00007f5bffbfe300 R15: 0000000000022000
</TASK>
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot <syzkaller@googlegroups.com>
Reported-by: Paolo Abeni <pabeni@redhat.com>
Diagnosed-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Tested-by: Paolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/r/20230526163458.2880232-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-06-09 10:23:55 +02:00
..
2019-07-03 13:14:42 +02:00
2022-08-11 12:48:38 +02:00
2021-06-10 13:24:06 +02:00
2018-06-28 10:40:47 -07:00
2023-05-30 12:42:12 +01:00
2021-04-14 08:22:34 +02:00
2021-12-01 09:27:43 +01:00
2019-03-23 20:09:51 +01:00
2022-01-05 12:34:58 +01:00
2022-05-18 09:42:48 +02:00
2020-06-03 08:19:15 +02:00
2020-08-11 15:32:34 +02:00
2018-07-13 12:18:18 -04:00
2018-08-03 12:46:20 -07:00
2021-07-31 08:22:37 +02:00
2018-08-07 12:39:13 -07:00
2017-11-02 11:10:55 +01:00
2022-04-15 14:15:01 +02:00
2017-11-02 11:10:55 +01:00
2022-04-27 13:39:45 +02:00
2018-04-19 16:11:11 -04:00
2022-02-23 11:58:39 +01:00
2021-12-14 10:18:05 +01:00
2020-12-08 10:18:53 +01:00
2022-09-05 10:26:30 +02:00
2017-07-04 22:35:16 +01:00
2021-06-03 08:38:03 +02:00
2022-03-02 11:38:12 +01:00
2017-07-04 01:29:04 -07:00
2018-04-02 20:16:17 +02:00
2017-11-02 11:10:55 +01:00
2018-07-27 13:17:50 -07:00
2018-10-10 10:19:10 -07:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-10-18 12:39:36 +01:00
2017-11-30 09:54:25 -05:00
2017-11-04 09:26:51 +09:00
2020-11-10 12:36:02 +01:00
2017-11-02 11:10:55 +01:00
2018-03-05 12:52:45 -05:00
2022-02-16 12:51:46 +01:00
2020-01-04 19:13:37 +01:00
2020-07-22 09:31:59 +02:00
2018-05-20 18:31:42 -04:00
2022-07-12 16:29:00 +02:00
2018-02-28 11:43:28 -05:00
2018-05-28 22:59:54 -04:00
2017-11-01 11:50:43 +09:00
2020-03-18 07:14:14 +01:00
2017-11-02 11:10:55 +01:00
2022-04-20 09:12:48 +02:00
2018-07-20 10:14:41 +02:00
2017-11-02 11:10:55 +01:00
2019-12-05 09:19:45 +01:00
2019-11-10 11:27:54 +01:00
2017-11-02 11:10:55 +01:00
2018-08-11 12:37:10 -07:00
2020-07-22 09:31:58 +02:00
2017-11-02 11:10:55 +01:00
2018-02-27 14:46:26 -05:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-12-11 14:10:06 -05:00
2017-11-02 11:10:55 +01:00
2021-03-04 09:39:59 +01:00
2018-06-15 14:04:00 +02:00
2022-10-26 13:19:42 +02:00
2022-06-14 16:59:14 +02:00
2018-04-22 21:12:00 -04:00
2017-08-07 11:39:22 -07:00
2018-06-26 11:33:04 +09:00
2021-04-07 12:48:47 +02:00
2020-07-22 09:32:00 +02:00
2019-04-27 09:36:33 +02:00
2022-06-06 08:24:20 +02:00
2022-07-29 17:10:31 +02:00
2018-06-05 10:45:24 -04:00
2019-02-23 09:07:24 +01:00
2022-02-08 18:23:09 +01:00
2021-08-12 13:19:39 +02:00
2023-05-30 12:42:10 +01:00
2019-01-31 08:14:32 +01:00
2023-05-30 12:42:10 +01:00
2020-08-19 08:14:56 +02:00
2023-06-09 10:23:54 +02:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2019-07-10 09:53:46 +02:00
2023-04-26 11:21:52 +02:00
2020-02-11 04:34:14 -08:00
2018-03-27 09:51:23 +02:00
2019-02-06 17:30:06 +01:00
2018-07-11 23:10:19 -07:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2017-10-25 12:06:25 +09:00
2019-11-06 13:06:23 +01:00
2021-08-04 12:23:46 +02:00
2021-11-26 11:36:16 +01:00
2018-02-14 14:43:32 -05:00
2018-06-18 22:40:32 +02:00
2017-11-02 11:10:55 +01:00
2023-01-18 11:30:36 +01:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2020-01-09 10:19:09 +01:00
2018-05-28 22:59:54 -04:00
2021-06-30 08:48:18 -04:00
2017-11-02 11:10:55 +01:00
2018-08-01 09:52:30 -07:00
2017-07-01 07:39:09 -07:00
2018-09-29 11:48:26 -07:00
2019-05-02 09:58:57 +02:00
2018-04-07 22:32:31 -04:00
2021-12-01 09:27:42 +01:00
2017-11-08 16:12:33 +09:00
2017-11-02 11:10:55 +01:00
2018-05-24 18:36:15 -07:00
2018-05-16 07:23:35 +02:00
2020-02-01 09:37:06 +00:00
2021-12-14 10:18:04 +01:00
2017-11-02 11:10:55 +01:00
2022-11-10 17:46:54 +01:00
2021-08-26 08:36:38 -04:00
2017-11-02 11:10:55 +01:00
2018-05-16 07:23:35 +02:00
2017-11-02 11:10:55 +01:00
2021-04-14 08:22:34 +02:00
2018-08-28 11:11:47 +02:00
2020-01-27 14:51:18 +01:00
2018-05-16 07:23:35 +02:00
2018-05-29 10:12:45 -04:00
2018-03-13 18:37:02 +02:00
2021-03-30 14:37:03 +02:00
2022-01-27 09:04:33 +01:00
2023-05-17 11:13:11 +02:00
2022-06-06 08:24:20 +02:00
2018-06-22 13:43:27 +09:00
2018-07-31 09:22:48 +02:00
2018-06-22 13:43:27 +09:00
2018-04-11 10:33:46 -04:00
2018-06-30 20:42:25 +09:00
2019-09-21 07:16:43 +02:00
2023-06-09 10:23:55 +02:00
2018-03-01 21:21:36 -05:00
2017-11-02 11:10:55 +01:00
2018-06-06 14:07:53 -04:00
2018-05-03 13:46:47 -04:00
2018-02-21 15:06:05 -05:00
2023-05-30 12:42:07 +01:00
2018-05-08 00:02:41 -04:00
2020-12-08 10:18:52 +01:00
2018-07-07 10:58:49 +09:00
2017-11-02 11:10:55 +01:00
2017-08-29 15:16:52 -07:00
2018-06-26 11:33:04 +09:00
2023-04-26 11:21:52 +02:00
2023-04-26 11:21:52 +02:00
2018-04-17 13:53:13 -04:00
2018-01-24 19:13:45 -05:00
2017-11-02 11:10:55 +01:00
2017-11-02 11:10:55 +01:00
2019-05-04 09:20:12 +02:00
2018-08-10 16:12:20 +02:00
2022-04-15 14:15:07 +02:00