public inbox for ntfs3@lists.linux.dev
 help / color / mirror / Atom feed
* [syzbot] [ntfs3?] WARNING in ni_rename
@ 2025-07-08  8:39 Moon Hee Lee
  2025-07-08  9:06 ` syzbot
  0 siblings, 1 reply; 9+ messages in thread
From: Moon Hee Lee @ 2025-07-08  8:39 UTC (permalink / raw)
  To: syzbot+b0373017f711c06ada64
  Cc: almaz.alexandrovich, linux-kernel, ntfs3, syzkaller-bugs

[-- Attachment #1: Type: text/plain, Size: 10 bytes --]

#syz test

[-- Attachment #2: 0001-ntfs3-reject-zero-length-BITMAP-when-index-blocks-ar.patch --]
[-- Type: text/x-patch, Size: 1655 bytes --]

From a7e94ad4959e46acf3861fa0c725a2d0c3373ebb Mon Sep 17 00:00:00 2001
From: Moon Hee Lee <moonhee.lee.ca@gmail.com>
Date: Tue, 8 Jul 2025 01:17:13 -0700
Subject: [PATCH] ntfs3: reject zero-length $BITMAP when index blocks are
 allocated

A non-empty index allocation requires at least one bit in $BITMAP
to track usage. Reject malformed on-disk structures with zero-length
bitmaps and allocated index blocks.

Signed-off-by: Moon Hee Lee <moonhee.lee.ca@gmail.com>
---
 fs/ntfs3/index.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index 1bf2a6593dec..15f3a711ea0a 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -478,6 +478,7 @@ static int indx_find_free(struct ntfs_index *indx, struct ntfs_inode *ni,
 	struct ATTR_LIST_ENTRY *le = NULL;
 	const struct INDEX_NAMES *in = &s_index_names[indx->type];
 	int err;
+	u64 bm_size;
 
 	b = ni_find_attr(ni, NULL, &le, ATTR_BITMAP, in->name, in->name_len,
 			 NULL, NULL);
@@ -488,6 +489,17 @@ static int indx_find_free(struct ntfs_index *indx, struct ntfs_inode *ni,
 	*bitmap = b;
 	*bit = MINUS_ONE_T;
 
+	bm_size = b->non_res ? le64_to_cpu(b->nres.valid_size) :
+			       le32_to_cpu(b->res.data_size);
+
+	/*
+	 * Allocated index blocks require $BITMAP to contain at least
+	 * one bit for usage tracking. A zero-length bitmap in this
+	 * case indicates a malformed on-disk structure and cannot be used.
+	 */
+	if (unlikely(bm_size == 0 && indx->alloc_run.count))
+		return -EINVAL;
+
 	if (!b->non_res) {
 		u32 nbits = 8 * le32_to_cpu(b->res.data_size);
 		size_t pos = find_next_zero_bit_le(resident_data(b), nbits, 0);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [syzbot] [ntfs3?] WARNING in ni_rename
@ 2025-07-08 21:45 Moon Hee Lee
  2025-07-08 22:11 ` syzbot
  0 siblings, 1 reply; 9+ messages in thread
From: Moon Hee Lee @ 2025-07-08 21:45 UTC (permalink / raw)
  To: syzbot; +Cc: almaz.alexandrovich, linux-kernel, ntfs3, syzkaller-bugs

[-- Attachment #1: Type: text/plain, Size: 10 bytes --]

#syz test

[-- Attachment #2: 0001-ntfs3-validate-BITMAP-size-when-index-blocks-are-pre.patch --]
[-- Type: text/x-patch, Size: 1098 bytes --]

From 7fa1f4b399c2d47d1ab301c2662f6a60c2098c45 Mon Sep 17 00:00:00 2001
From: Moon Hee Lee <moonhee.lee.ca@gmail.com>
Date: Tue, 8 Jul 2025 14:39:43 -0700
Subject: [PATCH] ntfs3: validate $BITMAP size when index blocks are present

Reject directories with allocated index blocks but zero-length $BITMAP,
as this indicates an inconsistent on-disk structure.

Signed-off-by: Moon Hee Lee <moonhee.lee.ca@gmail.com>
---
 fs/ntfs3/index.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index 1bf2a6593dec..6d1bf890929d 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -1508,6 +1508,16 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
 			bmp_size = bmp_size_v = le32_to_cpu(bmp->res.data_size);
 		}
 
+		/*
+		 * Index blocks exist, but $BITMAP has zero valid bits.
+		 * This implies an on-disk corruption and must be rejected.
+		 */
+		if (in->name == I30_NAME &&
+		    unlikely(bmp_size_v == 0 && indx->alloc_run.count)) {
+			err = -EINVAL;
+			goto out1;
+		}
+
 		bit = bmp_size << 3;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [syzbot] [ntfs3?] WARNING in ni_rename
@ 2025-07-08  7:54 Moonhee Lee
  2025-07-08  8:13 ` syzbot
  0 siblings, 1 reply; 9+ messages in thread
From: Moonhee Lee @ 2025-07-08  7:54 UTC (permalink / raw)
  To: syzbot+b0373017f711c06ada64
  Cc: almaz.alexandrovich, linux-kernel, ntfs3, syzkaller-bugs

#syz test

diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index 1bf2a6593dec..15f3a711ea0a 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -478,6 +478,7 @@ static int indx_find_free(struct ntfs_index *indx,
struct ntfs_inode *ni,
        struct ATTR_LIST_ENTRY *le = NULL;
        const struct INDEX_NAMES *in = &s_index_names[indx->type];
        int err;
+       u64 bm_size;

        b = ni_find_attr(ni, NULL, &le, ATTR_BITMAP, in->name, in->name_len,
                         NULL, NULL);
@@ -488,6 +489,17 @@ static int indx_find_free(struct ntfs_index
*indx, struct ntfs_inode *ni,
        *bitmap = b;
        *bit = MINUS_ONE_T;

+       bm_size = b->non_res ? le64_to_cpu(b->nres.valid_size) :
+                              le32_to_cpu(b->res.data_size);
+
+       /*
+        * Allocated index blocks require $BITMAP to contain at least
+        * one bit for usage tracking. A zero-length bitmap in this
+        * case indicates a malformed on-disk structure and cannot be used.
+        */
+       if (unlikely(bm_size == 0 && indx->alloc_run.count))
+               return -EINVAL;
+
        if (!b->non_res) {
                u32 nbits = 8 * le32_to_cpu(b->res.data_size);
                size_t pos = find_next_zero_bit_le(resident_data(b), nbits, 0);

^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [syzbot] [ntfs3?] WARNING in ni_rename
@ 2025-06-29  9:46 syzbot
  0 siblings, 0 replies; 9+ messages in thread
From: syzbot @ 2025-06-29  9:46 UTC (permalink / raw)
  To: almaz.alexandrovich, linux-kernel, ntfs3, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    1b152eeca84a Add linux-next specific files for 20250625
git tree:       linux-next
console+strace: https://syzkaller.appspot.com/x/log.txt?x=1409df0c580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=a3d8d413c6928dae
dashboard link: https://syzkaller.appspot.com/bug?extid=b0373017f711c06ada64
compiler:       Debian clang version 20.1.6 (++20250514063057+1e4d39e07757-1~exp1~20250514183223.118), Debian LLD 20.1.6
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=1683770c580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1183770c580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/4fe40968b29a/disk-1b152eec.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/edf810403580/vmlinux-1b152eec.xz
kernel image: https://storage.googleapis.com/syzbot-assets/0b63be52ad9a/bzImage-1b152eec.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/3256aebc06d8/mount_0.gz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+b0373017f711c06ada64@syzkaller.appspotmail.com

------------[ cut here ]------------
WARNING: fs/ntfs3/frecord.c:3030 at ni_rename+0xee/0x100 fs/ntfs3/frecord.c:3029, CPU#0: syz-executor359/5838
Modules linked in:
CPU: 0 UID: 0 PID: 5838 Comm: syz-executor359 Not tainted 6.16.0-rc3-next-20250625-syzkaller #0 PREEMPT(full) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/07/2025
RIP: 0010:ni_rename+0xee/0x100 fs/ntfs3/frecord.c:3029
Code: 8b 05 36 32 9a 0f 48 3b 44 24 10 75 22 44 89 e0 48 83 c4 18 5b 41 5c 41 5d 41 5e 41 5f 5d e9 19 b4 6b 08 cc e8 73 fe b9 fe 90 <0f> 0b 90 eb c5 e8 e8 d9 68 08 0f 1f 84 00 00 00 00 00 90 90 90 90
RSP: 0018:ffffc9000420fab8 EFLAGS: 00010293
RAX: ffffffff8305be0d RBX: 00000000fffffffe RCX: ffff888029afbc00
RDX: 0000000000000000 RSI: 00000000fffffffe RDI: 0000000000000000
RBP: 00000000fffffffe R08: ffffffff8fa18d37 R09: 1ffffffff1f431a6
R10: dffffc0000000000 R11: fffffbfff1f431a7 R12: 0000000000000000
R13: ffff88807c10a200 R14: ffff8880776e8758 R15: ffff888073d566d0
FS:  0000555581b87380(0000) GS:ffff888125c21000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055e3bd1067a8 CR3: 0000000072ba4000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 ntfs_rename+0x6e2/0xb40 fs/ntfs3/namei.c:316
 vfs_rename+0xbda/0xf00 fs/namei.c:5129
 do_renameat2+0x6ce/0xa80 fs/namei.c:5278
 __do_sys_rename fs/namei.c:5325 [inline]
 __se_sys_rename fs/namei.c:5323 [inline]
 __x64_sys_rename+0x82/0x90 fs/namei.c:5323
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fe16d5c28b9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 61 17 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffcc6842518 EFLAGS: 00000246 ORIG_RAX: 0000000000000052
RAX: ffffffffffffffda RBX: 0000200000000000 RCX: 00007fe16d5c28b9
RDX: 0000000000000000 RSI: 0000200000001040 RDI: 0000200000000280
RBP: 0030656c69662f2e R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007ffcc68426f8 R14: 0000000000000001 R15: 0000000000000001
 </TASK>


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-07-08 22:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-08  8:39 [syzbot] [ntfs3?] WARNING in ni_rename Moon Hee Lee
2025-07-08  9:06 ` syzbot
  -- strict thread matches above, loose matches on Subject: below --
2025-07-08 21:45 Moon Hee Lee
2025-07-08 22:11 ` syzbot
2025-07-08  7:54 Moonhee Lee
2025-07-08  8:13 ` syzbot
2025-07-08  8:21   ` Moon Hee Lee
2025-07-08  8:38     ` syzbot
2025-06-29  9:46 syzbot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox