Skip to contentSkip to conversation

ovpn: disable BHs in async crypto completion callbacks

PATCH Superseded Antonio Quartulli 1 participant 1 message Nov 25

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ovpn: disable BHs in async crypto completion callbacks

From: Antonio Quartulli <[email protected]>

ovpn_encrypt_post() and ovpn_decrypt_post() expect to run with BHs
disabled: they take socket spinlocks shared with softirq context, pass packets to gro_cells and update per-CPU stats. This holds on the synchronous path, but some async crypto drivers complete requests from a workqueue, a kthread or a threaded IRQ with BHs enabled (e.g. qce, starfive, keembay), which can deadlock or corrupt per-CPU state.

Wrap the async completion callbacks in local_bh_disable()/enable().

Fixes 8534731dbf2d ("ovpn: implement packet processing")
---
 drivers/net/ovpn/crypto_aead.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/net/ovpn/crypto_aead.c +19 -2
index 74eaf6fac2f5..0d96b46304d6 100644
@@ -135,6 +135,23 @@ static struct scatterlist *ovpn_aead_crypto_req_sg(struct crypto_aead *aead,
 			     __alignof__(struct scatterlist));
 }
 
+/* Async crypto drivers are expected to complete requests with BHs
+ * disabled, as the RX/TX paths require, but some do not: enforce it.
+ */
+static void ovpn_aead_encrypt_done(void *data, int ret)
+{
+	local_bh_disable();
+	ovpn_encrypt_post(data, ret);
+	local_bh_enable();
+}
+
+static void ovpn_aead_decrypt_done(void *data, int ret)
+{
+	local_bh_disable();
+	ovpn_decrypt_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 +246,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);
@@ -316,7 +333,7 @@ int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks,
 
 	/* setup async crypto operation */
 	aead_request_set_tfm(req, ks->decrypt);
-	aead_request_set_callback(req, 0, ovpn_decrypt_post, skb);
+	aead_request_set_callback(req, 0, ovpn_aead_decrypt_done, skb);
 	aead_request_set_crypt(req, sg, sg, payload_len + tag_size, 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