From nobody Fri Dec 19 11:49:59 2025 Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BED1195FE8 for ; Sun, 7 Dec 2025 06:05:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765087541; cv=none; b=LMU8ejCsQgc8pVSEuQGb0S06PAGPxz8uN2FFid+YI26yciX9FufpJRItNtz8S1qOGW7rcIiWbX/1XZNYIdkup8BKU3K4dtinvMR92LRUq08RQhwVkK2Ox4pymbFIMTVGeJBhwczKk2ZAur8u0RIiKnH0sNrFzuIHtRlG/Xb4wLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765087541; c=relaxed/simple; bh=q+kH1zyf65U0fEV5MvrR6snBKYINW9K4j/zXRgPpZTY=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=oNOXS/Ck3al8luoVAAJJZFpLtQy4cQtBHuQybhTj0fUS7Z9cbhJoRHPOo5tnt6q2aUmEfsWQIRTyeeAaz8A4nTFMTJE34fFfukL4axf3MQXQVHyqZXOGPC2IyMLvLEwG12rBRMnCLpOhUIMTH5x9edJIt+Hn/FE3Kky9b0zCWkg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.161.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-6577768ec28so6775338eaf.1 for ; Sat, 06 Dec 2025 22:05:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765087539; x=1765692339; h=content-transfer-encoding:to:from:subject:message-id:in-reply-to :date:mime-version:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/uYUtBTtQVEykozkqCWzmhyFoJH3tafTBeWFy9j/yNU=; b=b/DgwtN1V6+6oqRoDHIsXH2F1nXARztFQyJ2QgK8ly0UXONwot1ssOryp4piTwM1GO bc1J8F51K4jQMXD3b0QpKquhGcGq7TFOeWcAWXAzFk0q/+hTmTw2iOFgKgiT70jr4fWJ h3bIw7NZ6HF++LFDBoVfWoFFPZSM95RfE5JGQ8HwjcLICSppdK34u2+JQT3R2Nr1fJFC NfIS1UQoVRy5lQnf6fOQPpRM9XXJu3cTzLPCd8KSUbDCjhhmEF65ozzVpRRKRdeqUgx5 VSDQf23A2BOn6UsYe8vJij3lRi3cQQ/P2IHEjr8Z9z3duvNl6OqS3D4Jpn+TD+6EE3EZ tTpQ== X-Gm-Message-State: AOJu0YyrJ7DUjS2mT3WLGYIKG0SAEAjtGk/4oshpa3P9yVkjjRizGMHq vsH0Uym4au5NOQDUULbgzsWdWziSbbWoJZ+PNjxlrM47BoKRD+E2Ia1BAJ/EFGnx+NS4BLwAKxA 8xGreKY5kLGwjsAr7ZHomtnvI5POnZK5+lhc4Wc8n/bvYvdEeFMQrdLev5bs= X-Google-Smtp-Source: AGHT+IFwkF1tdU8p4017TG4iejSlZR7+/w5iWQMcRc9B76zeXX4daWV+5ax4mr5cs3Fr7ccMW0QRFZlEJQA1YAH+TTg4FiOFfIVQ Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:c010:b0:659:9a49:8e24 with SMTP id 006d021491bc7-6599a499c9fmr1513956eaf.22.1765087539215; Sat, 06 Dec 2025 22:05:39 -0800 (PST) Date: Sat, 06 Dec 2025 22:05:39 -0800 In-Reply-To: <6933eb82.a70a0220.38f243.001a.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69351933.a70a0220.38f243.0047.GAE@google.com> Subject: Forwarded: [PATCH] jfs: fix directory tree corruption in dtSplitRoot() From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] jfs: fix directory tree corruption in dtSplitRoot() Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git= master When reusing transaction locks for DTREE operations, the index field may contain stale values from previous operations, causing assertion failures in dtSplitRoot(): ASSERT(dtlck->index =3D=3D 0) This results in kernel crashes like: kernel BUG at fs/jfs/jfs_dtree.c:1942! Call Trace: dtSplitRoot+0x1694/0x16c0 fs/jfs/jfs_dtree.c:1942 dtSplitUp fs/jfs/jfs_dtree.c:1244 [inline] dtInsert+0x2525/0x5f40 fs/jfs/jfs_dtree.c:871 jfs_create+0x6c8/0xa80 fs/jfs/namei.c:137 The bug occurs because txLock() has multiple code paths for lock acquisition: 1. Fresh allocation (allocateLock) - correctly initializes index to 0 2. Lock reuse (same transaction) - skips initialization 3. Anonymous lock acquisition - skips initialization Paths 2 and 3 jump directly to the grantLock label, bypassing the index initialization. When dtSplitRoot() is called multiple times within a batched transaction (which JFS uses for performance), it may receive a reused lock with index=3D3 from a previous operation instead of the expected index=3D0. Example sequence: Transaction tid=3D1: - First dtSplitRoot: gets fresh lock, index=3D0 =E2=9C=93 - Modifies entries, index becomes 3 - Lock returned to pool but not freed Transaction tid=3D1 (continues): - Second dtSplitRoot: reuses same lock - index still =3D 3 (stale value) =E2=9C=97 - ASSERT(index =3D=3D 0) fails =E2=86=92 crash Fix by resetting dtlck->index to 0 at the grantLock label, but only for operations with the tlckNEW flag set. This ensures: - New pages (like dtSplitRoot) start with clean state (index=3D0) - Existing pages preserve accumulated changes within a transaction - No performance impact (only affects new page operations) The tlckNEW flag is used by dtSplitRoot() when creating a new root page, making this fix targeted to the exact scenario that requires index=3D0. Reported-by: syzbot+a099d674daa27a9272db@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Da099d674daa27a9272db Signed-off-by: Deepanshu Kartikey --- fs/jfs/jfs_dtree.c | 8 +++++++- fs/jfs/jfs_txnmgr.c | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c index 0ab83bb7bbdf..6e5b4431f287 100644 --- a/fs/jfs/jfs_dtree.c +++ b/fs/jfs/jfs_dtree.c @@ -1926,7 +1926,13 @@ static int dtSplitRoot(tid_t tid, */ tlck =3D txLock(tid, ip, rmp, tlckDTREE | tlckNEW); dtlck =3D (struct dt_lock *) & tlck->lock; - + printk(KERN_ERR "JFS_DEBUG: dtSplitRoot before assertion\n"); + printk(KERN_ERR " tid=3D%d, ip=3D%p, rmp=3D%p\n", tid, ip, rmp); + printk(KERN_ERR " tlck=3D%p, tlck->tid=3D%d, tlck->type=3D0x%x\n", tlck,= tlck->tid, tlck->type); + printk(KERN_ERR " dtlck=3D%p, dtlck->index=3D%d\n", dtlck, dtlck->index); + if (dtlck->index !=3D 0) { + printk(KERN_ERR " ERROR: index is %d, expected 0!\n", dtlck->index); + } rp->header.flag =3D (sp->header.flag & BT_LEAF) ? BT_LEAF : BT_INTERNAL; rp->header.self =3D *pxd; diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c index c16578af3a77..bb2fb9bc3440 100644 --- a/fs/jfs/jfs_txnmgr.c +++ b/fs/jfs/jfs_txnmgr.c @@ -811,6 +811,23 @@ struct tlock *txLock(tid_t tid, struct inode *ip, stru= ct metapage * mp, * update tlock vector */ grantLock: + if ((type & tlckDTREE) && (type & tlckNEW)) { + struct dt_lock *dtlck =3D (struct dt_lock *)&tlck->lock; + struct linelock *linelock =3D (struct linelock *)&tlck->lock; + printk(KERN_ERR "JFS_DEBUG: txLock grantLock (DTREE)\n"); + printk(KERN_ERR " tid=3D%d, ip=3D%p, mp=3D%p\n", tid, ip, mp); + printk(KERN_ERR " type=3D0x%x (DTREE=3D%d, NEW=3D%d)\n", type, !!(type = & tlckDTREE), !!(type & tlckNEW)); + printk(KERN_ERR " tlck=3D%p, tlck->tid=3D%d\n", tlck, tlck->tid); + printk(KERN_ERR " BEFORE: linelock->index=3D%d\n", linelock->index); + printk(KERN_ERR " BEFORE: linelock->next=3D%d, flag=3D%d\n",linelock->n= ext, linelock->flag); + if (type & tlckNEW) { + printk(KERN_ERR " ACTION: Resetting index to 0 (tlckNEW)\n"); + dtlck->index =3D 0; + } else { + printk(KERN_ERR " ACTION: NOT resetting (no tlckNEW)\n"); + } + printk(KERN_ERR " AFTER: linelock->index=3D%d\n", linelock->index); + } tlck->type |=3D type; =20 return tlck; --=20 2.43.0