ovpn: disable BHs in async encrypt completion callback
Subsystems (2)
PATCH v2 1/1 ovpn: disable BHs in async encrypt completion callback
From: Antonio Quartulli <[email protected]>
ovpn_encrypt_post() may take the TCP transport socket lock with a plain spin_lock(), which requires BHs disabled as the lock is also taken in softirq context. Some async crypto drivers complete requests from a workqueue or kthread with BHs enabled (e.g. qce, starfive, keembay), and a completion can then deadlock against TCP softirq processing on the same CPU.
Crypto drivers are expected to complete with BHs disabled (see crypto_engine's lockdep_assert_in_softirq()), but not all do: wrap the async encrypt completion in local_bh_disable()/enable().
---
v2:
- only wrap the encrypt completion: the RX path already disables BHs where needed
- reword commit message around the TCP socket lock, fix Fixes tag
v1: https://lore.kernel.org/all/[email protected]/
drivers/net/ovpn/crypto_aead.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/ovpn/crypto_aead.c +11 -1
@@ -135,6 +135,16 @@ static struct scatterlist *ovpn_aead_crypto_req_sg(struct crypto_aead *aead, __alignof__(struct scatterlist)); } +/* Crypto drivers should complete requests with BHs disabled, but not all +* do. ovpn_encrypt_post() relies on it (TCP socket lock): enforce it here. +*/ +static void ovpn_aead_encrypt_done (void *data,int ret) +{ +local_bh_disable (); +ovpn_encrypt_post (data, ret); +local_bh_enable (); +} +int ovpn_aead_encrypt (struct ovpn_peer *peer,struct ovpn_crypto_key_slot *ks,struct sk_buff *skb) {
@@ -229,7 +239,7 @@ int ovpn_aead_encrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,/* setup async crypto operation */ aead_request_set_tfm (req, ks->encrypt); -aead_request_set_callback (req,0 , ovpn_encrypt_post, skb); +aead_request_set_callback (req,0 , ovpn_aead_encrypt_done, skb);aead_request_set_crypt (req, sg, sg, skb->len -ovpn_aead_encap_overhead (ks), iv);aead_request_set_ad (req,OVPN_AAD_SIZE );
Signature · 8 lines
2.56.1 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Quoted 9 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]>
ovpn_encrypt_post()may take the TCP transport socket lock with a plainspin_lock(), which requires BHs disabled as the lock is also taken in softirq context. Some async crypto drivers complete requests from a workqueue or kthread with BHs enabled (e.g. qce, starfive, keembay), and a completion can then deadlock against TCP softirq processing on the same CPU.
Quoted 7 lines
Crypto drivers are expected to complete with BHs disabled (see crypto_engine's
lockdep_assert_in_softirq()), but not all do: wrap the async encrypt completion in local_bh_disable()/enable().Fixes 11851cbd60ea ("ovpn: implement TCP transport")Signed-off-by Antonio Quartulli <[email protected]>
One optional nit: adding a lockdep_assert_in_softirq in ovpn_tcp_send_skb would record the "BH must be off here" requirement right at the lock but I wouldn't respin just for that.
Signature · 8 lines
Ralf Lici Mandelbit Srl _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel