From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=162.62.57.210 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796284509; b=IN0pQ8sLYNMoAJsJL4rRkQL7iFYqz9+yf+OwbZbeezksRaTHGTmfzONiO2MHsqDnanDv UJKtKQJPiJGj03NVk/QEdF2HHAfzXXNiDimJBdu66SWyAYRGlxM3W2lzhyyt3JE4TA+0L XKh2atgNlkI2TqMEXjPQXEO94Q4mShchJ79BCheeaDZk+vID+qcjAf0zulBVN0ME6HvsM l7ZPN+55JbYoAO1XS42W7/Aw+r9lNhTDuDffy9dZC/sjEP8UsxphF3SqICBM1GuX3GMZg 90KMZEJnJLAAopsxeK/XKsTqGd8xy/wqvuS0G8CR6xDMatuYeonEDgc6cZQOivEt2ZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796284509; h=DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:Message-ID: X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:X-OQ-MSGID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=yjxDPHpP6nXn9zPtyOQy86qpl6gpbWdhnUIwVwo1eCk=; b=Yo6dGS628iVp2pc0ZrKv9cBEEqiKTc7pO23AZfUa9uEoU8pwGFirqWGl81QNh+NXP+7U kmysJQjzjVJAdocpsSwI1soPYl6qKx4FR0PNgy7rs0IP+kIA5Fp48Y2LoXfHR+jCFrNtH U2Qy6Zhdf1+q9vXLYkM1GawXVcu+zeIm6WJTggUSlp8Ciee47IjL71iPHzbbu/Xjh/ybV jW5ojsfbpbgS/5Im8KZGfRlWEwv4AtTunQIrqlodiPyUIJicI4oL2Y7qDfrlxZoNC5ETY E9qKC7DRhFFtDCCDboDyfhnChreNEbBToO41R5v4sJ8rrWu4ktMGg3nLdXUe1VSSk4A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=foxmail.com; spf=pass smtp.mailfrom=foxmail.com; dkim=pass header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=hWOhshgs; arc=none smtp.remote-ip=162.62.57.210 Received: from out162-62-57-210.mail.qq.com (out162-62-57-210.mail.qq.com [162.62.57.210]) (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 62D18606A32C; Thu, 3 Dec 2026 07:55:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 62D18606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=foxmail.com header.i=@foxmail.com header.a=rsa-sha256 header.s=s201512 header.b=hWOhshgs DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1796284496; bh=yjxDPHpP6nXn9zPtyOQy86qpl6gpbWdhnUIwVwo1eCk=; h=From:To:Cc:Subject:Date; b=hWOhshgsZUeGoTtMgZ0TjWFGbV7QMxIxI4xcffkZlbn/FzsZTjgLy9t7Y8oSUEhah 6JMg1piOf4nm6DOQT7dg7CMF9N9M8scmCqq0UjQNPu52yAPqL6gcFHSFauVfnpRj7W RreSMNpV5eHPJU2aAiJArF71AFIQyYmhVV7XTnow= Received: from HAPYCAO-MC1.tencent.com ([61.151.228.149]) by newxmesmtplogicsvrszc56-0.qq.com (NewEsmtp) with SMTP id DB61762F; Thu, 03 Dec 2026 15:54:54 +0800 X-QQ-mid: xmsmtpt1796284494tq0qxngl9 Message-ID: X-QQ-XMAILINFO: MfnHk2ggLakhkqHG9zU/4Sc7hKMNyK9eBhOtBPJYQhY2Sk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ld9HrZ62GV+1cA== X-QQ-XMRINFO: NI4Ajvh11aEjEMj13RCX7UuhPEoou2bs1g== From: bo cao To: linux-nfs@vger.kernel.org, trondmy@kernel.org, anna@kernel.org Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, Bo Cao Subject: [PATCH] pNFS: Fix use-after-free of layout header in pnfs_update_layout() Date: Thu, 3 Dec 2026 15:54:52 +0800 X-OQ-MSGID: <20261203075452.18754-1-treebacker@foxmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) X-Mailing-List: linux-kernel@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 From: Bo Cao pnfs_update_layout() drops its reference on the layout header with pnfs_put_layout_hdr(lo) and then jumps back to the top of the lookup_again loop. When that was the last reference the header is freed through kfree_rcu(), but the local variable 'lo' still points to it. The check at the top of the loop for failed open state recovery (added in 2fdbc20036ac) passes 'lo' to the pnfs_update_layout tracepoint. Its TP_fast_assign reads lo->plh_flags and lo->plh_stateid, so with the event enabled this reads freed memory. The tracepoint is the only user of 'lo' at the top of the loop, so without tracing nothing is dereferenced. KASAN on v7.4-rc5 with the event enabled, LAYOUTGET failing with an error that is retried while open state recovery has failed: [ 282.313103] BUG: KASAN: slab-use-after-free in trace_event_raw_event_pnfs_update_layout+0x5bc/0x5d0 [ 282.313151] Read of size 8 at addr ffff000014d6fe58 by task pnfs_uaf/1905 [ 282.313153] [ 282.313161] CPU: 0 UID: 65534 PID: 1905 Comm: pnfs_uaf Not tainted 7.4.0-rc5 #8 PREEMPT(full) [ 282.313164] Hardware name: linux,dummy-virt (DT) [ 282.313165] Call trace: [ 282.313173] show_stack+0x18/0x24 (C) [ 282.313191] dump_stack_lvl+0x74/0x8c [ 282.313214] print_report+0x118/0x5e0 [ 282.313225] kasan_report+0xc0/0x12c [ 282.313227] __asan_report_load8_noabort+0x20/0x2c [ 282.313230] trace_event_raw_event_pnfs_update_layout+0x5bc/0x5d0 [ 282.313232] __traceiter_pnfs_update_layout+0xa0/0xf8 [ 282.313237] trace_pnfs_update_layout+0x100/0x19c [ 282.313238] pnfs_update_layout+0x490/0x18c4 [ 282.313240] ff_layout_pg_get_read+0x190/0x324 [ 282.313242] ff_layout_pg_init_read+0x370/0x890 [ 282.313243] __nfs_pageio_add_request+0x8e8/0x14d8 Set lo to NULL after each put that is followed by a jump to lookup_again, so the tracepoint takes its existing NULL branch. The pointer is re-acquired by pnfs_find_alloc_layout() later in the loop. The retry path is the one reported by KASAN; the other four sites have the same pattern by inspection. Fixes: 2fdbc20036ac ("NFS: avoid infinite loop in pnfs_update_layout.") Cc: stable@vger.kernel.org Signed-off-by: Bo Cao --- fs/nfs/pnfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 14f4a4b12ffd..80e5cac2906c 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -2235,6 +2235,7 @@ pnfs_update_layout(struct inode *ino, if (IS_ERR(lseg)) goto out_put_layout_hdr; pnfs_put_layout_hdr(lo); + lo = NULL; goto lookup_again; } @@ -2252,6 +2253,7 @@ pnfs_update_layout(struct inode *ino, lseg, PNFS_UPDATE_LAYOUT_RETRY); pnfs_put_layout_hdr(lo); + lo = NULL; goto lookup_again; } trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, @@ -2288,6 +2290,7 @@ pnfs_update_layout(struct inode *ino, goto out_put_layout_hdr; pnfs_put_layout_hdr(lo); dprintk("%s retrying\n", __func__); + lo = NULL; goto lookup_again; } @@ -2305,6 +2308,7 @@ pnfs_update_layout(struct inode *ino, clear_and_wake_up_bit(NFS_LAYOUT_FIRST_LAYOUTGET, &lo->plh_flags); pnfs_put_layout_hdr(lo); + lo = NULL; goto lookup_again; } spin_lock(&ino->i_lock); @@ -2397,6 +2401,7 @@ pnfs_update_layout(struct inode *ino, trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, PNFS_UPDATE_LAYOUT_RETRY); pnfs_put_layout_hdr(lo); + lo = NULL; goto lookup_again; } } else { -- 2.39.5 (Apple Git-154)