Article View: linux.kernel.netdev
Article #13760Re: [PATCH net] xfrm: hold migrated state references through xfrm_migrate()
From: netdev-bot+sashiko
Date: Tue, 10 Nov 2026 09:34
Date: Tue, 10 Nov 2026 09:34
114 lines
12093 bytes
12093 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 1 ยท High: 0 ยท 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).
- [Critical] This patch fixes put-before-delete only for x_new[].
--
xfrm: hold migrated state references through xfrm_migrate()
This patch makes xfrm_state_migrate() take a caller reference on the
cloned state before installing it. xfrm_migrate() then drops that
reference after a successful migration, or after deleting the new states
on rollback. The goal is to stop a concurrent deletion, such as one from
the expiry timer, from freeing a migrated state before xfrm_migrate()
calls xfrm_state_delete() on it.
> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index cea6842e6454d..89e5acf4c210b 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -4730,6 +4730,9 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
> xfrm_states_delete(x_cur, nx_cur);
> }
>
> + if (nx_new)
> + xfrm_states_put(x_new, nx_new);
> +
[Severity: Critical]
This fixes the ordering for x_new[]. Can the old states in x_cur[] still
hit the same use-after-free on the success path?
Stage 4 in xfrm_migrate() drops the caller reference first and only then
deletes the states:
net/xfrm/xfrm_policy.c:xfrm_migrate() {
...
/* Stage 4 - delete old state(s) */
if (nx_cur) {
xfrm_states_put(x_cur, nx_cur);
xfrm_states_delete(x_cur, nx_cur);
}
...
}
The put loop releases the reference taken by xfrm_migrate_state_find().
After that, each x_cur[i] is held only by the table reference. Several
paths can drop that reference concurrently, and none of them take
xfrm_cfg_mutex:
- xfrm_timer_handler()->__xfrm_state_delete() on hard expiry
- a PF_KEY SADB_DELETE or flush, serialized by pfkey_mutex instead
- a datapath byte or packet hard limit that fires the timer at once
If that happens between Stage 2 and the put loop, the put in Stage 4 is
the final one. If it happens between the put loop and the delete loop,
the concurrent deleter does the final put. Either way the state goes to
the GC worker:
__xfrm_state_destroy()
-> schedule_work(&xfrm_state_gc_work)
xfrm_state_gc_task()
-> synchronize_rcu()
-> xfrm_state_gc_destroy()
xfrm_migrate() is in preemptible process context and holds no RCU read
lock. Could the free therefore finish before this call reads freed
memory?
xfrm_states_delete(x_cur, nx_cur)
-> xfrm_state_delete(x)
spin_lock_bh(&x->lock);
err = __xfrm_state_delete(x);
If the memory has been reused and km.state no longer reads as DEAD,
__xfrm_state_delete() also unlinks list and hash nodes in freed memory
and puts the state a second time.
nx_cur can be up to XFRM_MAX_DEPTH. The whole put loop finishes before
any delete runs, so the window for later entries also covers the
earlier deletes.
The commit message describes this same situation: a concurrent deletion
frees a migrated state before xfrm_migrate() calls xfrm_state_delete().
Should Stage 4 use the order the new restore_state path uses, that is,
xfrm_states_delete(x_cur, nx_cur) and then xfrm_states_put(x_cur,
nx_cur)?
The peer path xfrm_do_migrate_state() in net/xfrm/xfrm_user.c already
does this. It keeps its lookup reference on x across
__xfrm_state_delete(x) and drops it afterwards.
XFRM_MSG_MIGRATE only requires CAP_NET_ADMIN in the netlink socket's
user namespace. That means a user and net namespace can reach this
path, and the same user controls the SA lifetimes that drive the expiry
timer.
> /* Stage 5 - announce */
> km_migrate(sel, dir, type, m, num_migrate, k, net, encap);
>
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106091511.45429-1-juny24602%40gmail.com
Technical Details
Message-ID:
<179430324333.994134.1099651074842502096@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360029-linux-kernel-netdev=dewy.ruReferences:
<20261106091511.45429-1-juny24602@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360029-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] xfrm: hold migrated state references through xfrm_migrate() Date: Tue, 10 Nov 2026 09:34:03 +0000 Organization: Usenet Network Message-ID: <179430324333.994134.1099651074842502096@kernel.org> References: <20261106091511.45429-1-juny24602@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="573774"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:CLyCxKZx+NJ71HSTzCWWdx7S7qY= sha256:01NPvKOdtozVfyMPZ1qTL/dTudKBOSpDxYaCO1qKU64= sha1:DiDIp9bemAR+j1hJY3V3DA4H4Ug= sha256:2XcnUuCF7fSDqTwjmRxINSP82PlPTBIsUgQZtkatT5M= 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 1D3D1113AC7; Tue, 10 Nov 2026 12:46:52 +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 1ci-KsITrsQH; Tue, 10 Nov 2026 12:46:48 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-360029-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 0CB4E113AC5; Tue, 10 Nov 2026 12:46:37 +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 24C73334E2; Tue, 10 Nov 2026 09:46:05 +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=1794303246; b=ubZ+QQUM47P/fSOvHUDMJ/Ugnet5GWQSiEt3pX5vWhYACUNrJnKbrRez0Pi+6nBSZsGM KaqGDXGGnVnGPIaoERekApc6kQK337oB5SKOveRwWs+VQVW+K4YTnShKQgFL7LRX2+KgF xGIh4ZJ+17zuR1a8ahf6/y8Ay8fNhSpTj4AMf1oAC0MY1DhZZIfEd2h01LJMiNvTrZPsn QwVWD+Tg6qYoy6jCWeKhmwqzTs03S5vutkiFhwQyXedY1IwfnHXMhuo1Ys9slHmbTD+z9 2GpPvBJVn5rdzGPPJFczamZMK8xb6wo4+kwkIRpMP7qdaZ4q0Gpc2N4/6KJsaYg+aDA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794303246; 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=NGAJINqsl0pL1ERlBrJ4oxNTMHJQBWQyUyZoZjOn/ok=; b=ldiPLBvvhpiDlAy4Q0CEe9VwQlaCXHtWsDTqQCjt4/QV9HcdUbEyimfcPK/vAE9n4JH1 3xq37d7oAlBPBA+q3eR/HPqVaALvp1QUgDP4fSkh6M/zV40t98bTgBYT5kiFqdv5jVFIc 1RdUwevLbWHKCUFiM1368UN+YH7sHZ8jpVgoktLxQbLrWCFiOkIKoO0NnNArDRlmyFvkI IEVZc+YPccOMLmE4Mra9o85hlo9JJgAVbATB7FBc3b+haaEXwPYK9sRWwI9dPiAZquWMK AyJMxegBfAsy5tj33qHPGsaOYnsBbrL8OMkLQYggQbT5dt2qgJkSHGQcOpE4GtbuTgQ== 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=g9jMXT0G; 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 E7CA9606D5B4; Tue, 10 Nov 2026 09:34:05 +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=g9jMXT0G 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=1794303245; b=4KAjg2w/VFKbu0I9EuYO1BWRFovQY1Ai/gLfge6RuMj0DdBBX4zAeHmhHDW5gr3GBTkf nTwHtTlIp0epNTqjqEldf+I1pGgVSSVmceQ3aZL41uFfeA81sjKMHhwG38dc6VkUNaQwi BhSAIZSVSx9Y7JgZ7+TB3OWlile/WTlTImQq4saS+PFnMftLb+voZkIlCw2eLwpIF7bL+ f5sIpiNrWraFeAxc0FpLB4/1MxR9G4x5vSMEgOhng63Dxc5FKpChGITru7YnzNq4iPj80 wj4c+/8lUBXjNDnK9GTSrvrUZy8L6xi0/k0gy/iPClnsmBbS0fOCwGOesii1BXCzY4g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794303245; 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=NGAJINqsl0pL1ERlBrJ4oxNTMHJQBWQyUyZoZjOn/ok=; b=sU+Tsv9rs3KuYybA3XMWM2twddvfNTLrVtsDqfwFbZxDf6bxuyQHrJ1iChUmpYtV1KUy IeHOOiACXrxCJuuBmoC3JQhcU74kOyLucsZ7wFfUCCvhr4tUL7HcQd4p67WAfEZMCidpl I7nWX6RclHblnsg1ynwqPxuuz/3R3dpugwCflxAqqGADB1l0A+QIbFq1cPn7Do4sl5ciS k9YDKbX9jxzofXV4UaD2J59T4tdrbpiO87QZnHSUHimTd/V0aCFq9k8pHHzRNXbGX60L7 jR52UVswSly1PIZMC09rmRw5ZHj4L4g196j3DecC15Mh63fr6mH+97VE+5o/tblnjOg== 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=g9jMXT0G; 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 C2957606C66F for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 09:34:04 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBEC41F008A1; Tue, 10 Nov 2026 09:34:03 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794303244; bh=NGAJINqsl0pL1ERlBrJ4oxNTMHJQBWQyUyZoZjOn/ok=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=g9jMXT0G0cmWxS9w0VMQFmnsYVn7N8jG0b3LiFfNO4XCg3SemcYT9b1QRK9RFN8ni +dO4PWeh4VMqHmA2rCNj8asK4dPJvgMhTZ25a9aekOg1/RlYHF9/98jaVGpTc1/TkL iJYwy7IbDO2sxDxPjwyNzU0shkGD4cVzXVk/XtayKuYGF9KHfw+ufzAt6g2hSiYo72 CbBOCjdInDYjzkPO/tw1DHf/CRP10Q47OUDTf63OdV6cS4wIN3+kWufftGOGxsxT+b 1ImavlPlfVfwCWZsQk6JFrJsghcq0QfCPrcdo6L/d1muP5Atbdxxo4j1NyITJryyQI Y5FOrvasPvnGQ== X-Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, nakam@linux-ipv6.org, shinta.sugimoto@ericsson.com, yoshfuji@linux-ipv6.org, netdev@vger.kernel.org, junvyyang@tencent.com, stable@kernel.org, corvus@tencent.com X-In-Reply-To: <20261106091511.45429-1-juny24602@gmail.com> X-sashiko-severity: Critical 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