Article View: linux.kernel.netdev
Article #23831Re: [PATCH net 2/2] xfrm: fix use-after-free in xfrm_lookup_with_ifid()
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 09:36
Date: Sat, 28 Nov 2026 09:36
131 lines
12573 bytes
12573 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 0
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] The patch does not fix the use-after-free it claims to fix.
--
xfrm: fix use-after-free in xfrm_lookup_with_ifid()
This patch changes the no-policy path of xfrm_lookup_with_ifid(). It now
reads the device of dst_orig through dst_dev_rcu() inside an RCU read-side
critical section, instead of dereferencing dst_orig->dev directly. The
commit message says this depends on a netdev_run_todo() change that waits
for RCU readers.
Link: https://lore.kernel.org/netdev/20260908224901.1591334-1-kuba@kernel.org/
> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index cea6842e6454d..eafd090e3aebc 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
[ ... ]
> @@ -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();
[Severity: High]
In this tree, does this RCU section close the race?
The commit message says:
This requires netdev_run_todo() to wait for RCU readers after flushing
routes; that fix is a prerequisite of this patch.
That change isn't in this tree. Neither this patch nor the earlier
"ipv4: route: fix use-after-free in ip_route_output_flow()" touches
net/core/. The only rcu_barrier() in netdev_run_todo() still runs before
the route flush, and nothing waits for readers after the flush:
net/core/dev.c:netdev_run_todo() {
...
if (!list_empty(&list))
rcu_barrier();
...
if (!list_empty(&list)) {
rt_flush_dev(NULL);
rt6_uncached_list_flush_dev(NULL);
}
cnt = 0;
while (!list_empty(&list)) {
struct net *net;
dev = netdev_wait_allrefs_any(&list);
...
}
rt_flush_dev() and rt6_uncached_list_flush_dev() call
rcu_assign_pointer(rt->dst.dev_rcu, blackhole_netdev). They then drop the
old device reference at once through netdev_ref_replace().
netdev_wait_allrefs_any() returns immediately when netdev_refcnt_read(dev)
is 1. The device is then released through kobject_put() and
netdev_release(), which calls kvfree(dev) without waiting for an RCU grace
period.
The only grace period on the free path is the synchronize_net() in
netdev_napi_exit(). It is skipped when napi_list is empty, which is the
case for the dummy device used in the reproducer.
If dst_orig is an uncached output route, can this sequence still happen?
CPU A
xfrm_lookup_with_ifid()
rcu_read_lock();
dev = dst_dev_rcu(dst_orig);
<preempted under CONFIG_PREEMPT_RCU>
CPU B
netdev_run_todo()
rt_flush_dev(NULL)
rcu_assign_pointer(rt->dst.dev_rcu, blackhole_netdev);
netdev_ref_replace(...);
netdev_wait_allrefs_any() <-- refcnt is 1, returns at once
kobject_put(&dev->dev.kobj)
netdev_release()
kvfree(dev);
CPU A
is_loopback = dev && (dev->flags & IFF_LOOPBACK); <-- freed dev
As far as I can tell, this makes the window smaller but doesn't close it.
That would need a synchronize_rcu() or synchronize_net() in
netdev_run_todo() after the flush and before the devices are freed.
The commit message doesn't give a SHA, Link or Depends-on for the
prerequisite, and the patch is tagged Cc: stable with Fixes: 2d151d39073a.
Could the prerequisite be named explicitly, or sent in the same series as
this patch? Otherwise a stable backport could pick up this patch without
it.
The commit message also names dst_dev_put() as the writer:
dst_dev_put() can replace a dst's device with the blackhole device and
drop the reference to the original device.
The dst_dev_put() calls made from NETDEV_UNREGISTER notifiers are followed
by synchronize_net() in unregister_netdevice_many_notify(). The pointer
swap with no grace period after it seems to be the rt_flush_dev(NULL) and
rt6_uncached_list_flush_dev(NULL) calls in netdev_run_todo(). Would it be
more accurate to describe those calls instead?
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795769101.git.n0ps1edzz%40gmail.com
Technical Details
Message-ID:
<179585858536.3135.14235570619606863005@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373077-linux-kernel-netdev=dewy.ruReferences:
<624bf99e815ca1a98d13ef06684c86148166fe9b.1795769101.git.n0ps1edzz@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373077-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net 2/2] xfrm: fix use-after-free in xfrm_lookup_with_ifid() Date: Sat, 28 Nov 2026 09:36:25 +0000 Organization: Usenet Network Message-ID: <179585858536.3135.14235570619606863005@kernel.org> References: <624bf99e815ca1a98d13ef06684c86148166fe9b.1795769101.git.n0ps1edzz@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="923088"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:k9PMIE0b6WaRyfPlxpVtWEhg53A= sha256:PTjAk7G0lJrJllzID4Ly8F4S7Son48fBtV3tw4LAvFE= sha1:t5GVHr//BdbeuAFplVoHDBhBNIc= sha256:cSOuVlKlDKb9iZ9PvV/sl02/RRNahbCQwY8BLcp90QA= 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 E1A68125F72; Sat, 28 Nov 2026 12:36:52 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.5 X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[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 sTEgRmlPlbZP; Sat, 28 Nov 2026 12:36:45 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-373077-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id E97F0125F70; Sat, 28 Nov 2026 12:36:35 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 6A1212B0E3; Sat, 28 Nov 2026 09:36:33 +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=1795858593; b=pwUCPy8PFnvbgs4tZ2yuOUHnLRE2I9KCn0bjCgMRKm2x6j+ETfILtg/1iPmCPrNo9K70 K+jBEzgrX8YR9iUz+fXO55WEGFCdBViF1NNQGebBCRHYVgbJ6R23PZSITi6pQzxt5+rCi lo/yDsGKqD25AGc7rYCm1hNCCN9mzZa2/E3T741eDlyw289t8cdilM2cz3kibC5RxdHht 2jRMEdHxrSxljL55zN2RFeotcUCOZMUa62vBsjwJs+4a9DtcUL7irtgZs4eWsJRY+3lnn sidJKv0hJiHZgcwpolKjzWLXimJHdoyo/vjx9g5/Z31SuRlAxpWwvWzRabLGl9WHlTA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795858593; 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=DVKtRB77pjKumLl0InNIzwfOdZ0b+h+a09XoRP57V3Q=; b=MovtHdY1RDw0N6KCw1upEpKW4oHTbOynrBQ2fnxAjW/C+RCNZD6Lhi8BpYvKmOeTPk9E aF9u++59xXqLe/7Z1z/Vm7ReuFjNguRpB7zJKmfUhq0IWEbJ8lWYt391tlSJ20Tc0hLDv o7cGy1xS2ZEULvM9VcFXexIfIeQQmsJOugGl91N//Jhz3qtz5KsYBUMOm+ZpFL9K7Ysop Siaeu7vOGspKjScfsrPdATL/ZKGcdKlH36XvxPSryMgTN58a65vwacT9UIdg10/Isritt eWAsXnJeOuI9uXcuSjWCV+JachccppQy8phwJpy4fVZuv9uvNOz+vlVMCPY+bauj1nQ== 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=e099H928; 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 2F389606A326; Sat, 28 Nov 2026 09:36:33 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e099H928 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=1795858587; b=qaC6qu31aNN0YPttU9bsXZTv/Hdc6Oy/uMbQ3oQA4yDZdfk+06FsCipYUBF1PNXNDJGy METkjfwUThRXiRFAkZYQNi+R/xoPj79xASblNLmxGj3ccflyZ54KOXfYbWs8sHdrrJcId WMlK6ltjJxGhVw47m6D8o4QoKwse78BHF0wlv3/UQuakhpw4BUK5hPGKY4wrd2fx+xgWx +tfaH1qWuo/jqDnrTUssOAGB45lxIa2YjXLJ2B3xSBNH2jntMygPptxyQXHPXf8bQMJea TuXZjRgpTAb8YHvbdBHtP4pDpYqMe78rGPAe9W1I9awPaWOU2zcW4yJCFzUTCqVlfgw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795858587; 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=DVKtRB77pjKumLl0InNIzwfOdZ0b+h+a09XoRP57V3Q=; b=s/SW89tSixlQ/AgAsUblyHL6wPKQmkU1o0LhdSDt08rSAGrLwhKZjsW1759bExErEBSx pRKFVGNQMuVidZYhWo5dWmUQL2Ae9AM/jI7iV3nfI+9RaiF6kF5l48kqmeXQi50G74i11 x7td9pMLo4epIS29hXrLZmWQHl3oiTyHunsPQSOnMNnshNxT1bmW/qUcD3TfwEdPkfj17 otCx7zPa+fKEqX5spMrJsQtistABrDMgyHXuSuW8GENZbCO1pFu8dvyOGjgvU2h89rKge zOUzGOopc/bDjQ6KU1ZaYV0zd4g/IaTdixbt7MVOwrKixFJmUT1QMaf0OBf+SpCbB1w== 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=e099H928; 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 5123B606A32C; Sat, 28 Nov 2026 09:36:27 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C832F1F00898; Sat, 28 Nov 2026 09:36:25 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795858586; bh=DVKtRB77pjKumLl0InNIzwfOdZ0b+h+a09XoRP57V3Q=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=e099H928jPFmoT7jqR3wrxa76wXy7PWyyLoc1j71uvisiJy1MxuLKx5ntf9l0Ng/C ckk/zIKeZR1qpgbA4JpysmKonK8ggAHz4JYG39A1B/hYLH20czOt0S01Z47Ywqs7RC 0WeJHg/RgAGFapL2FQx18xgcwR4LND/DvlSOyac99Oj9M7h6e6A36e5jiz6bGzZNDM tPP6JeFPhl5giT8zlJHg26QAdDU5HxhjIoxFtw4sRNb8ivuqDymvUAhr9qtFBwaklU 94i/fEo8+8lMJApsv+zE72vlGjbny23XsEgkhKzST+TCJkAkrYmjVJsJiQb0y/oESc uz3XmqRt4R//g== X-Cc: netdev@vger.kernel.org, dsahern@kernel.org, idosch@nvidia.com, kuniyu@amazon.com, steffen.klassert@secunet.com, herbert@gondor.apana.org.au, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, willemb@google.com, liuhangbin@gmail.com, ipsec@lists.linux.dev, linux-kernel@vger.kernel.org X-In-Reply-To: <624bf99e815ca1a98d13ef06684c86148166fe9b.1795769101.git.n0ps1edzz@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