Article View: linux.kernel.netdev
Article #25262[PATCH 05/22] xfrm: keep old state references until migration deletion completes
From: Steffen Klassert
Date: Tue, 01 Dec 2026 12:41
Date: Tue, 01 Dec 2026 12:41
129 lines
14011 bytes
14011 bytes
From: Cen Zhang <zzzccc427@gmail.com>
xfrm_migrate() must retain the references returned by
xfrm_migrate_state_find() until it finishes using the old states. The
successful migration path instead calls xfrm_states_put() before
xfrm_states_delete(), leaving the latter to use unreferenced pointers
from x_cur[].
With CONFIG_XFRM_MIGRATE enabled, a privileged XFRM_MSG_MIGRATE or
SADB_X_MIGRATE request can reach this path for an SA with a finite hard
lifetime and no other users. If migration is preempted after the put,
the old SA can expire and be reclaimed before deletion resumes:
Migration task Hard-expiry timer / GC worker
-------------- -----------------------------
xfrm_migrate_state_find()
hold old SA in x_cur[]
migrate state and policy
xfrm_states_put(x_cur, ...)
drop lookup reference
xfrm_timer_handler()
__xfrm_state_delete(old SA)
drop SAD reference
xfrm_state_gc_task()
synchronize_rcu()
free old SA
xfrm_states_delete(x_cur, ...)
xfrm_state_delete(old SA)
spin_lock_bh(&x->lock) /* use after free */
The configuration mutex does not serialize migration with the timer or
GC worker, and migration holds no RCU read lock across this interval.
xfrm_state_delete() accesses the freed lock before it can check whether
the state is already dead. Expiry before the migration put can open the
same window, with that put dropping the last reference.
Delete the old states before putting their lookup references. Each state
then remains allocated through the lock access and the dead-state check,
including when expiry has already removed it from the SAD.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in _raw_spin_lock_bh+0x38/0x50
Read of size 1 at addr ffff88810967af48 by task python3/443
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
kasan_report+0xe0/0x110
__kasan_check_byte+0x36/0x50
lock_acquire+0x113/0x2f0
_raw_spin_lock_bh+0x38/0x50
xfrm_state_delete+0x26/0x60
xfrm_migrate+0xd26/0x1950
xfrm_do_migrate+0x797/0xad0
xfrm_user_rcv_msg+0x3b3/0xc20
netlink_rcv_skb+0x133/0x390
xfrm_netlink_rcv+0x76/0x90
netlink_unicast+0x504/0x840
netlink_sendmsg+0x7f7/0xcf0
__sys_sendto+0x425/0x470
__x64_sys_sendto+0xe5/0x1c0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
Allocated by task 424:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_slab_alloc+0x89/0x90
kmem_cache_alloc_noprof+0x20b/0x5f0
xfrm_state_alloc+0x28/0x5d0
xfrm_add_sa+0xb81/0x5660
xfrm_user_rcv_msg+0x3b3/0xc20
netlink_rcv_skb+0x133/0x390
xfrm_netlink_rcv+0x76/0x90
netlink_unicast+0x504/0x840
netlink_sendmsg+0x7f7/0xcf0
____sys_sendmsg+0x88b/0x9d0
___sys_sendmsg+0x125/0x1d0
__sys_sendmsg+0x13e/0x1e0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 66:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kmem_cache_free+0x242/0x580
xfrm_state_gc_task+0x534/0x780
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
The buggy address belongs to the object at ffff88810967aec0
which belongs to the cache xfrm_state of size 936
The buggy address is located 136 bytes inside of
freed 936-byte region [ffff88810967aec0, ffff88810967b268)
==================================================================
Fixes: 80c9abaabf42 ("[XFRM]: Extension for dynamic update of endpoint address(es)")
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/xfrm/xfrm_policy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index cea6842e6454..39ca04432220 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);
}
/* Stage 5 - announce */
--
2.53.0
Technical Details
Message-ID:
<20261201124252.1163254-6-steffen.klassert@secunet.com>Path:
mbox-mo1.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375050-linux-kernel-netdev=dewy.ruReferences:
<20261201124252.1163254-1-steffen.klassert@secunet.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375050-linux-kernel-netdev=dewy.ru From: steffen.klassert@secunet.com (Steffen Klassert) Newsgroups: linux.kernel.netdev Subject: [PATCH 05/22] xfrm: keep old state references until migration deletion completes Date: Tue, 1 Dec 2026 13:41:31 +0100 Organization: Usenet Network Message-ID: <20261201124252.1163254-6-steffen.klassert@secunet.com> References: <20261201124252.1163254-1-steffen.klassert@secunet.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1712468"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Ty9OrUWs/dP0dCLneDu7OJRXyLY= sha256:KKGzglClrWWVPpLoGAc23QIYsUjefQdetUxodOMtv/c= sha1:wmYz3lK6hFtjSL0Ujw/7AWvRGEM= sha256:wC8PkdC1912YV4YoEIhf/3ucwd8F1lbZEWcDtrhRzs0= 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 CCB5E117396; Tue, 1 Dec 2026 15:45:08 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=secunet.com 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 nZJ4KI0ZD05M; Tue, 1 Dec 2026 15:45:06 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375050-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id E9FC5117395; Tue, 1 Dec 2026 15:44:57 +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 E616A29FDA; Tue, 1 Dec 2026 12:44:37 +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=1796129059; b=krHrGc3txEUFJWjAbG1WUhRhn2JJeKz3LyOXER48s3z3+S3eOBFSrrBxw9BQRgQAPFB8 kgPp/QFU9XzKVlqZhgQWlBWQnqcsf4QQlPVLOo6FC+g1cYbUyahc3vLZbajn5pp+YDlkR yS/0WU6frtR9HRqhISNREWD1/m1gPXE7+Vbg381vRyLLZSHqGPHj4cx57zG3jY1Ve8DOw PSVPemmhmNjVmOCui1zs/097xz32xZ2ZOseVnX3b+3hfzvZEZgpXsz0ijuQldqcU6yibd hEJ+dslESFhUFHQRR6vXe2AX53BmErtijoKmYXPN16FIe7+hskgudDfyvPPeL99aGWQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129059; h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned: Received:Received:DKIM-Filter:DKIM-Signature:Received:Received:From: To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy; bh=GRZKO5dpa7+idxlWhX3k4ljcMoVGt4FahFIaMHzz56c=; b=zq1ishJMTAk2L1TJg6AAFEWn2aWHnE7hnxmtdk24ZebLJjf5VQL2Z6DqH0FNCrDZSzra /7ec7yGlWWgdSxCa8VrBE0Ryn7gPHoki+BiKCBTPWI6FBjjtdU9NWV4eHfp0vF34GAc/4 pT8Rn6UW9lDVlvupASDO26Bb4ndDUXfXLNG+Rm/yyzORI6ZaUcagFtQTaZz95dObUkPhj Ie9IPlT9QSayfQ92O1ySCrkx8n/XKo8qRwMN2/PJxBirfAj0G1gFDEBo5QklTf6rq//cI vU/DVipOJeI/Cje567Glps3IeWsUNpf4LidrZrWk/eXWsoXSgQcV93GoK4p/1oZjT8A== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=KrC60adq; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; 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 F03B5606A6AB; Tue, 1 Dec 2026 12:44:18 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=KrC60adq X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796129058; b=h+mPHqWVZutNtsmzlNBGDLSHnXuIOfoeAcak52CtbiLQXj82td74W7KY26qK9Hh0a/SM 8K6emZsV1oqgks/Bdf73J46Y76VucEu/d+9hBHZhYyX2TsfcnbXxi/dD+Xp3GiCcEJUdJ LW2vSDmRdYOvT1AqraitW8NNr7zyKmFsUzDC0tv1QFcqT4S/tZDMjCUl3d0Vl57CZzEzT myZ0FFCaFmc3QlTqre89RqrlvKtCgpasPnwCtlQ8ivjYEd6NTKLfIx+S1bL+TZhKUmP3L J8kcNuXfhHjnk7N2Xkku9wg77FiBL6mgnkTke2XsaXsVxixdzAcrY3xMCq40B/iTqZg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129058; h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter: DKIM-Signature:Received:Received:From:To:CC:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy; bh=GRZKO5dpa7+idxlWhX3k4ljcMoVGt4FahFIaMHzz56c=; b=WD30sCdCBFYW+xWejgCVkjGsbUtG0fpOuTo5EOlSyxRH5ojAPx9IO6wwSybPyfO4FJz8 SwsO784pTWT1wX1XB5QUK9BES2ZFW6CcDy3OwuHucurGFfaXiDiEJ6Yk4bcWhY7Y9Rt63 g2OtJVCJQ9vydozKEeomL8Igf4uvnwHfZ2LPDCRQ6CDcTIE5f5eJ1oWohLd4LuUdj5LH2 zT6uUW878AVlV/MaAhWp8uXdT8t4yLpn/Nt2CjwyeBiTpOnpoefUJWGMZQn5SPnqUgNYo pWJTVfVXnKySyIfNJf6sPWBOgtCax7zj89sALqmewhYJeU4jvXfX7hZ6m3Xl209v1Rg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=KrC60adq; arc=none smtp.remote-ip=62.96.220.36 X-Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7ED0A606A6AC for <netdev@vger.kernel.org>; Tue, 1 Dec 2026 12:44:17 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7ED0A606A6AC X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com X-Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id 2AB1F2069C; Tue, 1 Dec 2026 13:44:16 +0100 (CET) X-Virus-Scanned: by secunet X-Received: from mx1.secunet.com ([127.0.0.1]) by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Lo-rK0NubdGp; Tue, 1 Dec 2026 13:44:15 +0100 (CET) X-Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.secunet.com (Postfix) with ESMTPS id 713F920684; Tue, 1 Dec 2026 13:44:15 +0100 (CET) X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 713F920684 X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1796129055; bh=GRZKO5dpa7+idxlWhX3k4ljcMoVGt4FahFIaMHzz56c=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=KrC60adqkKXko3UohxDm2J9MzZtVBA73K5V7Fb+yekuFKKw+yIYEekU217geySK2E EPdlagxSoJBZEc6bXfsV8jLl7gLB2LYTGvOvMv9AvmnCmVM1fKl/FnLzMIhtbGD8Ym G98x674H87mZhh0ArJDM/rXmUwKY7VJYsssHVHDGK9TAq4P51dNsrNNYD9p33nR7GS RAA4OFasOsVKPTQuAMVsdpTx4wTlcOwktf1CPPiFKxBqTneptAiiYtgP6Jo00YbSSA XJ1sWLtuS+hTcKTWOpXQnSXEHbYoRlrQS+FU9MF5pgL8cGtW35Zkv8fDgmNDmzItBM 24Cr6eWKn4p/g== X-Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Tue, 1 Dec 2026 13:44:14 +0100 X-Received: (nullmailer pid 1165767 invoked by uid 1000); Tue, 01 Dec 2026 12:43:55 -0000 X-CC: Herbert Xu <herbert@gondor.apana.org.au>, Steffen Klassert <steffen.klassert@secunet.com>, <netdev@vger.kernel.org> X-Mailer: git-send-email 2.53.0 X-In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com> 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 X-ClientProxiedBy: EXCH-02.secunet.de (10.32.0.172) To EXCH-01.secunet.de (10.32.0.171)