Article View: linux.kernel.netdev
Article #9451Re: [PATCH ipsec] xfrm: protect offload statistics device access with RCU
From: netdev-bot+sashiko
Date: Mon, 02 Nov 2026 03:29
Date: Mon, 02 Nov 2026 03:29
169 lines
14405 bytes
14405 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 (1) · Low: 0 (1)
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] On real offload hardware, the new RCU section does not close the
GETSA/dump vs. device-teardown use-after-free that the commit says it…
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but
xfrm_do_migrate_state() (net/xfrm/xfrm_user.c:3462-3463) has the same…
- [Low] This problem wasn't introduced by this patch, but the guard `if
(x->xso.dev)` in copy_to_user_state() (net/xfrm/xfrm_user.c:1184) is a…
--
xfrm: protect offload statistics device access with RCU
This patch wraps the xfrm_dev_state_update_stats() call in
copy_to_user_state() in an RCU read-side critical section. The goal is to
keep the offload net_device alive while GETSA or a dump reads its
xfrmdev_ops. The commit message relies on synchronize_net() during netdevice
unregistration to order the device free after any reader that sampled the
old xso.dev binding.
> diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
> index a5fbe38839c49..e9dd98c387da9 100644
> --- a/net/xfrm/xfrm_user.c
> +++ b/net/xfrm/xfrm_user.c
> @@ -1179,8 +1179,11 @@ static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p)
> memcpy(&p->id, &x->id, sizeof(p->id));
> memcpy(&p->sel, &x->sel, sizeof(p->sel));
> memcpy(&p->lft, &x->lft, sizeof(p->lft));
> + /* Pairs with synchronize_net() in netdevice unregistration. */
> + rcu_read_lock();
> if (x->xso.dev)
[Severity: Low]
This isn't a bug introduced by this patch, but this guard is still a plain
load of x->xso.dev. The writer in xfrm_dev_state_free() uses
WRITE_ONCE(xso->dev, NULL). The other readers in this file,
copy_to_user_state_extra() and xfrm_sa_len(), use READ_ONCE(x->xso.dev).
This line is now inside the new RCU section anyway. Could it use READ_ONCE()
too, so KCSAN doesn't report it as a data race? At runtime it is harmless,
because xfrm_dev_state_update_stats() reloads the pointer with READ_ONCE()
and checks it for NULL.
> xfrm_dev_state_update_stats(x);
> + rcu_read_unlock();
[Severity: High]
Does this RCU section close the GETSA vs. device teardown race on real
offload hardware?
rcu_read_lock() here only delays the final free of the struct net_device.
The driver callback reached through xfrm_dev_state_update_stats() also uses
the driver's per-SA state, and that state is freed without a grace period.
In xfrm_dev_state_free(), the driver state is torn down before the binding
is cleared:
net/xfrm/xfrm_state.c:xfrm_dev_state_free() {
...
if (dev->xfrmdev_ops->xdo_dev_state_free)
dev->xfrmdev_ops->xdo_dev_state_free(dev, x);
WRITE_ONCE(xso->dev, NULL);
xso->type = XFRM_DEV_OFFLOAD_UNSPECIFIED;
netdev_put(dev, &xso->dev_tracker);
...
}
For mlx5, xdo_dev_state_free is mlx5e_xfrm_free_state(). It removes the
flow counters and frees sa_entry right away:
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c:mlx5e_xfrm_free_state() {
...
mlx5e_accel_ipsec_fs_del_rule(sa_entry);
mlx5_ipsec_free_sa_ctx(sa_entry);
...
sa_entry_free:
kfree(sa_entry);
}
A GETSA or SA dump may already have passed the READ_ONCE(xdo->dev) check in
xfrm_dev_state_update_stats(). In that case it goes on to run
mlx5e_xfrm_update_stats():
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c:mlx5e_xfrm_update_stats() {
struct mlx5e_ipsec_sa_entry *sa_entry = to_ipsec_sa_entry(x);
struct mlx5e_ipsec_rule *ipsec_rule = &sa_entry->ipsec_rule;
struct net *net = dev_net(x->xso.dev);
...
}
Can this read the freed sa_entry through the stale x->xso.offload_handle?
Can it also reach the destroyed flow counters through
mlx5_fc_query_cached()?
dev_net(x->xso.dev) is also a new plain load. If WRITE_ONCE(xso->dev, NULL)
lands between the helper's check and this load, would it dereference NULL?
On the teardown side the call chain is:
NETDEV_DOWN/NETDEV_UNREGISTER notifier
xfrm_dev_down() / xfrm_dev_unregister()
xfrm_dev_state_flush()
xfrm_state_delete(x)
xfrm_dev_state_free(x)
xfrm_dev_state_flush() drops xfrm_state_lock before these calls.
xfrm_state_delete() releases x->lock before it returns, and xfrm_cfg_mutex
is not held. The reader holds only xfrm_cfg_mutex in xfrm_get_sa(), or
xfrm_state_lock in the dump walk. Nothing seems to order the two sides.
This is the link-down plus link-delete case described in the commit
message. Does the free side need to clear the binding and wait for a grace
period before calling xdo_dev_state_free()? Alternatively, could the reader
and the free path share a lock such as x->lock?
> memcpy(&p->curlft, &x->curlft, sizeof(p->curlft));
> put_unaligned(x->stats.replay_window, &p->stats.replay_window);
> put_unaligned(x->stats.replay, &p->stats.replay);
[Severity: Medium]
This is a pre-existing issue, not one introduced by this patch.
xfrm_do_migrate_state() in net/xfrm/xfrm_user.c has a similar unprotected
xso.dev access:
net/xfrm/xfrm_user.c:xfrm_do_migrate_state() {
...
if (inherit_offload && x->xso.dev) {
xso_to_xuo(&x->xso, &xuo);
m.xuo = &xuo;
}
...
}
net/xfrm/xfrm_user.c:xso_to_xuo() {
xso_to_xuo_ifindex(xso, xso->dev->ifindex, xuo);
}
This path runs for XFRM_MSG_MIGRATE_STATE on an offloaded SA when neither
XFRMA_OFFLOAD_DEV nor XFRM_MIGRATE_STATE_CLEAR_OFFLOAD is given. It holds
only xfrm_cfg_mutex. There is no device reference, no RCU read lock, no
x->lock and no READ_ONCE() snapshot.
xfrm_dev_state_flush() can run from the netdev notifier and clear xso->dev
between the check and the xso->dev->ifindex load. Can that dereference
NULL? If unregister then completes, could the ifindex read hit a freed
net_device?
The state dump path avoids the device pointer by using the cached ifindex:
net/xfrm/xfrm_user.c:copy_user_state_offload() {
return copy_user_offload_ifindex(xso, READ_ONCE(xso->ifindex), skb);
}
Could the migrate path use READ_ONCE(xso->ifindex) as well?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/pm-xfrm-core-objects-candidate-0050-v3-dbfb7194ffb750193d02%40gmail.com
Technical Details
Message-ID:
<179359016018.3131.9644618161410466770@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354442-linux-kernel-netdev=dewy.ruReferences:
<pm-xfrm-core-objects-candidate-0050-v3-dbfb7194ffb750193d02@gmail.com>Show 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-354442-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH ipsec] xfrm: protect offload statistics device access with RCU Date: Mon, 02 Nov 2026 03:29:20 +0000 Organization: Usenet Network Message-ID: <179359016018.3131.9644618161410466770@kernel.org> References: <pm-xfrm-core-objects-candidate-0050-v3-dbfb7194ffb750193d02@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2837346"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:/E6MqI6qTQs4GPkX+fOlzfB3DPk= sha256:NarZlA4Y3osTaVSnPKSkFZR3WhA4FrHqJyVcfpHMlxE= sha1:ChF+bKapyLQ6+O/X0++3xKTKKkg= sha256:AGE1cTi2U3SpS6EDbf7XgSyG4p8XcMcvEfZDoCkGQVY= 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 DC7FD125CC6; Mon, 2 Nov 2026 06:29:41 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org 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 Vhbw1AnZCe4G; Mon, 2 Nov 2026 06:29:37 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-354442-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id A523C125CC4; Mon, 2 Nov 2026 06:29:28 +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 E05572846F; Mon, 2 Nov 2026 03:29:22 +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=1793590162; b=qtRd3CHu7smpKHRHeJXJroQGdq0n+dXoewh7FNVqjiLUOg4nb8ut1oEh+l9Tl5KzPDdW oE19dKjkrj3ZlTaex0pCO36zgoWBZ7FAQfFyuWaaIbBSP+wV/L49KnDlY1Za6PXWxa7mN vYStxC2BmqN2ZsDGtH6ygUw80xfHv8J9brxKXyQivPqpCqL2IvuU452t/J+7ngmYo7fBS PNxZXCsb+KJXO1dUxlLgQ3YHId0nRnF3f5+ywk9k4CgeCBxhysD8rmYysd1cW1hxSx1D3 Xvb2ZnQLM4VNdmB44RgDxYLEl9qbxbVfFfNbILBn2YcoVCeMeXARhNvAZGHanNCI7hQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793590162; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=CxVfMchF5dsGBfGJzosZhBQYD88YqP9n06Re6kC/c6E=; b=mFx8f385Z+Fik4qm87UbSDON+VjfIgo9q/pTY1YEDb/TNPSZakcUZnl0hLhH9aYKZj7Q bh37fJkzXEGzw0ahWXPn9s4TBL9LnW+RKhtW42abLH7Zvjc4Q0VJgqr5/G3zFHHUF6VSF SUDtvHNHtQoet0IBgRovCGdMF1zlag+8E2JjPlsjqjeA9LDq7b/7EK9eh+JRHlA3SWSgo oigV1MugN66S5fv8vy1qwBcu9FpX6JFP56hYmXy0/WMVlYu0eHCeOccuIzMeK42JG8ZNx Wm+SRSJuQZsiEn2EkglDb4HMg68joH8xhaIGGzutcy0JvFC0uCZOCnJrx8QEW4wIREg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KGjKclDu; 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 B5E2D606A32F; Mon, 2 Nov 2026 03:29:22 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KGjKclDu X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793590161; b=eBWzLYfbS5DMfhI84VnSS+5q8Kh9b6f4tdTOSLV8hQHuU4y3vsVzHQeRAxjIKjfxFDTr qEOTTPhJdB3N3vHBU60dMwdPzwDdU7Ya3g+ajE5qTokmBasWJR+qwEXHots9OOFxWUe59 kOYOtf8s6RjeLEZTwZow6OiLKYBslb8dQgI8iAI66icdeJgZ0Qmmt8R7dQ3DwRFmJJ5QD +XZ2M5GM/5xRCzj9Dbf2mwoQbjXQZJa2p4LU93rHBx1mP5RywlDHIBwLY+HlmtHFQkZCe Tcyo7SpRL0VGEGmL/VttgFLTN1T6jzZ6BERyOH9+k8IPSKYVSBqphmABf56M5fLuQSw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793590161; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=CxVfMchF5dsGBfGJzosZhBQYD88YqP9n06Re6kC/c6E=; b=lyT9LF/JP5cOpq6BhKlxZS5zYwiDZZg8QF2WK24A9aAEreSYDK8l3w9gRN64vaUcYtJ8 to3Ay7sMBM1MEUUBfoUmAfVfVrCPe8ZFEpyRjA7289hRrml9MH+eNuixGZ9DqJGqKmKpC ZjTEw597CeYB1pko5646hWpSia0ammaCgZnEYiiNwKMir0Y8s9iWKKE3/AsZ4WfI8Wdwo OhOpysAMqFscW7xyFuY+y+Ykx8Pq3lkeRXo79zJK6F7Cco4KBPv3p6aw802txCxqGagql TMgL8GTZqidIasfnrSZhI+PWIB2UQsyJFEeL/nGeaIpCtmkP3XxBovB0NamiX85DRaA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KGjKclDu; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F4FA606A324 for <netdev@vger.kernel.org>; Mon, 2 Nov 2026 03:29:21 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9E2B1F000C1; Mon, 2 Nov 2026 03:29:20 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793590161; bh=CxVfMchF5dsGBfGJzosZhBQYD88YqP9n06Re6kC/c6E=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=KGjKclDunLmyO7iL8O4lyI/Fsbc8N9QhhBWaDSJ61perp8DgmhUJn+EacCn8PPeMU 6bNRBMErYwlPOCc+hebW4v2+F5Is8n2lzTQiYwvseLxKWvLLNxCaUvKUt4lgAgh6cd N4YtSsbe87gzTwzO+6cinvKSXfy2ApY6KIBwXtWW5OYtj99na/vtvQ6U3rMIUZaDaT 291fybWrzt4W9TJwS52K+QUk3ghURRrgP9jEHRsNjoPbqLYjtg493EKPUe/2or1zTe o/JlxtsT25aQ3d/8rKA1P9212v7fXziSRw7eAY3cjz0H5gY1Xzdz0KqUdtm0Cfz2ax 02wBdgcQC195A== X-Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au, davem@davemloft.net, netdev@vger.kernel.org, baijiaju1990@gmail.com, jjzuming@gmail.com, kuba@kernel.org X-In-Reply-To: <pm-xfrm-core-objects-candidate-0050-v3-dbfb7194ffb750193d02@gmail.com> X-sashiko-severity: High 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