Article View: linux.kernel.netdev
Article #13741Re: [PATCH net] xfrm: delete migrated old states before dropping their references
From: netdev-bot+sashiko
Date: Tue, 10 Nov 2026 09:19
Date: Tue, 10 Nov 2026 09:19
102 lines
11785 bytes
11785 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] This patch fixes the Stage 4 x_cur[] path but leaves a matching
use-after-free on the restore_state error path in xfrm_migrate()…
--
xfrm: delete migrated old states before dropping their references
This patch reorders Stage 4 of xfrm_migrate() so the old states in x_cur[]
are deleted before their lookup references are dropped. The states then
stay alive during xfrm_states_delete(), even if an expiry timer or a
concurrent deletion has already removed them from the state tables.
> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index cea6842e6454d..39ca04432220b 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -4726,8 +4726,8 @@ int xfrm_migrate(const struct xfrm_selector *sel, u8 dir, u8 type,
>
> /* Stage 4 - delete old state(s) */
> if (nx_cur) {
> - xfrm_states_put(x_cur, nx_cur);
> xfrm_states_delete(x_cur, nx_cur);
> + xfrm_states_put(x_cur, nx_cur);
> }
[Severity: High]
This fixes the x_cur[] path. Does the restore_state error path in
xfrm_migrate() still have the same use-after-free for the x_new[] states?
net/xfrm/xfrm_policy.c:xfrm_migrate() {
...
restore_state:
if (pol)
xfrm_pol_put(pol);
if (nx_cur)
xfrm_states_put(x_cur, nx_cur);
if (nx_new)
xfrm_states_delete(x_new, nx_new);
...
}
In Stage 2 the new state is stored without taking a reference:
xc = xfrm_state_migrate(x, mp, net, extack);
if (xc) {
x_new[nx_new] = xc;
nx_new++;
By this point xfrm_state_migrate()->xfrm_state_migrate_install() has
already published xc with xfrm_state_insert() or xfrm_state_add(). The
state tables now own its only reference, and __xfrm_state_insert() has
armed mtimer.
Once published, xc can be found by SPI lookup on the data path. Its curlft
was copied from the old SA by xfrm_migrate_sync(). That means it can be
deleted without xfrm_cfg_mutex, for example:
xfrm_state_check_expire() /* hard byte/packet limit reached */
hrtimer_start(&x->mtimer, 0, HRTIMER_MODE_REL_SOFT);
xfrm_timer_handler()
__xfrm_state_delete()
xfrm_state_put() /* drops the only reference */
The 1s mtimer reaching hard_add_expires with the copied add_time has the
same effect.
Userspace can still reach restore_state after xc has been published. One
way is xfrm_policy_migrate() returning -ENODATA (no template matches) or
-ENOENT (dead policy). Another is a later entry's xfrm_state_migrate()
returning NULL, for example -EEXIST from xfrm_state_add(). That later
entry's xfrm_state_migrate_create() allocates with GFP_KERNEL and can
sleep, which makes the window wider.
If xc has already been freed by then, xfrm_state_delete(xc) would take
xc->lock and read xc->km.state on freed memory. If the slab has been
reused, this could also lead to list corruption and another put.
Reordering cannot fix this one, because xfrm_migrate() never holds its own
reference on the x_new[] entries. Could a reference be taken on xc before
it is installed? The parallel path xfrm_do_migrate_state() in xfrm_user.c
already does this:
xfrm_state_hold(xc);
err = xfrm_state_migrate_install(x, xc, &m, extack);
That reference would then be dropped after xfrm_states_delete() in
restore_state, or on the success path.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261106090300.29203-1-juny24602%40gmail.com
Technical Details
Message-ID:
<179430236030.994134.16814357178144716775@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-360010-linux-kernel-netdev=dewy.ruReferences:
<20261106090300.29203-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-360010-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] xfrm: delete migrated old states before dropping their references Date: Tue, 10 Nov 2026 09:19:20 +0000 Organization: Usenet Network Message-ID: <179430236030.994134.16814357178144716775@kernel.org> References: <20261106090300.29203-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="570136"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:4xtjniqi1/3lPxlOe1Zb01b/LJU= sha256:238x7h116vyKl+S64nHP7Yr+1mx5yEsyrNVcYlz1T+E= sha1:YNHV2Yy9lIoLhT61dUZFsE9gaAs= sha256:GoL6OdLY8BzTFZQqpH4KI117GRylB+r0lFiHaBfnak0= 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 CE542113AB3; Tue, 10 Nov 2026 12:32:13 +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 sVqhLpfLBLV5; Tue, 10 Nov 2026 12:32:10 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-360010-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 53E22113AA7; Tue, 10 Nov 2026 12:32:02 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 82E67648C96; Tue, 10 Nov 2026 09:29:51 +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=1794302363; b=N0E8E5NHpk6xdYbUFrpQyz83VsCB8erHifGT8ug8LvMPBI5ae7Awm0bqQA42ky+UcS6i 3i6zkXURJU65conqGYFv+CXnXuoanaQW+YX0J+nq1cPOJweLXPfKDPbLKsU9V15eWBNYe FpurtF3+p8PQNzU9hmE/INcy9jt6C9cSHdvLSTToV3YbrNj33Rzn7UVU9Pv1/Ia+GHj7u 4OoIGdVmiypxRgJ9Z+yvNuo8xqoh98AhaDbtEHBXimPIiv6g/0p8z+jBqpj68xZfHZ5Zm AzQqZ2oewL5Jps1TVxRdCRs/igLHrj3GP3TCNJ9fERuTwDAalU+097pROUvlsyY4uZQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794302363; 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=1lgSH5IuSLix0Y5Q87huJLSem8KubFPPy50MySmjKP8=; b=0WYBWxU28ZrpRcqU0MguY61oycaklB3iPUXtGZK1TZtQNZUsJTo1mfLHZC/n+0QAol1n d8yFelAbYqVwLGQxwOtBsOlCBmLPbv6N6FGL6RI4xcL/wvq//RG7iW1IFJyJ9zq/VDMzG +a8zre/kPHLR0e6EtgC+BJ6lhk/Fg9faAWx5GI8/KE6+pJcJsnl2+BOqmhQWHXAn8wGLf ent8VRng7ef0MtIFXw3HVKghUa2phqSKpdnTdFDRi8rFG0CxXPz9YtgBBEGIxU23Oljfg 1vM9Kxg4oQjZLux7fvUTxe0VNqL7yd+1PpKyxtRoVpU+c02PSqfTxhPqa0hvGDNaNVg== 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=LgUEMCiU; 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 244B5606C66B; Tue, 10 Nov 2026 09:19:23 +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=LgUEMCiU 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=1794302362; b=E9aF8WL8zsqOxnfSyl8q+uYIGnjgNktxtBYSn9Ym6nqnC6iiye5PlIOX5wMX9QCaTD7A 9Vav0qW2qXqPIsRtqdz0z89+v/jE9sJ5zsfaBLFn5LjOuK4d1hpu1bK8iyZgo5mZOdMec +vr9pGabCS9jBDP+fw1e/pCoLugfxjJSjOLoPtAcAA35BvgJHmH102iWrqK+MeqKD5zAS 7n89DzEru6RDHBsnknA3XJPdQProWAXOc3mPbAT8yKKiHPKhe6PUvykIqLEGMt/N09EHi z+2edxZYk5aykRlgENjzKeB5fDT6sSst72FXbLY/AkD3y5LRRfrYXSYd35qDOe5WuTg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794302362; 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=1lgSH5IuSLix0Y5Q87huJLSem8KubFPPy50MySmjKP8=; b=R7zK9db2l45SvJAGBVTS7u/MkYesPLpsxWUwEXM1qH2aT2KVhEKopx8BFjQYShyz71pA BILH/MGhEUGaGhM7WMeZE56VCT7agdttlVQs7LMVsIZ4eSYOFvjAS8/KeON/avdq3WAAC 4lKvZnKKEKYSvxhBfxOXZcd4ggUu16lDfT7+0P50zFqSoxyMvAlgubmF/KtfS5BjrTQ0H 0xwila+MTZytbUWb6p+Mw4igrcDYW4qDhbEm8J0EhUEocknphPYmkLQ5OYfVIFv+dodKF SYUvbpgY+59meJq93RCPBSwHJFe1NzO0n2fJo2GXlGqHm4/137wGjUaA1sxYFh9fh6g== 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=LgUEMCiU; 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 003AD606C664 for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 09:19:21 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7A851F008A1; Tue, 10 Nov 2026 09:19:20 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794302361; bh=1lgSH5IuSLix0Y5Q87huJLSem8KubFPPy50MySmjKP8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=LgUEMCiUH2lU8GtyM2P3dC/cJl6bV1TVHO5hk3KByLZ90bsVLRMFUi7jpANyh/wVG YVRfk18tHXTX9iqGxzK/CaHM1vd9MIbrf8uF/NkcTe63v4OeanR6zwYN1qL4EB/vxx kPvU1NvCAkIRA/288HfFguyLdO1+hNOUCt4oXedIoU3cYkBaDmivVAqXBuz2zn4p23 V3c38rCT00uxd81iuF+CvOUOL3mrDDZAF+HQZTO6MRz5DpWeT8bzo1pwrKIMZTgd0s EP92SXJT2fpuLHbFfB5knewq5ZNqBZIOon8hGfLGZoo1lKvbp4UyViFRoDF5+E1vYZ HWlXbttV8+26w== 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, shinta.sugimoto@ericsson.com, yoshfuji@linux-ipv6.org, nakam@linux-ipv6.org, netdev@vger.kernel.org, junvyyang@tencent.com, stable@kernel.org, corvus@tencent.com X-In-Reply-To: <20261106090300.29203-1-juny24602@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