Eric Dumazet
4faeee0cf8
tcp: deny tcp_disconnect() when threads are waiting
...
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>
2023-05-29 22:03:48 -07:00
..
2023-03-27 02:33:48 +00:00
2023-05-19 15:37:45 -07:00
2021-07-01 13:19:48 -07:00
2021-11-19 11:52:25 +00:00
2023-04-14 08:56:19 +01:00
2023-05-03 08:24:32 +02:00
2023-04-20 20:07:50 -07:00
2021-11-17 20:17:05 -08:00
2022-07-22 12:53:22 +01:00
2023-04-21 08:19:30 +01:00
2023-02-16 10:39:28 +01:00
2023-02-20 16:46:10 -08:00
2023-03-17 08:56:37 +00:00
2023-05-01 07:43:19 +01:00
2023-03-18 12:23:33 +00:00
2023-03-29 08:19:38 +01:00
2022-07-22 12:53:22 +01:00
2023-03-21 21:32:18 -07:00
2023-03-18 12:23:34 +00:00
2022-08-09 22:14:02 -07:00
2021-12-13 12:34:09 +00:00
2022-09-16 14:34:01 +01:00
2022-11-02 20:38:13 -07:00
2022-07-22 12:53:22 +01:00
2023-05-19 22:46:37 -07:00
2021-03-26 17:43:55 +01:00
2022-08-24 13:46:58 +01:00
2022-11-16 11:31:47 +02:00
2023-03-24 11:45:51 +01:00
2023-01-28 13:51:22 +01:00
2023-01-27 11:19:46 +00:00
2021-12-22 15:03:47 -08:00
2022-07-22 12:53:22 +01:00
2021-12-22 15:03:51 -08:00
2022-07-24 18:39:17 -06:00
2022-07-22 12:53:22 +01:00
2022-07-22 12:53:22 +01:00
2023-01-20 09:33:22 +00:00
2023-02-13 09:49:14 +00:00
2023-04-20 20:20:49 -07:00
2023-04-20 20:20:49 -07:00
2023-04-09 15:35:49 +01:00
2023-04-03 10:04:27 +01:00
2021-11-29 19:50:45 -08:00
2022-12-05 21:58:27 -08:00
2023-01-13 20:59:14 -08:00
2023-03-28 18:52:28 -07:00
2022-07-22 12:53:22 +01:00
2022-07-22 12:53:22 +01:00
2022-07-22 12:53:22 +01:00
2021-12-06 16:06:02 -08:00
2021-12-16 07:18:35 -08:00
2022-07-28 22:21:54 -07:00
2023-04-20 19:25:02 -07:00
2023-02-20 16:46:10 -08:00
2023-01-27 11:19:46 +00:00
2023-04-12 16:40:39 -07:00
2022-12-01 15:09:10 +01:00
2022-07-22 12:53:22 +01:00
2022-07-22 12:53:22 +01:00
2021-10-18 12:54:41 +01:00
2022-11-21 13:09:07 +00:00
2022-10-31 10:43:04 +00:00
2021-01-29 20:39:14 -08:00
2022-08-25 16:07:42 -07:00
2022-07-22 12:53:22 +01:00
2022-07-22 12:53:22 +01:00
2023-05-24 22:05:24 -07:00
2022-07-22 12:53:22 +01:00
2021-06-28 14:29:45 -07:00
2023-03-07 20:11:36 +01:00
2023-01-28 13:55:10 +01:00
2022-04-06 22:09:39 -07:00
2022-07-22 12:53:22 +01:00
2022-07-22 12:53:22 +01:00
2022-07-29 11:58:54 +01:00
2022-07-22 12:53:22 +01:00
2022-08-24 19:30:07 -07:00
2022-02-07 20:12:45 -08:00
2021-10-15 11:33:08 +01:00
2023-04-20 20:20:49 -07:00
2022-12-30 07:25:52 +00:00
2023-03-17 08:56:37 +00:00
2022-12-30 07:25:52 +00:00
2022-02-17 07:00:39 -06:00
2021-11-16 13:16:54 +00:00
2023-03-29 08:22:52 +01:00
2023-03-28 18:52:22 -07:00
2022-04-25 11:40:45 +01:00
2022-04-11 17:37:50 -07:00
2023-04-13 16:43:38 -07:00
2023-04-22 01:39:41 +02:00
2023-05-23 15:38:59 +02:00
2022-09-29 07:18:00 +02:00
2022-07-22 12:53:22 +01:00
2022-10-31 20:14:27 -07:00
2022-09-02 20:34:32 -07:00
2023-02-13 19:55:32 -08:00
2021-03-23 14:14:50 -07:00
2022-07-22 12:53:22 +01:00
2022-07-22 12:53:22 +01:00
2021-12-07 20:44:59 -08:00
2021-10-13 09:40:46 -07:00
2021-07-27 13:05:56 +01:00
2022-07-22 12:53:22 +01:00
2022-07-22 12:53:22 +01:00
2022-07-28 11:29:36 +02:00
2021-11-07 19:25:29 +00:00
2021-08-30 01:51:36 +02:00
2023-04-18 14:48:01 +02:00
2022-10-12 12:57:19 +02:00
2022-09-23 06:56:08 -07:00
2022-04-01 12:04:15 +01:00
2021-10-29 13:23:51 +01:00
2021-03-26 15:14:56 -07:00
2022-07-22 12:53:22 +01:00
2022-12-12 13:11:24 -08:00
2022-11-18 12:14:55 +00:00
2022-07-22 12:53:22 +01:00
2023-03-21 21:32:18 -07:00
2023-03-21 21:32:18 -07:00
2022-05-11 12:43:10 +01:00
2022-10-24 11:04:43 +01:00
2021-12-10 06:38:26 -08:00
2023-04-18 12:59:01 +02:00
2022-07-22 12:53:22 +01:00
2023-01-28 00:33:51 -08:00
2022-07-22 12:53:22 +01:00
2023-05-11 18:07:05 -07:00
2023-01-28 13:51:22 +01:00
2022-07-22 12:53:22 +01:00
2023-05-23 20:25:13 -07:00
2022-12-01 12:42:46 +01:00
2023-02-20 16:46:10 -08:00
2023-04-13 22:22:10 -07:00
2022-07-22 12:53:22 +01:00
2022-07-15 18:50:35 -07:00
2021-08-09 15:34:21 -07:00
2022-07-22 12:53:22 +01:00
2023-04-06 12:01:20 -07:00
2023-03-17 08:56:37 +00:00
2022-10-11 17:42:58 -06:00
2022-07-22 12:53:22 +01:00
2022-02-02 14:45:18 +00:00
2022-08-01 11:59:23 -07:00
2023-03-28 18:52:22 -07:00
2022-10-31 18:10:21 -07:00
2023-02-20 16:46:10 -08:00
2023-03-15 08:20:12 +00:00
2022-07-22 12:53:22 +01:00
2022-01-04 12:17:35 +00:00
2021-04-28 14:06:45 -07:00
2023-03-15 08:18:35 +00:00
2022-10-25 11:35:16 +02:00
2023-05-29 22:03:48 -07:00
2021-08-03 13:05:26 +01:00
2022-07-22 12:53:22 +01:00
2022-07-18 11:24:10 +01:00
2022-11-09 19:06:13 -08:00
2023-02-16 09:27:07 +01:00
2023-05-23 16:10:42 +02:00
2023-05-19 08:37:37 +01:00
2022-10-24 09:40:39 +01:00
2022-12-12 15:04:39 -08:00
2022-07-22 12:53:22 +01:00
2022-11-08 16:42:28 +00:00
2022-10-24 10:52:50 +01:00
2022-10-12 17:50:37 -07:00
2023-03-17 22:41:16 -07:00
2023-03-18 12:23:34 +00:00
2022-07-22 12:53:22 +01:00
2022-09-30 07:55:46 -07:00
2023-03-07 09:33:43 -08:00
2023-04-13 16:43:38 -07:00
2023-03-20 11:29:33 +02:00
2023-04-06 09:53:05 -07:00