Article View: linux.kernel.netdev
Article #7089[PATCH net] net/mlx5e: macsec: free SC lookup entries after an RCU grace period
From: Joas Antonio dos Santos
Date: Sat, 24 Oct 2026 16:21
Date: Sat, 24 Oct 2026 16:21
64 lines
14228 bytes
14228 bytes
macsec_del_rxsc_ctx() removes rx_sc->sc_xarray_element from
macsec->sc_xarray with xa_erase() and frees it with kfree() right away.
mlx5e_macsec_offload_handle_rx_skb() looks the element up with
xa_load() under rcu_read_lock() and then dereferences ->rx_sc, so an RX
completion that loaded the element just before xa_erase() reads freed
memory. rx_sc itself is already freed with kfree_rcu_mightsleep(); only
the element pointing to it was missed.
macsec_fs_id_del() has the same problem on the TX side: it removes
fs_id_found from the SCI rhashtable and frees it with kfree(), while
mlx5e_macsec_handle_tx_skb() and mlx5e_macsec_tx_build_eseg() read it
through mlx5_macsec_fs_get_fs_id_from_hashtable(), which uses
rhashtable_lookup() under rcu_read_lock().
Free both with kvfree_rcu_mightsleep(). Both run in process context
from the macsec offload ops, outside any spinlock, so sleeping is fine.
The sc_xarray_element issue was pointed out during review of
"net/mlx5e: macsec: fix use-after-free of metadata_dst on RX SC delete"
and left for a follow-up; this is that follow-up.
Fixes: b7c9400cbc48 ("net/mlx5e: Implement MACsec Rx data path using MACsec skb_metadata_dst")
Signed-off-by: Joas Antonio dos Santos <joasantonio108@gmail.com>
Assisted-by: Yaga Agent HackerSec Claude:claude-opus-5-5
---
Testing: compile-tested only (arm64, W=1, CONFIG_MLX5_MACSEC=y, no new
warnings). I do not have MACsec-capable ConnectX hardware, so this was
not run on a real device and I have no reproducer against the driver
itself. The free-while-reader-holds-RCU pattern was reproduced with a
standalone test module under KASAN (slab-use-after-free on kmalloc-16),
and the same module showed no reports after switching to
kvfree_rcu_mightsleep().
drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 2 +-
drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
index 38a3415ac..fb9126f6b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c
@@ -839,7 +839,7 @@ static void macsec_del_rxsc_ctx(struct mlx5e_macsec *macsec, struct mlx5e_macsec
list_del_rcu(&rx_sc->rx_sc_list_element);
xa_erase(&macsec->sc_xarray, rx_sc->sc_xarray_element->fs_id);
dst_release(&rx_sc->md_dst->dst);
- kfree(rx_sc->sc_xarray_element);
+ kvfree_rcu_mightsleep(rx_sc->sc_xarray_element);
kfree_rcu_mightsleep(rx_sc);
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
index efc516749..910fafe40 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/macsec_fs.c
@@ -684,7 +684,7 @@ static void macsec_fs_id_del(struct list_head *macsec_devices_list, u32 fs_id,
xa_erase(fs_id_xa, fs_id);
- kfree(fs_id_found);
+ kvfree_rcu_mightsleep(fs_id_found);
if (macsec_fs_is_macsec_device_empty(macsec_device)) {
list_del(&macsec_device->macsec_devices_list_entry);
Technical Details
Message-ID:
<179285888829.90275.17386097105525068016@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351423-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351423-linux-kernel-netdev=dewy.ru
From: joasantonio108@gmail.com (Joas Antonio dos Santos)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] net/mlx5e: macsec: free SC lookup entries after an RCU
grace period
Date: Sat, 24 Oct 2026 13:21:28 -0300
Organization: Usenet Network
Message-ID: <179285888829.90275.17386097105525068016@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="803953"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:WYM5JLDqdphcE3+z5SPVOuq2O44= sha256:vryt8htbEtdodnjugGsZ4BVf9NKnYFjxXZKt87xzbsI=
sha1:TXNa6yhZ7MFsbH7iYiR1qy9PLg0= sha256:QqGfaXpZUeUuvSx+SHlRna7mdipvUa+TniNbzdoT6PQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 23A72111681; Sat, 24 Oct 2026 19:24:27 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id b1JDCiYQin15;
Sat, 24 Oct 2026 19:24:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351423-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 9EC56111678; Sat, 24 Oct 2026 19:24:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 4D40A36E1F; Sat, 24 Oct 2026 16:21:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1792858895;
b=U49E2SkR/o9e6QkfiyMp/DSNT/4Az2QYxlZL1eQce+AC60qCoKERPhoIud/HkOysWRby
FUXUBvb3C+sr0RbjzgFihvJGG772l6+GNQyC4OelPnOs8xt0CzyWUgA3hzwfe6/bhOsW2
xuzGCLl0CGHzAyr5IoLi8ZudjtHvhc5uDvfjrs8hSnW1vLIw0aQw2dO1qw7OK0AmNBuuU
dimsgWDud1XIn0fH4Fhnv+WdB3zKH4lsxad/asoD0DTsu0JmI4ukaWV4Bzs/rDjFtnWde
bQ5GpOT5VAKiJTpbd4K23FjE3heaA0hUjjYVTirAh6OUts1hIBIzAjrAys/QbXAn2Pw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792858895;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version;
bh=F6yz0j17ZlA2N3jpWRgDpMHKo6hhIh1hOz7KuS7dRpI=;
b=3ADvPwc8MQLpuZpwZjWQUSlat4Zk2/43B6fFzzPIihF8p+hJhBVvMdGTZ89CO1OB1IpI
r9xEbF8MiaEo8wg4+M1J1zNeWb7V5gRI1TAPYvF3elYQkntFDmwpR6MPgwPwZGX92aKF1
4ntR0VpHrfSZ49ot7XiHPktLNMJGjswGRTxuEKOQSBK2gXC+YMhoxofIn4KDnw/aEgT8T
015G6kN1EtSMwwBkE9jRkUm04Zawkw4vh4HnGpdJOyp8+ZN16PLHPdpkcVknpVyXKT8UF
jid3+UAHyk66vvlCs3476OMqydFuhASvSwLIDaoQxhm6so+8pAvcKp+kxWBceAlV5mA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=BXiZ4od0;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 18916606A325;
Sat, 24 Oct 2026 16:21:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=BXiZ4od0
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.178
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792858894;
b=YQCuxKFcDZs/o/15R62qHsej9ckhDkTubfkGePOGhlQE4PQc/J7SLzV8G4SoNaLxOEd1
SJPqXYTJCtcOUa6+tMibxTPrTbuLj3x/JT2A5fbIz7pwDBM59uLcjqFsS3+Al5gSKsADp
Nkx+d5JlUm1loUd964xdhzdqoADXMdTnh7cybMMAmXhZOkkABEDoTlK3Dn4cv6aXyvoqe
KpBveMIibjViiYE6tlcbrjab5dRhZBxJHODpFuDA3RvlgncLtn32upk9Kt3/FiegrPG29
VzniAVBSWkzAJnhRxXYBDApKkacEidFJJ5fguRjJtDQu2VgrbRWp7odnyIeovX+LMUw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792858894;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:Content-Type:
Content-Transfer-Encoding:MIME-Version;
bh=F6yz0j17ZlA2N3jpWRgDpMHKo6hhIh1hOz7KuS7dRpI=;
b=ohovgw9qvbsFfbzQzp9oNGqaMt/L/vuiQQCJuHT0ca7otwp+DVWfIUXJQawp0iLtWgrd
Z39sKS40fi88BY2LjtuofF0SjM40buen2WY2dtEXqb+mTy5Nzxv7QM57af6LYfQTIRYHY
Ht7TawDbyam8qJcISug+1d8reRILUd87rO85fPd5WdH+Ncy/R5+MbKoEiiU5vY9r23xb6
BmD2BMiYmZA0UXd6Ftx+reQcH8lTOK9IRtqXKOR2irue+++JPvt615VIlJMAc1eiZV/ae
1YVoSqubgggUAoUSmkrDy9bFadSzvNqxAlTFlWevG2VaDgDHV6V84HEHimk07X/nH+Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=BXiZ4od0;
arc=none smtp.remote-ip=74.125.82.178
X-Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8AA4606A31E
for <netdev@vger.kernel.org>; Sat, 24 Oct 2026 16:21:33 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B8AA4606A31E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-369f3e9e431so45357eec.1
for <netdev@vger.kernel.org>; Sat, 24 Oct 2026 09:21:33 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792858893; x=1793463693; darn=vger.kernel.org;
h=mime-version:content-transfer-encoding:content-type:message-id:date
:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=F6yz0j17ZlA2N3jpWRgDpMHKo6hhIh1hOz7KuS7dRpI=;
b=BXiZ4od0QPRwbJ1HEHXEZYLtBvs7l27b1YDBlLvDljIyAU63OB2ocpUGaqbitr2UE8
U9e0mn5TdgBq7v01NRToS0bUYeZ3PR3hro5KVsLTqXLkuMfKNDMLsfC5VCIXUVxpacZE
9PzBO2uJItxIj8DK0OUoHfDnoCp6yABJB9gzY+MA0D+HUlLt1hHSk9AafZcJYU3oRQGo
YMaDEe7nTEcdJ7kVLy6iwzRB5F/wq+tlPyySqeVVfjk3SK72yGCggtnuaG7vlqNCkwd2
31YuO5ewL3hZuVXK8W+asKZG8KXhBVQETyfuXpXib73rIXukDf7u3E3lCfBWljhb6hfG
kRBQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792858893; x=1793463693;
h=mime-version:content-transfer-encoding:content-type:message-id:date
:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=F6yz0j17ZlA2N3jp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uqTAhFNvCgfL/XhqkuRZNv3wdx0T
FiUwJU77TH3G1I/IGou9j3X98p/GZ7ZWBGnXEla0JA3vsJwDFWdj0shLbofldl5/HTRJ/mY1z7p
MVLQfwLH4B/ENLn1t4yFeCBWuyAW5SIosLCB4jOPmLGYoQ6c5mO7QYPG67LPqmr7OBl8rd4+EWv
BVt+HJwS3nw5fvPZD9YcSC6cb1E+mF1TfBwfADI2osKb437nMK0GdsHqmLCxPLRQkW051jHOXeA
KKMKMPKWqg+mCKqxRrZcjKeWqWGk/GPbIxM8XNfuPpg==
X-Received: by 2002:a05:693c:6395:10b0:359:3991:ce1a with SMTP id 5a478bee46e88-369e84dd2demr3177495eec.16.1792858892703;
Sat, 24 Oct 2026 09:21:32 -0700 (PDT)
X-Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([2804:7f0:b101:277b:c08d:c9f9:7c08:79c4])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-369e8ec4d73sm11664942eec.22.2026.10.24.09.21.29
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sat, 24 Oct 2026 09:21:32 -0700 (PDT)
X-Cc: Boris Pismenny <borisp@nvidia.com>, Sabrina Dubroca <sd@queasysnail.net>,
Andrew Lunn <andrew+netdev@lunn.ch>, David S. Miller <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list