From: Zhou Qiuyue <n0ps1edzz@gmail.com>
To: netdev@vger.kernel.org
Cc: David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
David S. Miller <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Willem de Bruijn <willemb@google.com>,
Hangbin Liu <liuhangbin@gmail.com>,
ipsec@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH net 2/2] xfrm: fix use-after-free in xfrm_lookup_with_ifid()
Date: Fri, 27 Nov 2026 14:39:57 +0800 [thread overview]
Message-ID: <624bf99e815ca1a98d13ef06684c86148166fe9b.1795769101.git.n0ps1edzz@gmail.com> (raw)
In-Reply-To: <cover.1795769101.git.n0ps1edzz@gmail.com>
dst_dev_put() can replace a dst's device with the blackhole device and
drop the reference to the original device. The device can then be freed
after the unregistering netdevice's todo work runs.
xfrm_lookup_with_ifid() reads dst_orig->dev directly in its no-policy
path. It can therefore dereference the original device after that device
has been freed. KASAN reported this race three times while a reproducer
repeatedly deleted and recreated a dummy interface and exercised the XFRM
no-policy path.
Read the device through dst_dev_rcu() in an RCU read-side critical section.
This requires netdev_run_todo() to wait for RCU readers after flushing
routes; that fix is a prerequisite of this patch.
This access was also identified during review of an earlier XFRM device
lifetime fix and left for a follow-up.
OpenAI Codex was used to analyze the supplied KASAN traces and reproducer
and to draft this patch and changelog.
Reported-by: Jakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/netdev/20260908224901.1591334-1-kuba@kernel.org/
Fixes: 2d151d39073a ("xfrm: Add possibility to set the default to block if we have no policy")
Cc: stable@vger.kernel.org
Signed-off-by: Zhou Qiuyue <n0ps1edzz@gmail.com>
---
net/xfrm/xfrm_policy.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index cea6842e6..eafd090e3 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -3186,8 +3186,10 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX];
struct xfrm_dst *xdst;
struct dst_entry *dst, *route;
+ struct net_device *dev;
u16 family = dst_orig->ops->family;
u8 dir = XFRM_POLICY_OUT;
+ bool is_loopback;
int i, err, num_pols, num_xfrms = 0, drop_pols = 0;
dst = NULL;
@@ -3312,7 +3314,12 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,
return dst;
nopol:
- if ((!dst_orig->dev || !(dst_orig->dev->flags & IFF_LOOPBACK)) &&
+ rcu_read_lock();
+ dev = dst_dev_rcu(dst_orig);
+ is_loopback = dev && (dev->flags & IFF_LOOPBACK);
+ rcu_read_unlock();
+
+ if (!is_loopback &&
READ_ONCE(net->xfrm.policy_default[dir]) == XFRM_USERPOLICY_BLOCK) {
err = -EPERM;
goto error;
--
2.56.0
prev parent reply other threads:[~2026-11-27 9:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 8:45 [PATCH net 0/2] ipv4/xfrm: fix two dst->dev lifetime races Zhou Qiuyue
2026-11-27 6:38 ` [PATCH net 1/2] ipv4: route: fix use-after-free in ip_route_output_flow() Zhou Qiuyue
2026-11-27 6:39 ` Zhou Qiuyue [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=624bf99e815ca1a98d13ef06684c86148166fe9b.1795769101.git.n0ps1edzz@gmail.com \
--to=n0ps1edzz@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=ipsec@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liuhangbin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®