* [PATCH net-next] net: bpf: Use sockopt_lock_sock() in ip_sock_set_tos()
@ 2023-10-27 18:24 Yonghong Song
2023-10-27 18:42 ` Eric Dumazet
2023-10-27 23:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Yonghong Song @ 2023-10-27 18:24 UTC (permalink / raw)
To: bpf, netdev
Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team,
Eric Dumazet, Martin KaFai Lau
With latest sync from net-next tree, bpf-next has a bpf selftest failure:
[root@arch-fb-vm1 bpf]# ./test_progs -t setget_sockopt
...
[ 76.194349] ============================================
[ 76.194682] WARNING: possible recursive locking detected
[ 76.195039] 6.6.0-rc7-g37884503df08-dirty #67 Tainted: G W OE
[ 76.195518] --------------------------------------------
[ 76.195852] new_name/154 is trying to acquire lock:
[ 76.196159] ffff8c3e06ad8d30 (sk_lock-AF_INET){+.+.}-{0:0}, at: ip_sock_set_tos+0x19/0x30
[ 76.196669]
[ 76.196669] but task is already holding lock:
[ 76.197028] ffff8c3e06ad8d30 (sk_lock-AF_INET){+.+.}-{0:0}, at: inet_listen+0x21/0x70
[ 76.197517]
[ 76.197517] other info that might help us debug this:
[ 76.197919] Possible unsafe locking scenario:
[ 76.197919]
[ 76.198287] CPU0
[ 76.198444] ----
[ 76.198600] lock(sk_lock-AF_INET);
[ 76.198831] lock(sk_lock-AF_INET);
[ 76.199062]
[ 76.199062] *** DEADLOCK ***
[ 76.199062]
[ 76.199420] May be due to missing lock nesting notation
[ 76.199420]
[ 76.199879] 2 locks held by new_name/154:
[ 76.200131] #0: ffff8c3e06ad8d30 (sk_lock-AF_INET){+.+.}-{0:0}, at: inet_listen+0x21/0x70
[ 76.200644] #1: ffffffff90f96a40 (rcu_read_lock){....}-{1:2}, at: __cgroup_bpf_run_filter_sock_ops+0x55/0x290
[ 76.201268]
[ 76.201268] stack backtrace:
[ 76.201538] CPU: 4 PID: 154 Comm: new_name Tainted: G W OE 6.6.0-rc7-g37884503df08-dirty #67
[ 76.202134] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
[ 76.202699] Call Trace:
[ 76.202858] <TASK>
[ 76.203002] dump_stack_lvl+0x4b/0x80
[ 76.203239] __lock_acquire+0x740/0x1ec0
[ 76.203503] lock_acquire+0xc1/0x2a0
[ 76.203766] ? ip_sock_set_tos+0x19/0x30
[ 76.204050] ? sk_stream_write_space+0x12a/0x230
[ 76.204389] ? lock_release+0xbe/0x260
[ 76.204661] lock_sock_nested+0x32/0x80
[ 76.204942] ? ip_sock_set_tos+0x19/0x30
[ 76.205208] ip_sock_set_tos+0x19/0x30
[ 76.205452] do_ip_setsockopt+0x4b3/0x1580
[ 76.205719] __bpf_setsockopt+0x62/0xa0
[ 76.205963] bpf_sock_ops_setsockopt+0x11/0x20
[ 76.206247] bpf_prog_630217292049c96e_bpf_test_sockopt_int+0xbc/0x123
[ 76.206660] bpf_prog_493685a3bae00bbd_bpf_test_ip_sockopt+0x49/0x4b
[ 76.207055] bpf_prog_b0bcd27f269aeea0_skops_sockopt+0x44c/0xec7
[ 76.207437] __cgroup_bpf_run_filter_sock_ops+0xda/0x290
[ 76.207829] __inet_listen_sk+0x108/0x1b0
[ 76.208122] inet_listen+0x48/0x70
[ 76.208373] __sys_listen+0x74/0xb0
[ 76.208630] __x64_sys_listen+0x16/0x20
[ 76.208911] do_syscall_64+0x3f/0x90
[ 76.209174] entry_SYSCALL_64_after_hwframe+0x6e/0xd8
...
Both ip_sock_set_tos() and inet_listen() calls lock_sock(sk) which
caused a dead lock.
To fix the issue, use sockopt_lock_sock() in ip_sock_set_tos()
instead. sockopt_lock_sock() will avoid lock_sock() if it is in bpf
context.
Fixes: 878d951c6712 ("inet: lock the socket in ip_sock_set_tos()")
Cc: Eric Dumazet <edumazet@google.com>
Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
---
net/ipv4/ip_sockglue.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 9c68b6b74d9f..2efc53526a38 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -602,9 +602,9 @@ void __ip_sock_set_tos(struct sock *sk, int val)
void ip_sock_set_tos(struct sock *sk, int val)
{
- lock_sock(sk);
+ sockopt_lock_sock(sk);
__ip_sock_set_tos(sk, val);
- release_sock(sk);
+ sockopt_release_sock(sk);
}
EXPORT_SYMBOL(ip_sock_set_tos);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next] net: bpf: Use sockopt_lock_sock() in ip_sock_set_tos()
2023-10-27 18:24 [PATCH net-next] net: bpf: Use sockopt_lock_sock() in ip_sock_set_tos() Yonghong Song
@ 2023-10-27 18:42 ` Eric Dumazet
2023-10-27 23:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2023-10-27 18:42 UTC (permalink / raw)
To: Yonghong Song
Cc: bpf, netdev, Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
kernel-team, Martin KaFai Lau
On Fri, Oct 27, 2023 at 8:24 PM Yonghong Song <yonghong.song@linux.dev> wrote:
>
> With latest sync from net-next tree, bpf-next has a bpf selftest failure:
> [root@arch-fb-vm1 bpf]# ./test_progs -t setget_sockopt
> ...
> [ 76.194349] ============================================
> ...
>
> Both ip_sock_set_tos() and inet_listen() calls lock_sock(sk) which
> caused a dead lock.
>
> To fix the issue, use sockopt_lock_sock() in ip_sock_set_tos()
> instead. sockopt_lock_sock() will avoid lock_sock() if it is in bpf
> context.
>
> Fixes: 878d951c6712 ("inet: lock the socket in ip_sock_set_tos()")
> Cc: Eric Dumazet <edumazet@google.com>
> Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
> ---
SGTM, thanks.
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net-next] net: bpf: Use sockopt_lock_sock() in ip_sock_set_tos()
2023-10-27 18:24 [PATCH net-next] net: bpf: Use sockopt_lock_sock() in ip_sock_set_tos() Yonghong Song
2023-10-27 18:42 ` Eric Dumazet
@ 2023-10-27 23:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-27 23:00 UTC (permalink / raw)
To: Yonghong Song
Cc: bpf, netdev, ast, andrii, daniel, kernel-team, edumazet,
martin.lau
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 27 Oct 2023 11:24:24 -0700 you wrote:
> With latest sync from net-next tree, bpf-next has a bpf selftest failure:
> [root@arch-fb-vm1 bpf]# ./test_progs -t setget_sockopt
> ...
> [ 76.194349] ============================================
> [ 76.194682] WARNING: possible recursive locking detected
> [ 76.195039] 6.6.0-rc7-g37884503df08-dirty #67 Tainted: G W OE
> [ 76.195518] --------------------------------------------
> [ 76.195852] new_name/154 is trying to acquire lock:
> [ 76.196159] ffff8c3e06ad8d30 (sk_lock-AF_INET){+.+.}-{0:0}, at: ip_sock_set_tos+0x19/0x30
> [ 76.196669]
> [ 76.196669] but task is already holding lock:
> [ 76.197028] ffff8c3e06ad8d30 (sk_lock-AF_INET){+.+.}-{0:0}, at: inet_listen+0x21/0x70
> [ 76.197517]
> [ 76.197517] other info that might help us debug this:
> [ 76.197919] Possible unsafe locking scenario:
> [ 76.197919]
> [ 76.198287] CPU0
> [ 76.198444] ----
> [ 76.198600] lock(sk_lock-AF_INET);
> [ 76.198831] lock(sk_lock-AF_INET);
> [ 76.199062]
> [ 76.199062] *** DEADLOCK ***
> [ 76.199062]
> [ 76.199420] May be due to missing lock nesting notation
> [ 76.199420]
> [ 76.199879] 2 locks held by new_name/154:
> [ 76.200131] #0: ffff8c3e06ad8d30 (sk_lock-AF_INET){+.+.}-{0:0}, at: inet_listen+0x21/0x70
> [ 76.200644] #1: ffffffff90f96a40 (rcu_read_lock){....}-{1:2}, at: __cgroup_bpf_run_filter_sock_ops+0x55/0x290
> [ 76.201268]
> [ 76.201268] stack backtrace:
> [ 76.201538] CPU: 4 PID: 154 Comm: new_name Tainted: G W OE 6.6.0-rc7-g37884503df08-dirty #67
> [ 76.202134] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
> [ 76.202699] Call Trace:
> [ 76.202858] <TASK>
> [ 76.203002] dump_stack_lvl+0x4b/0x80
> [ 76.203239] __lock_acquire+0x740/0x1ec0
> [ 76.203503] lock_acquire+0xc1/0x2a0
> [ 76.203766] ? ip_sock_set_tos+0x19/0x30
> [ 76.204050] ? sk_stream_write_space+0x12a/0x230
> [ 76.204389] ? lock_release+0xbe/0x260
> [ 76.204661] lock_sock_nested+0x32/0x80
> [ 76.204942] ? ip_sock_set_tos+0x19/0x30
> [ 76.205208] ip_sock_set_tos+0x19/0x30
> [ 76.205452] do_ip_setsockopt+0x4b3/0x1580
> [ 76.205719] __bpf_setsockopt+0x62/0xa0
> [ 76.205963] bpf_sock_ops_setsockopt+0x11/0x20
> [ 76.206247] bpf_prog_630217292049c96e_bpf_test_sockopt_int+0xbc/0x123
> [ 76.206660] bpf_prog_493685a3bae00bbd_bpf_test_ip_sockopt+0x49/0x4b
> [ 76.207055] bpf_prog_b0bcd27f269aeea0_skops_sockopt+0x44c/0xec7
> [ 76.207437] __cgroup_bpf_run_filter_sock_ops+0xda/0x290
> [ 76.207829] __inet_listen_sk+0x108/0x1b0
> [ 76.208122] inet_listen+0x48/0x70
> [ 76.208373] __sys_listen+0x74/0xb0
> [ 76.208630] __x64_sys_listen+0x16/0x20
> [ 76.208911] do_syscall_64+0x3f/0x90
> [ 76.209174] entry_SYSCALL_64_after_hwframe+0x6e/0xd8
> ...
>
> [...]
Here is the summary with links:
- [net-next] net: bpf: Use sockopt_lock_sock() in ip_sock_set_tos()
https://git.kernel.org/netdev/net-next/c/06497763c8f1
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-27 23:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27 18:24 [PATCH net-next] net: bpf: Use sockopt_lock_sock() in ip_sock_set_tos() Yonghong Song
2023-10-27 18:42 ` Eric Dumazet
2023-10-27 23:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox