Eric Dumazet
5c35681661
bpf, sockmap: fix race in sock_map_free()
[ Upstream commit 0a182f8d607464911756b4dbef5d6cad8de22469 ]
sock_map_free() calls release_sock(sk) without owning a reference
on the socket. This can cause use-after-free as syzbot found [1]
Jakub Sitnicki already took care of a similar issue
in sock_hash_free() in commit 75e68e5bf2c7 ("bpf, sockhash:
Synchronize delete from bucket list on map free")
[1]
refcount_t: decrement hit 0; leaking memory.
WARNING: CPU: 0 PID: 3785 at lib/refcount.c:31 refcount_warn_saturate+0x17c/0x1a0 lib/refcount.c:31
Modules linked in:
CPU: 0 PID: 3785 Comm: kworker/u4:6 Not tainted 6.1.0-rc7-syzkaller-00103-gef4d3ea40565 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Workqueue: events_unbound bpf_map_free_deferred
RIP: 0010:refcount_warn_saturate+0x17c/0x1a0 lib/refcount.c:31
Code: 68 8b 31 c0 e8 75 71 15 fd 0f 0b e9 64 ff ff ff e8 d9 6e 4e fd c6 05 62 9c 3d 0a 01 48 c7 c7 80 bb 68 8b 31 c0 e8 54 71 15 fd <0f> 0b e9 43 ff ff ff 89 d9 80 e1 07 80 c1 03 38 c1 0f 8c a2 fe ff
RSP: 0018:ffffc9000456fb60 EFLAGS: 00010246
RAX: eae59bab72dcd700 RBX: 0000000000000004 RCX: ffff8880207057c0
RDX: 0000000000000000 RSI: 0000000000000201 RDI: 0000000000000000
RBP: 0000000000000004 R08: ffffffff816fdabd R09: fffff520008adee5
R10: fffff520008adee5 R11: 1ffff920008adee4 R12: 0000000000000004
R13: dffffc0000000000 R14: ffff88807b1c6c00 R15: 1ffff1100f638dcf
FS: 0000000000000000(0000) GS:ffff8880b9800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b30c30000 CR3: 000000000d08e000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
__refcount_dec include/linux/refcount.h:344 [inline]
refcount_dec include/linux/refcount.h:359 [inline]
__sock_put include/net/sock.h:779 [inline]
tcp_release_cb+0x2d0/0x360 net/ipv4/tcp_output.c:1092
release_sock+0xaf/0x1c0 net/core/sock.c:3468
sock_map_free+0x219/0x2c0 net/core/sock_map.c:356
process_one_work+0x81c/0xd10 kernel/workqueue.c:2289
worker_thread+0xb14/0x1330 kernel/workqueue.c:2436
kthread+0x266/0x300 kernel/kthread.c:376
ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306
</TASK>
Fixes: 7e81a3530206 ("bpf: Sockmap, ensure sock lock held during tear down")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Song Liu <songliubraving@fb.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/r/20221202111640.2745533-1-edumazet@google.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-12-31 13:32:22 +01:00
..
2022-08-24 13:46:57 +01:00
2022-09-02 12:29:02 +01:00
2021-11-20 12:25:57 +00:00
2022-04-07 20:32:09 -07:00
2022-06-09 21:52:55 -07:00
2022-10-19 14:04:36 +01:00
2022-05-16 11:33:59 +01:00
2022-09-30 18:17:16 -07:00
2022-08-29 12:47:15 +01:00
2021-11-29 19:50:45 -08:00
2022-06-09 21:52:55 -07:00
2022-06-09 21:52:55 -07:00
2019-10-04 11:10:56 -07:00
2021-12-16 07:18:35 -08:00
2022-12-31 13:32:22 +01:00
2022-11-18 15:21:00 +01:00
2022-09-20 09:13:38 +02:00
2021-10-18 12:54:41 +01:00
2022-08-16 19:38:20 -07:00
2022-09-28 18:57:14 -07:00
2022-10-03 12:38:34 +01:00
2019-06-09 19:40:10 -07:00
2022-06-09 21:52:55 -07:00
2022-04-22 17:45:25 +02:00
2022-10-12 10:45:51 +02:00
2022-09-07 15:28:08 +01:00
2022-11-18 10:29:50 +00:00
2022-10-24 12:40:06 +01:00
2022-04-07 20:32:09 -07:00
2022-09-30 12:27:44 +01:00
2020-02-26 20:07:25 -08:00
2021-05-14 15:26:03 -07:00
2022-08-31 09:40:34 +01:00
2021-03-28 17:56:56 -07:00
2022-08-22 18:06:18 -07:00
2021-09-13 16:35:58 -07:00
2022-01-12 14:14:36 +00:00
2022-08-05 16:32:45 -07:00
2022-10-11 17:42:58 -06:00
2022-03-07 11:31:34 +00:00
2019-10-13 10:13:08 -07:00
2022-09-20 08:37:44 -07:00
2021-07-20 06:00:38 -07:00
2022-07-20 10:14:49 +01:00
2021-10-24 13:59:44 +01:00
2022-11-03 20:58:09 -07:00
2022-12-31 13:32:20 +01:00
2021-10-22 12:35:51 -07:00
2021-12-29 08:48:14 -08:00
2022-12-31 13:32:22 +01:00
2022-12-31 13:32:04 +01:00
2022-12-31 13:32:04 +01:00
2022-10-11 17:42:55 -06:00
2022-09-07 15:31:19 +01:00
2019-12-25 19:51:33 -08:00
2020-06-18 20:46:23 -07:00
2022-02-21 11:40:44 +00:00
2022-09-26 11:28:19 -07:00