Eric Dumazet
56667da739
net: implement lockless setsockopt(SO_PEEK_OFF)
...
syzbot reported a lockdep violation [1] involving af_unix
support of SO_PEEK_OFF.
Since SO_PEEK_OFF is inherently not thread safe (it uses a per-socket
sk_peek_off field), there is really no point to enforce a pointless
thread safety in the kernel.
After this patch :
- setsockopt(SO_PEEK_OFF) no longer acquires the socket lock.
- skb_consume_udp() no longer has to acquire the socket lock.
- af_unix no longer needs a special version of sk_set_peek_off(),
because it does not lock u->iolock anymore.
As a followup, we could replace prot->set_peek_off to be a boolean
and avoid an indirect call, since we always use sk_set_peek_off().
[1]
WARNING: possible circular locking dependency detected
6.8.0-rc4-syzkaller-00267-g0f1dd5e91e2b #0 Not tainted
syz-executor.2/30025 is trying to acquire lock:
ffff8880765e7d80 (&u->iolock){+.+.}-{3:3}, at: unix_set_peek_off+0x26/0xa0 net/unix/af_unix.c:789
but task is already holding lock:
ffff8880765e7930 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1691 [inline]
ffff8880765e7930 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: sockopt_lock_sock net/core/sock.c:1060 [inline]
ffff8880765e7930 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: sk_setsockopt+0xe52/0x3360 net/core/sock.c:1193
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (sk_lock-AF_UNIX){+.+.}-{0:0}:
lock_acquire+0x1e3/0x530 kernel/locking/lockdep.c:5754
lock_sock_nested+0x48/0x100 net/core/sock.c:3524
lock_sock include/net/sock.h:1691 [inline]
__unix_dgram_recvmsg+0x1275/0x12c0 net/unix/af_unix.c:2415
sock_recvmsg_nosec+0x18e/0x1d0 net/socket.c:1046
____sys_recvmsg+0x3c0/0x470 net/socket.c:2801
___sys_recvmsg net/socket.c:2845 [inline]
do_recvmmsg+0x474/0xae0 net/socket.c:2939
__sys_recvmmsg net/socket.c:3018 [inline]
__do_sys_recvmmsg net/socket.c:3041 [inline]
__se_sys_recvmmsg net/socket.c:3034 [inline]
__x64_sys_recvmmsg+0x199/0x250 net/socket.c:3034
do_syscall_64+0xf9/0x240
entry_SYSCALL_64_after_hwframe+0x6f/0x77
-> #0 (&u->iolock){+.+.}-{3:3}:
check_prev_add kernel/locking/lockdep.c:3134 [inline]
check_prevs_add kernel/locking/lockdep.c:3253 [inline]
validate_chain+0x18ca/0x58e0 kernel/locking/lockdep.c:3869
__lock_acquire+0x1345/0x1fd0 kernel/locking/lockdep.c:5137
lock_acquire+0x1e3/0x530 kernel/locking/lockdep.c:5754
__mutex_lock_common kernel/locking/mutex.c:608 [inline]
__mutex_lock+0x136/0xd70 kernel/locking/mutex.c:752
unix_set_peek_off+0x26/0xa0 net/unix/af_unix.c:789
sk_setsockopt+0x207e/0x3360
do_sock_setsockopt+0x2fb/0x720 net/socket.c:2307
__sys_setsockopt+0x1ad/0x250 net/socket.c:2334
__do_sys_setsockopt net/socket.c:2343 [inline]
__se_sys_setsockopt net/socket.c:2340 [inline]
__x64_sys_setsockopt+0xb5/0xd0 net/socket.c:2340
do_syscall_64+0xf9/0x240
entry_SYSCALL_64_after_hwframe+0x6f/0x77
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(sk_lock-AF_UNIX);
lock(&u->iolock);
lock(sk_lock-AF_UNIX);
lock(&u->iolock);
*** DEADLOCK ***
1 lock held by syz-executor.2/30025:
#0 : ffff8880765e7930 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1691 [inline]
#0 : ffff8880765e7930 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: sockopt_lock_sock net/core/sock.c:1060 [inline]
#0 : ffff8880765e7930 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: sk_setsockopt+0xe52/0x3360 net/core/sock.c:1193
stack backtrace:
CPU: 0 PID: 30025 Comm: syz-executor.2 Not tainted 6.8.0-rc4-syzkaller-00267-g0f1dd5e91e2b #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x1e7/0x2e0 lib/dump_stack.c:106
check_noncircular+0x36a/0x4a0 kernel/locking/lockdep.c:2187
check_prev_add kernel/locking/lockdep.c:3134 [inline]
check_prevs_add kernel/locking/lockdep.c:3253 [inline]
validate_chain+0x18ca/0x58e0 kernel/locking/lockdep.c:3869
__lock_acquire+0x1345/0x1fd0 kernel/locking/lockdep.c:5137
lock_acquire+0x1e3/0x530 kernel/locking/lockdep.c:5754
__mutex_lock_common kernel/locking/mutex.c:608 [inline]
__mutex_lock+0x136/0xd70 kernel/locking/mutex.c:752
unix_set_peek_off+0x26/0xa0 net/unix/af_unix.c:789
sk_setsockopt+0x207e/0x3360
do_sock_setsockopt+0x2fb/0x720 net/socket.c:2307
__sys_setsockopt+0x1ad/0x250 net/socket.c:2334
__do_sys_setsockopt net/socket.c:2343 [inline]
__se_sys_setsockopt net/socket.c:2340 [inline]
__x64_sys_setsockopt+0xb5/0xd0 net/socket.c:2340
do_syscall_64+0xf9/0x240
entry_SYSCALL_64_after_hwframe+0x6f/0x77
RIP: 0033:0x7f78a1c7dda9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f78a0fde0c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000036
RAX: ffffffffffffffda RBX: 00007f78a1dac050 RCX: 00007f78a1c7dda9
RDX: 000000000000002a RSI: 0000000000000001 RDI: 0000000000000006
RBP: 00007f78a1cca47a R08: 0000000000000004 R09: 0000000000000000
R10: 0000000020000180 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000006e R14: 00007f78a1dac050 R15: 00007ffe5cd81ae8
Fixes: 859051dd165e ("bpf: Implement cgroup sockaddr hooks for unix sockets")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: Daan De Meyer <daan.j.demeyer@gmail.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
Cc: Martin KaFai Lau <martin.lau@kernel.org>
Cc: David Ahern <dsahern@kernel.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-02-21 11:24:20 +00:00
..
2024-01-17 12:02:49 +01:00
2024-02-04 16:06:53 +00:00
2024-02-09 14:12:02 -08:00
2024-02-20 10:50:19 +01:00
2023-12-19 08:23:03 -08:00
2023-08-16 11:09:17 +01:00
2023-10-01 19:39:19 +01:00
2024-02-18 10:22:27 +00:00
2023-10-06 07:30:40 +02:00
2024-02-09 14:12:02 -08:00
2023-03-16 17:26:31 -07:00
2022-02-17 11:44:20 -08:00
2024-01-03 16:42:48 -08:00
2023-10-18 18:11:31 -07:00
2023-12-27 11:50:20 -05:00
2023-11-01 22:33:53 -07:00
2023-04-12 16:40:39 -07:00
2023-05-26 10:30:14 +01:00
2023-05-26 10:30:14 +01:00
2023-06-10 00:11:41 -07:00
2023-10-06 08:31:53 +02:00
2023-11-24 15:25:56 +00:00
2024-01-19 21:13:25 -08:00
2023-12-22 22:15:35 +00:00
2022-10-31 20:14:27 -07:00
2024-02-16 09:41:54 +00:00
2023-12-22 22:15:35 +00:00
2022-07-08 12:10:33 +01:00
2023-10-13 09:58:45 -07:00
2023-08-15 15:26:18 -07:00
2024-02-09 14:12:02 -08:00
2023-09-01 08:11:51 +01:00
2022-01-29 17:53:07 +00:00
2024-02-15 12:04:04 +01:00
2024-01-26 21:05:26 -08:00
2024-02-03 12:43:19 +00:00
2024-02-09 14:12:02 -08:00
2024-02-09 14:12:02 -08:00
2022-09-29 07:18:00 +02:00
2023-05-22 11:17:55 +01:00
2024-02-09 14:12:02 -08:00
2022-06-24 11:34:38 +01:00
2024-01-26 21:05:26 -08:00
2023-10-27 10:35:44 +01:00
2024-01-04 10:23:10 -08:00
2023-01-23 21:37:25 -08:00
2023-10-06 08:31:53 +02:00
2023-08-15 18:54:53 -07:00
2023-10-16 21:05:33 -07:00
2023-10-27 10:35:45 +01:00
2023-11-19 20:09:13 +00:00
2024-01-26 21:05:26 -08:00
2023-11-21 12:55:22 +01:00
2023-11-29 20:16:38 -08:00
2023-12-08 10:44:42 -08:00
2023-12-07 17:53:17 -08:00
2023-10-01 19:09:54 +01:00
2022-04-06 12:05:41 -07:00
2023-10-18 18:09:31 -07:00
2022-10-16 15:27:07 -07:00
2023-03-22 22:53:00 -07:00
2023-02-02 00:25:14 +01:00
2023-02-02 00:25:14 +01:00
2023-11-19 20:09:13 +00:00
2023-08-16 11:09:18 +01:00
2022-04-06 12:05:41 -07:00
2022-04-06 12:05:41 -07:00
2022-04-06 12:05:41 -07:00
2022-04-06 12:05:41 -07:00
2023-12-14 17:14:41 -08:00
2024-01-08 19:08:51 -08:00
2023-10-23 09:35:01 +01:00
2023-10-03 10:05:22 +02:00
2023-12-06 12:36:55 +01:00
2022-04-06 12:05:41 -07:00
2023-06-10 00:11:41 -07:00
2023-12-12 15:56:02 -08:00
2022-12-20 03:13:45 +01:00
2022-04-28 13:02:01 -07:00
2023-10-17 17:25:42 -07:00
2022-04-06 12:05:41 -07:00
2024-01-01 14:42:05 +00:00
2023-11-16 23:35:12 +00:00
2023-01-19 09:26:16 -08:00
2022-04-06 12:05:41 -07:00
2022-04-06 12:05:41 -07:00
2022-04-06 12:05:41 -07:00
2022-04-06 12:05:41 -07:00
2024-02-12 09:51:26 +00:00
2024-02-09 14:12:02 -08:00
2023-03-03 17:25:15 +01:00
2023-11-19 20:09:13 +00:00
2023-06-24 15:50:13 -07:00
2023-09-14 16:16:36 +02:00
2024-02-09 14:12:02 -08:00
2023-10-03 11:39:34 +02:00
2024-02-21 11:24:20 +00:00
2023-09-14 16:16:36 +02:00
2023-10-23 07:10:39 +02:00
2023-08-29 17:39:15 -07:00
2022-06-08 10:10:13 -07:00
2024-02-09 14:12:02 -08:00