Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 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== 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== 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 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 ; Tue, 1 Dec 2026 12:44:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7ED0A606A6AC Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com 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 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 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) 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) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 713F920684 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== 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 Received: (nullmailer pid 1165767 invoked by uid 1000); Tue, 01 Dec 2026 12:43:55 -0000 From: Steffen Klassert To: David Miller , Jakub Kicinski CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 05/22] xfrm: keep old state references until migration deletion completes Date: Tue, 1 Dec 2026 13:41:31 +0100 Message-ID: <20261201124252.1163254-6-steffen.klassert@secunet.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com> References: <20261201124252.1163254-1-steffen.klassert@secunet.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EXCH-02.secunet.de (10.32.0.172) To EXCH-01.secunet.de (10.32.0.171) From: Cen Zhang 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: 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 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 Signed-off-by: Steffen Klassert --- 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