]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
macsec: use rcu_work to defer TX SA crypto cleanup out of softirq
authorJinliang Zheng <alexjlzheng@tencent.com>
Mon, 11 May 2026 15:31:00 +0000 (23:31 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 14 May 2026 02:03:05 +0000 (19:03 -0700)
free_txsa() is an RCU callback running in softirq context, but calls
crypto_free_aead() which can invoke vunmap() internally on hardware
crypto drivers (e.g. hisi_sec2), triggering a kernel crash.

Use rcu_work to defer the cleanup to a workqueue, for the same reasons
as the analogous fix to free_rxsa() in the previous patch.

Fixes: c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver")
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Link: https://patch.msgid.link/20260511153102.2640368-4-alexjlzheng@tencent.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/macsec.c
include/net/macsec.h

index e7ad24f1ea5b90a148e5cc14f3c1a0da2dbd55d2..f904f4d16b45fd4d8dbcb610de0814e55567b4af 100644 (file)
@@ -205,9 +205,10 @@ static struct macsec_tx_sa *macsec_txsa_get(struct macsec_tx_sa __rcu *ptr)
        return sa;
 }
 
-static void free_txsa(struct rcu_head *head)
+static void free_txsa_work(struct work_struct *work)
 {
-       struct macsec_tx_sa *sa = container_of(head, struct macsec_tx_sa, rcu);
+       struct macsec_tx_sa *sa =
+               container_of(to_rcu_work(work), struct macsec_tx_sa, destroy_work);
 
        crypto_free_aead(sa->key.tfm);
        free_percpu(sa->stats);
@@ -217,7 +218,7 @@ static void free_txsa(struct rcu_head *head)
 static void macsec_txsa_put(struct macsec_tx_sa *sa)
 {
        if (refcount_dec_and_test(&sa->refcnt))
-               call_rcu(&sa->rcu, free_txsa);
+               queue_rcu_work(macsec_wq, &sa->destroy_work);
 }
 
 static struct macsec_cb *macsec_skb_cb(struct sk_buff *skb)
@@ -1510,6 +1511,7 @@ static int init_tx_sa(struct macsec_tx_sa *tx_sa, char *sak, int key_len,
        tx_sa->active = false;
        refcount_set(&tx_sa->refcnt, 1);
        spin_lock_init(&tx_sa->lock);
+       INIT_RCU_WORK(&tx_sa->destroy_work, free_txsa_work);
 
        return 0;
 }
index 0980ef36fbf0a47582a2d9e363e41ed120e875fc..d962093ee9237536b0a11afdc120f957aac19268 100644 (file)
@@ -176,6 +176,7 @@ struct macsec_rx_sc {
  * @key: key structure
  * @ssci: short secure channel identifier
  * @stats: per-SA stats
+ * @destroy_work: deferred work to free the SA in process context after RCU grace period
  */
 struct macsec_tx_sa {
        struct macsec_key key;
@@ -188,7 +189,7 @@ struct macsec_tx_sa {
        refcount_t refcnt;
        bool active;
        struct macsec_tx_sa_stats __percpu *stats;
-       struct rcu_head rcu;
+       struct rcu_work destroy_work;
 };
 
 /**