From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 1D45F223710 for ; Sun, 7 Dec 2025 06:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765090311; cv=none; b=VLzCtiF+Q259zJDqsS8AQaQsmlyy+p5PyQrpyKUjdavf4udhfohixeHvIS04BCeKh5HPXpAYN3Ik7bsQBVRx+xE4+T+CNfv3YPZuMjCjZn/s+/tqgKTSAqO8wVsbwA0KXx4QLoMPqiklwkaFLLA4hz1BMGXGAqEhblyFsfKEsgU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765090311; c=relaxed/simple; bh=9DVC7BpkFFu6Ilr3hm+gkQ3zWfG0Wc4s1p3HRKHDu8A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=tkHRSp8HJ8Q0GEVz9/yLj/zujARdjx9S+oxAlS03v4IkDxZnw0OxvpiDl0kV48WiEFbDpxmSad1dk4nLLwMnICI5HrZ1B9ODrm/PGpl/MAjfCsGMXvsYvhep4yH8c9plTb85LN/184ScVo1n/H39ity61lkV2lsbAyQT33J2DA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DwTlSSEg; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DwTlSSEg" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7bb710d1d1dso5604833b3a.1 for ; Sat, 06 Dec 2025 22:51:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765090309; x=1765695109; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QWAO72Z2iAFbIFWQdy5xnnkqY/ScKvkKahaKLosP+Es=; b=DwTlSSEgGdDNzHrEv1K9Ow23mHYA7NBpbl8PYT/3la0nbl0BemU3CfxJQbciWQXE7p oFuGJPtHVtcAtOWAS+cspVWpTnEUKIsR+55/tL36oC1L1wVZit33/DJiOOTqNhZtTHGh I8lyBMCq56O+Sx12AQogAgYuEl0LFUVVX97r2HwSo/n+tul6BzWgpKDtSvI+PssCZO7G oti8IJZWW+xWXrN+0FAYgVEZaBMXx4usWs5xg1U2R2peKyBaQFl8Bz/JrL3bHh9aY/TS MCmZwwPCMwQwrzjFKlw5mgw4PNPvTzSAno4ARzQ2ExlajrjTBiQtQIf571GFbRR2hwbM v4og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765090309; x=1765695109; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QWAO72Z2iAFbIFWQdy5xnnkqY/ScKvkKahaKLosP+Es=; b=G8FZOhDyGti4dW6C18ulKgR9aD+qLWHr9//DlynjW5taO+BTEOV2iSErMyjiWTF6YB JKq7hzqabTEkQTKMeWinIsOhgt2n7f4jiZ5r4da3UxOxNbNq9E/7LCZ6Wjjf37bcv6iC kAKaRZo0z58Y3GR8EE1iD9XKeuEogVRp+OiHkHxzYedvQIZ799ubec52FK8exLN6UdEh MSUNMMaDMQxrtWJ0aOcn6y5EcXeq1hSQAzmwoRTZ15XSCzHJjHAUjqECnnHhKWa7WH5A cIwC/MtRKf/bXYqTK5k1XWoBAGkN8simlGzGrJrWQT0b0OFSm/9hfbrFeKnLPYnYdAH/ zwnQ== X-Forwarded-Encrypted: i=1; AJvYcCVc5sVqwg7wuH5EhSsh6UWWFPNKb4Bx4PMm5p7nYBo+Frr3DDWKcdQxxPOYet6d3KFjzZcpx9RlfOQ65CU=@vger.kernel.org X-Gm-Message-State: AOJu0YwoY82KI26N3aCheTOg/SREnYLloJJInfjoeH3kE7qilNQnoBFy jLyOXFejPqAUxOHW84Cv5spA6iWJDSDSKgzc5PjQzktJ+HMAzBBJ2A4s X-Gm-Gg: ASbGncu9+Z9vCPLbZQeLK3f+lPf6GKxkheGM0D0vlNCD/CDQ/Bix0G54yElNyx+168H 7BIbZAAublfRuxONf6tQsxC1cWg1niXmq+MUla4/oKVCiWs+3jIR1E1FdH6Pq8gTD3S2mEUzYBl 8LhzQAstGjMe4tvWt8Xd6/fCPSmzCn1wHX3oTPQMjyeo+FH2bIW07UnUbYxmp7ZVbo4M1+R5w7f X0ev0z2s4fqVr6Q9l1gK/x4tsemW+kkNjZyMv3oiQ+J/3mlC3AB9BoSCuD30NEj9Qn2gcye3sCR +FIxm5e5dMIBKWvEVEnRRBgFfI5UQikMYvEgh9TGKOsiQXc1lYfmiVTUYch0/0HizBtb0uZ0gi9 6D6dszXywrSTItytlIPgsU7hx9rUh0b2tjG0++w2x330kt3c90THn6d2H/cZ+0YARJdgEJHfiVq MZ6BT0SLdWU0oQc7TgsNCfjFx2qE6Wozle4cNXDHkwnN0os7OeUHJxj3DwPds6ZHVZtyc= X-Google-Smtp-Source: AGHT+IGKLBAVrlWnCfTNdMzCf6W3jb7E215aZktJGw5E3/h0pYj0lS87phfTv/fiJqTr5iKnNPQygw== X-Received: by 2002:a05:6a00:2347:b0:7a2:7c25:1f38 with SMTP id d2e1a72fcca58-7e8c2b94698mr3651966b3a.13.1765090309387; Sat, 06 Dec 2025 22:51:49 -0800 (PST) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:6893:b3d4:beeb:8a65]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7e2af9393e9sm9733386b3a.63.2025.12.06.22.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Dec 2025 22:51:48 -0800 (PST) From: Deepanshu Kartikey To: shaggy@kernel.org, brauner@kernel.org Cc: mjguzik@gmail.com, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+a099d674daa27a9272db@syzkaller.appspotmail.com Subject: [PATCH] jfs: fix directory tree corruption in dtSplitRoot() Date: Sun, 7 Dec 2025 12:21:30 +0530 Message-ID: <20251207065134.2610956-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=y Content-Transfer-Encoding: 8bit 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 == 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=3 from a previous operation instead of the expected index=0. Example sequence: Transaction tid=1: - First dtSplitRoot: gets fresh lock, index=0 ✓ - Modifies entries, index becomes 3 - Lock returned to pool but not freed Transaction tid=1 (continues): - Second dtSplitRoot: reuses same lock - index still = 3 (stale value) ✗ - ASSERT(index == 0) fails → 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=0) - 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=0. Reported-by: syzbot+a099d674daa27a9272db@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=a099d674daa27a9272db Signed-off-by: Deepanshu Kartikey --- fs/jfs/jfs_txnmgr.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c index c16578af3a77..5ce2fc17d967 100644 --- a/fs/jfs/jfs_txnmgr.c +++ b/fs/jfs/jfs_txnmgr.c @@ -811,6 +811,17 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp, * update tlock vector */ grantLock: + /* + * Reset index for new DTREE locks to ensure clean state. + * When locks are reused, index may contain stale values from + * previous operations. Operations like dtSplitRoot() expect + * index to be 0 when creating new pages (tlckNEW flag). + */ + if ((type & tlckDTREE) && (type & tlckNEW)) { + struct dt_lock *dtlck = (struct dt_lock *)&tlck->lock; + + dtlck->index = 0; + } tlck->type |= type; return tlck; -- 2.43.0