bpf: fix recursive lock when verdict program return SK_PASS
Subsystems (4)
PATCH 1/1 bpf: fix recursive lock when verdict program return SK_PASS
When the stream_verdict program returns SK_PASS, it places the received skb into its own receive queue, but a recursive lock eventually occurs, leading to an operating system deadlock. This issue has been present since v6.9.
'''sk_psock_strp_data_ready
write_lock_bh(&sk->sk_callback_lock)
strp_data_ready
strp_read_sock
read_sock -> tcp_read_sock
strp_recv
cb.rcv_msg -> sk_psock_strp_read
# now stream_verdict return SK_PASS without peer sock assign
__SK_PASS = sk_psock_map_verd(SK_PASS, NULL)
sk_psock_verdict_apply
sk_psock_skb_ingress_self
sk_psock_skb_ingress_enqueue
sk_psock_data_ready
read_lock_bh(&sk->sk_callback_lock) <= dead lock'''
This topic has been discussed before, but it has not been fixed. Previous discussion:
https://lore.kernel.org/all/[email protected]
--- net/core/skmsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/skmsg.c +2 -2
@@ -1117,9 +1117,9 @@ static void sk_psock_strp_data_ready(struct sock *sk)if (tls_sw_has_ctx_rx (sk)) { psock->saved_data_ready (sk); }else { -write_lock_bh (&sk->sk_callback_lock); +read_lock_bh (&sk->sk_callback_lock);strp_data_ready (&psock->strp); -write_unlock_bh (&sk->sk_callback_lock); +read_unlock_bh (&sk->sk_callback_lock); } }rcu_read_unlock ();
Signature · 1 line
2.43.5
Martin KaFai Lau
reviewerQuoted 20 lines · mrpre
When the
stream_verdictprogram returnsSK_PASS, it places the received skb into its own receive queue, but a recursive lock eventually occurs, leading to an operating system deadlock. This issue has been present since v6.9.'''
sk_psock_strp_data_readywrite_lock_bh(&sk->sk_callback_lock) strp_data_ready strp_read_sock read_sock -> tcp_read_sock strp_recv cb.rcv_msg -> sk_psock_strp_read # now stream_verdict return SK_PASS without peer sock assign __SK_PASS = sk_psock_map_verd(SK_PASS, NULL) sk_psock_verdict_apply sk_psock_skb_ingress_self sk_psock_skb_ingress_enqueue sk_psock_data_ready read_lock_bh(&sk->sk_callback_lock) <= dead lock
Quoted 5 lines
'''
This topic has been discussed before, but it has not been fixed. Previous discussion:
https://lore.kernel.org/all/[email protected]
Is the selftest included in this link still useful to reproduce this bug? If yes, please include that also.
Quoted 4 lines
Fixes 6648e613226e ("bpf, skmsg: Fix NULL pointer dereference in sk_psock_skb_ingress_enqueue")Reported-by Vincent Whitchurch <[email protected]>Signed-off-by Jiayuan Chen <[email protected]>
Please also use the real name in the author (i.e. the email sender). The patch needs a real author name also. I had manually fixed one of your earlier lock_sock fix before applying.
pw-bot: cr
Quoted 1 line
Signed-off-by John Fastabend <[email protected]>
The patch and the earlier discussion make sense to me. John and JakubS, please help to take another look in the next respin.
Martin KaFai Lau
reviewerQuoted 31 lines · Martin KaFai Lau
Quoted 20 lines · mrpre
When the
stream_verdictprogram returnsSK_PASS, it places the received skb into its own receive queue, but a recursive lock eventually occurs, leading to an operating system deadlock. This issue has been present since v6.9.'''
sk_psock_strp_data_ready
write_lock_bh(&sk->sk_callback_lock)
strp_data_ready
strp_read_sock
read_sock->tcp_read_sock
strp_recv
cb.rcv_msg ->sk_psock_strp_read# now stream_verdict return SK_PASS without peer sock assign __SK_PASS = sk_psock_map_verd(SK_PASS, NULL) sk_psock_verdict_apply sk_psock_skb_ingress_self sk_psock_skb_ingress_enqueue sk_psock_data_ready read_lock_bh(&sk->sk_callback_lock) <= dead lockQuoted 5 lines
'''
This topic has been discussed before, but it has not been fixed. Previous discussion:
https://lore.kernel.org/all/[email protected]Is the selftest included in this link still useful to reproduce this bug? If yes, please include that also.
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Fixes 6648e613226e ("bpf, skmsg: Fix NULL pointer dereference in sk_psock_skb_ingress_enqueue")Reported-by Vincent Whitchurch <[email protected]>Signed-off-by Jiayuan Chen <[email protected]>Please also use the real name in the author (i.e. the email sender). The patch needs a real author name also. I had manually fixed one of your earlier
lock_sockfix before applying.
and the bpf mailing list address has a typo in the original patch email... I fixed that in this reply.
Quoted 9 lines
pw-bot: cr
Quoted 1 line
Signed-off-by John Fastabend <[email protected]>The patch and the earlier discussion make sense to me. John and JakubS, please help to take another look in the next respin.
Quoted 37 lines · Martin KaFai Lau
Quoted 36 lines · Martin KaFai Lau
Quoted 20 lines · mrpre
When the
stream_verdictprogram returnsSK_PASS, it places the received skb into its own receive queue, but a recursive lock eventually occurs, leading to an operating system deadlock. This issue has been present since v6.9.'''
sk_psock_strp_data_ready
write_lock_bh(&sk->sk_callback_lock)
strp_data_ready
strp_read_sock
read_sock->tcp_read_sock
strp_recv
cb.rcv_msg ->sk_psock_strp_read# now stream_verdict return SK_PASS without peer sock assign __SK_PASS = sk_psock_map_verd(SK_PASS, NULL) sk_psock_verdict_apply sk_psock_skb_ingress_self sk_psock_skb_ingress_enqueue sk_psock_data_ready read_lock_bh(&sk->sk_callback_lock) <= dead lockQuoted 5 lines
'''
This topic has been discussed before, but it has not been fixed. Previous discussion:
https://lore.kernel.org/all/[email protected]Is the selftest included in this link still useful to reproduce this bug? If yes, please include that also.
Quoted 5 lines
Fixes 6648e613226e ("bpf, skmsg: Fix NULL pointer dereference in
sk_psock_skb_ingress_enqueue")Reported-by Vincent Whitchurch <[email protected]>Signed-off-by Jiayuan Chen <[email protected]>
Quoted 16 lines
Quoted 3 lines
Please also use the real name in the author (i.e. the email sender). The patch needs a real author name also. I had manually fixed one of your earlier
lock_sockfix before applying.and the bpf mailing list address has a typo in the original patch email... I fixed that in this reply.
Quoted 9 lines
pw-bot: cr
Quoted 1 line
Signed-off-by John Fastabend <[email protected]>The patch and the earlier discussion make sense to me. John and JakubS, please help to take another look in the next respin.
Hi Martin,
Thank you for the reminder. I’ve added test case in the new patch,and I found that the deadlock issue can be reproduced 100% of the time whenever the test cases are run. This is indeed a very dangerous defect.
New patch: https://lore.kernel.org/bpf/[email protected]/T/#t
(Additionally, I followed your guidance and used the correct names in the new patch. Thanks again.)