From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796129060; b=PFrtjLX8cMosV7sphxRbkwYSjVWR6M7FgvWhVUstV/xKRyKG39UYPYeuaUjW4wHIis5X 9Y7xtZNq1XKfhw4ND13prvfogK/5j/Ar8tzKONVtQ7NzSXtqWIv+xTsgKp3BQPcyfXfoW NsKOGhyfNJlpTWLQtA31W8kSEGUCF58qg1fU5gmEJ4h5fHmsXcxGgRfT68vvSNnsww5zs 6sMPuVItZl9nR2OnxRE4PK47YutLDW2oU/KhOsb98kgKnUrdvbsyAg9lsnvkhK1INVJOV Y/h3pljueIPZFaz6R0fo+qKPROnKL0pxEPMAqqB1+zz+mT6HE5nK3AdTfVzaj3tP2eA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129060; 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=wizKlGFUZfxn0/zITkTvGwjNcNXXYs6uD0FmIdnaqa8=; b=yG4OC9Avs98e/AyRUGZ5rt19s2laf9/60y2wy6YErbM8fUlr7Hpdm30Dt/NLattnPSoG 8HJHJCbWum1U/DUFxhJSYP8kmvnfKWJK/dpVHAO9Wfp67z/I6Nx0TW+E6fWQFmVIHkCEH iB6NiLsha/l48FPr6wMTiigZZGpxs3Hb9sjMuKwyp08LJt7bUoSWcrcRnu5kZ8v5VnvFP q8WsWwRIrsFnnQIwrdNZ6loE8wL2poGTBGBOL6DwD8ozPYyYOhtUc08a/bMpZVdn9hJsf x5b+SdVFwO6RWMIVw+efMTqT4jkwlv1PIAZBr73N9ED1X/0pNgGGJHLFropLSB7pkyQ== 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=yjaLx+xW; 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 0B99D606A334 for ; Tue, 1 Dec 2026 12:44:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0B99D606A334 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=yjaLx+xW Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id B1E40205E3; Tue, 1 Dec 2026 13:44:18 +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 t6Tz-dAoaMkk; Tue, 1 Dec 2026 13:44:18 +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 E146320684; Tue, 1 Dec 2026 13:44:17 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com E146320684 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1796129057; bh=wizKlGFUZfxn0/zITkTvGwjNcNXXYs6uD0FmIdnaqa8=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=yjaLx+xWuRkS/cdkYqbPa9lGnkVkzHBqcGm6hhauje+cc+5mc5buaRsz+g8oHqPlq 7BWb+eDifWOAV5FOO9Q4eDVCEGpKb9DmbZjn2A0aZ4AU3ustVtqhTqo/hHM3wH6N+h dXKUrlrXrjMC88vXFxd2B4kX1AHR9uCt3vnpwz66Rhgd/mEsCX3+iGTWSn9KRKe2TN Tjjlq3nzmmgs+SlIbuMIsZ+ndvxkFQBnLntGnj6uG2Xuy3DxH0WcMfIVtoFilCKjf/ 83mHmpMwSEW1nBU1kmVdj867slGrdnpeBH3WW6199thO9xyNvB3Se8jPMwChv4IJsf uN+KgK+pUtDkw== 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:17 +0100 Received: (nullmailer pid 1165760 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 03/22] xfrm: keep the mode module pinned until destroy_state returns Date: Tue, 1 Dec 2026 13:41:29 +0100 Message-ID: <20261201124252.1163254-4-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 An IPTFS state keeps its mode module referenced while mode_data exists. However, iptfs_destroy_state() drops that reference before returning to xfrm_state_gc_destroy(), which has no reference covering the callback's return path. With CONFIG_XFRM_IPTFS=m and module unloading enabled, deleting the last IPTFS SA can overlap with ordinary module removal in this order: XFRM GC worker rmmod xfrm_iptfs iptfs_destroy_state() free mode_data module_put(owner) delete_module() xfrm_iptfs_fini() unregister mode callbacks free_module() resume in freed module text An unload started after the put can finish before the callback resumes. GC invokes the callback outside an RCU read-side critical section, after its grace period. The RCU waits in mode unregistration and module freeing therefore do not protect the callback. The GC mutex only serializes GC with device state flushes. Resuming the callback can cause an instruction-fetch fault in the freed module text. The Oops below was observed on an earlier kernel with scheduling probes holding the worker in module_put() after the decrement until ordinary rmmod completed. The fixture created and deleted the SA over NETLINK_XFRM. Take an additional reference to the already pinned owner before calling destroy_state(), and release it in XFRM core after the callback returns. Cache the owner before the call so releasing the extra reference does not need to access the callback table after the callback has finished. Oops report as below: BUG: unable to handle page fault for address: ffffffffc0407455 #PF: supervisor instruction fetch in kernel mode #PF: error_code(0x0010) - not-present page PGD 80a9067 P4D 80a9067 PUD 80ab067 PMD 0 Oops: Oops: 0010 [#1] SMP KASAN NOPTI CPU: 3 UID: 0 PID: 53 Comm: kworker/3:1 Not tainted 7.2.0-rc5-pmb-xfrm-functional-v1+ #11 PREEMPT(lazy) Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Workqueue: events xfrm_state_gc_task RIP: 0010:0xffffffffc0407455 Code: Unable to access opcode bytes at 0xffffffffc040742b. RSP: 0018:ffff8881013e7aa0 EFLAGS: 00010282 RAX: 0000000000000000 RBX: ffffffffc02199c0 RCX: ffffffff816fc84e RDX: ffff8881013c0000 RSI: 0000000000000000 RDI: ffffffff86338344 RBP: ffff8881013e7ba8 R08: 0000000000000001 R09: 0000000000000001 R10: ffffffff893e0257 R11: ffff8881013c0000 R12: ffff888107e9ec00 R13: ffff888102b07980 R14: ffff888107412ec0 R15: ffff8881013e7ae0 FS: 0000000000000000(0000) GS:ffff8881fd929000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffffc040742b CR3: 00000000080a6006 CR4: 0000000000770ef0 PKRU: 55555554 Call Trace: ? pmbd_gate_maybe+0x47/0x60 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 xfrm_state_gc_task+0x17e/0x790 ? lock_acquire+0x17b/0x2f0 ? __pfx_xfrm_state_gc_task+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_release+0xc8/0x280 ? srso_alias_return_thunk+0x5/0xfbef5 process_one_work+0x908/0x19c0 ? __pfx_process_one_work+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_is_held_type+0x8f/0x100 ? srso_alias_return_thunk+0x5/0xfbef5 worker_thread+0x65c/0xe40 ? srso_alias_return_thunk+0x5/0xfbef5 ? __kthread_parkme+0x175/0x220 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_worker_thread+0x10/0x10 kthread+0x34f/0x460 ? srso_alias_return_thunk+0x5/0xfbef5 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x659/0x940 ? __pfx_ret_from_fork+0x10/0x10 ? srso_alias_return_thunk+0x5/0xfbef5 ? __switch_to+0x74f/0xf80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Modules linked in: [last unloaded: xfrm_iptfs] CR2: ffffffffc0407455 ---[ end trace 0000000000000000 ]--- RIP: 0010:0xffffffffc0407455 Code: Unable to access opcode bytes at 0xffffffffc040742b. RSP: 0018:ffff8881013e7aa0 EFLAGS: 00010282 RAX: 0000000000000000 RBX: ffffffffc02199c0 RCX: ffffffff816fc84e RDX: ffff8881013c0000 RSI: 0000000000000000 RDI: ffffffff86338344 RBP: ffff8881013e7ba8 R08: 0000000000000001 R09: 0000000000000001 R10: ffffffff893e0257 R11: ffff8881013c0000 R12: ffff888107e9ec00 R13: ffff888102b07980 R14: ffff888107412ec0 R15: ffff8881013e7ae0 FS: 0000000000000000(0000) GS:ffff8881fd929000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffffffc040742b CR3: 00000000080a6006 CR4: 0000000000770ef0 PKRU: 55555554 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Fixes: 4b3faf610cc6 ("xfrm: iptfs: add new iptfs xfrm mode impl") Signed-off-by: Cen Zhang Assisted-by: LLM Signed-off-by: Steffen Klassert --- net/xfrm/xfrm_state.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index 0555e5d796ed..45a52771796b 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -596,8 +596,14 @@ EXPORT_SYMBOL(xfrm_state_free); static void xfrm_state_delete_tunnel(struct xfrm_state *x); static void xfrm_state_gc_destroy(struct xfrm_state *x) { - if (x->mode_cbs && x->mode_cbs->destroy_state) + if (x->mode_cbs && x->mode_cbs->destroy_state) { + struct module *owner = x->mode_cbs->owner; + + /* The callback may drop the last module reference. */ + __module_get(owner); x->mode_cbs->destroy_state(x); + module_put(owner); + } hrtimer_cancel(&x->mtimer); timer_delete_sync(&x->rtimer); kfree_sensitive(x->aead); -- 2.53.0