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

Fixes: 11851cbd60ea ("ovpn: implement TCP transport")
Cc: [email protected]
Signed-off-by: Antonio Quartulli <[email protected]>
---

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

diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c
index 74eaf6fac2f5..1b3cd3ea12c5 100644
--- a/drivers/net/ovpn/crypto_aead.c
+++ b/drivers/net/ovpn/crypto_aead.c
@@ -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);
-- 
2.56.1



_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to