ovpn: fix incorrect use of rcu_access_pointer()
Subsystems (2)
PATCH 1/1 ovpn: fix incorrect use of rcu_access_pointer()
rcu_access_pointer() should only be used to test the value of a pointer, not to dereference it. Use rcu_dereference() instead. No extra rcu_read_lock() is needed here, as the spin_lock_bh() above marks an RCU critical section.
--- drivers/net/ovpn/peer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ovpn/peer.c +1 -1
@@ -1164,7 +1164,7 @@ static void ovpn_peer_release_p2p(struct ovpn_priv *ovpn, struct sock *sk, }if (sk) { - ovpn_sock =rcu_access_pointer (peer->sock); + ovpn_sock =rcu_dereference (peer->sock);if (!ovpn_sock || ovpn_sock->sk != sk) {spin_unlock_bh (&ovpn->lock);ovpn_peer_put (peer);
Signature · 8 lines
2.43.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi!
Quoted 16 lines · Qingfang Deng
rcu_access_pointer()should only be used to test the value of a pointer, not to dereference it. Usercu_dereference()instead. No extrarcu_read_lock()is needed here, as thespin_lock_bh()above marks an RCU critical section.Fixes f6226ae7a0cd ("ovpn: introduce the ovpn_socket object")Signed-off-by Qingfang Deng <[email protected]>--- drivers/net/ovpn/peer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ovpn/peer.c +0
-0
drivers/net/ovpn/peer.c static void ovpn_peer_release_p2p(struct ovpn_priv *ovpn, struct sock *sk, · line 1167
Quoted 5 lines
drivers/net/ovpn/peer.c +1
-1@@ -1164,7 +1164,7 @@ static void ovpn_peer_release_p2p(struct ovpn_priv *ovpn, struct sock *sk, }if (sk) { - ovpn_sock =rcu_access_pointer (peer->sock); + ovpn_sock =rcu_dereference (peer->sock);
Sashiko says:
Using rcu_dereference() instead of rcu_dereference_bh() under spin_lock_bh() triggers a lockdep warning.
Signature · 8 lines
Antonio Quartulli _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi,
Quoted 27 lines · Antonio Quartulli
Hi!
Quoted 16 lines · Qingfang Deng
rcu_access_pointer()should only be used to test the value of a pointer, not to dereference it. Usercu_dereference()instead. No extrarcu_read_lock()is needed here, as thespin_lock_bh()above marks an RCU critical section.Fixes f6226ae7a0cd ("ovpn: introduce the ovpn_socket object")Signed-off-by Qingfang Deng <[email protected]>---
drivers/net/ovpn/peer.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ovpn/peer.c +0
-0drivers/net/ovpn/peer.c static void ovpn_peer_release_p2p(struct · line 1167
Quoted 5 lines
drivers/net/ovpn/peer.c +1
-1@@ -1164,7 +1164,7 @@ static void ovpn_peer_release_p2p(struct ovpn_priv *ovpn, struct sock *sk, } if (sk) { - ovpn_sock = rcu_access_pointer(peer->sock); + ovpn_sock = rcu_dereference(peer->sock);Sashiko says:
Quoted 2 lines
Using
rcu_dereference()instead ofrcu_dereference_bh()underspin_lock_bh()triggers a lockdep warning.
I think rcu_dereference() has more relax checks than rcu_dereference_bh() and Sashiko is wrong, i.e. using rcu_dereference() in a BH-disabled context is okay, but using rcu_dereference_bh() in a process context with only rcu_read_lock() is _not_ okay. Can you verify that?
Best regards,
Qingfang
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Ralf Lici
reviewerQuoted 1 line · Qingfang Deng
Hi,
Hi Qingfang,
Quoted 28 lines · Antonio Quartulli
Quoted 27 lines
Hi!
Quoted 16 lines · Qingfang Deng
rcu_access_pointer()should only be used to test the value of a pointer, not to dereference it. Usercu_dereference()instead. No extrarcu_read_lock()is needed here, as thespin_lock_bh()above marks an RCU critical section.Fixes f6226ae7a0cd ("ovpn: introduce the ovpn_socket object")Signed-off-by Qingfang Deng <[email protected]>---
drivers/net/ovpn/peer.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/ovpn/peer.c +0
-0drivers/net/ovpn/peer.c static void ovpn_peer_release_p2p(struct · line 1167
Quoted 5 lines
drivers/net/ovpn/peer.c +1
-1@@ -1164,7 +1164,7 @@ static void ovpn_peer_release_p2p(struct ovpn_priv *ovpn, struct sock *sk, } if (sk) { - ovpn_sock = rcu_access_pointer(peer->sock); + ovpn_sock = rcu_dereference(peer->sock);Sashiko says:
Quoted 9 lines
Quoted 3 lines
Using
rcu_dereference()instead ofrcu_dereference_bh()underspin_lock_bh()triggers a lockdep warning.I think
rcu_dereference()has more relax checks thanrcu_dereference_bh()and Sashiko is wrong, i.e. usingrcu_dereference()in a BH-disabled context is okay, but usingrcu_dereference_bh()in a process context with onlyrcu_read_lock()is _not_ okay. Can you verify that?
rcu_dereference relies on rcu_read_lock_held to check that the caller context is valid. However, ovpn_peer_release_p2p does not hold a normal rcu_read_lock section, it relies on the BH-disabled section established by spin_lock_bh instead.
rcu_read_lock_held does not consider BH-disabled context, so it will return false here. In contrast, rcu_read_lock_bh_held explicitly recognizes BH-disabled/softirq context.
So I think Sashiko is right: rcu_dereference will trigger its RCU lockdep warning with CONFIG_PROVE_RCU enabled. This should use rcu_dereference_bh instead.
Kind regards.
Signature · 8 lines
Ralf Lici Mandelbit Srl _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Hi Ralf,
Quoted 5 lines · Ralf Lici
rcu_dereferencerelies onrcu_read_lock_heldto check that the caller context is valid. However,ovpn_peer_release_p2pdoes not hold a normalrcu_read_locksection, it relies on the BH-disabled section established byspin_lock_bhinstead.
Quoted 7 lines
rcu_read_lock_helddoes not consider BH-disabled context, so it will return false here. In contrast,rcu_read_lock_bh_heldexplicitly recognizes BH-disabled/softirq context.So I think Sashiko is right:
rcu_dereferencewill trigger its RCU lockdep warning withCONFIG_PROVE_RCUenabled. This should usercu_dereference_bhinstead.
I read the code, and found that you are correct. I'll submit a new patch with your suggested change. Thank you.
Best regards,
Qingfang
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
hi Qingfang,
When resending, please split the subject as "ovpn net" so that our patchwork can pick it up correctly.
Thanks a lot!
Il 24 Luglio 2026 03:20:51 CEST, Qingfang Deng <[email protected]> ha scritto:
Quoted 16 lines
Hi Ralf,
Quoted 5 lines · Ralf Lici
rcu_dereferencerelies onrcu_read_lock_heldto check that the caller context is valid. However,ovpn_peer_release_p2pdoes not hold a normalrcu_read_locksection, it relies on the BH-disabled section established byspin_lock_bhinstead.Quoted 7 lines
rcu_read_lock_helddoes not consider BH-disabled context, so it will return false here. In contrast,rcu_read_lock_bh_heldexplicitly recognizes BH-disabled/softirq context.So I think Sashiko is right:
rcu_dereferencewill trigger its RCU lockdep warning withCONFIG_PROVE_RCUenabled. This should usercu_dereference_bhinstead.
Quoted 6 lines
I read the code, and found that you are correct. I'll submit a new patch with your suggested change. Thank you.
Best regards,
Qingfang
Antonio Quartulli
Edited on mobile, please excuse typos and brevity.
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Quoted 3 lines · Antonio Quartulli
hi Qingfang,
When resending, please split the subject as "ovpn net" so that our patchwork can pick it up correctly.
Oops, I resent too early..
Quoted 5 lines
Thanks a lot!
Antonio Quartulli
Edited on mobile, please excuse typos and brevity.
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel