Skip to contentSkip to conversation

bpf: fix recursive lock when verdict program return SK_PASS

PATCH Superseded mrpre 2 participants 4 messages Nov 6, 2024 – Nov 10, 2024

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

mrpre

author
#0 lore raw

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]

Fixes 6648e613226e ("bpf, skmsg: Fix NULL pointer dereference in sk_psock_skb_ingress_enqueue")
---
 net/core/skmsg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/skmsg.c +2 -2
index b1dcbd3be89e..e90fbab703b2 100644
@@ -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
#1 lore raw
Quoted 20 lines · mrpre

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
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")

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

The patch and the earlier discussion make sense to me. John and JakubS, please help to take another look in the next respin.

#2 lore raw
Quoted 31 lines · Martin KaFai Lau
Quoted 20 lines · mrpre

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
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 1 line
Quoted 5 lines
Quoted 3 lines
Fixes 6648e613226e ("bpf, skmsg: Fix NULL pointer dereference in sk_psock_skb_ingress_enqueue")

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.

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

The patch and the earlier discussion make sense to me. John and JakubS, please help to take another look in the next respin.

#3 lore raw
Quoted 37 lines · Martin KaFai Lau
Quoted 36 lines · Martin KaFai Lau
Quoted 20 lines · mrpre

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
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 5 lines
Fixes 6648e613226e ("bpf, skmsg: Fix NULL pointer dereference in

sk_psock_skb_ingress_enqueue")

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_sock fix 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

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.)