* [PATCH] ntfs3: check if more than chunk-size bytes are written
2024-05-14 16:19 [syzbot] [ntfs3?] UBSAN: array-index-out-of-bounds in decompress_lznt syzbot
@ 2024-05-15 12:38 ` Andrew Ballance
2024-05-15 12:59 ` [syzbot] [ntfs3?] UBSAN: array-index-out-of-bounds in decompress_lznt syzbot
2024-07-01 21:55 ` [syzbot] test syzbot
` (3 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Andrew Ballance @ 2024-05-15 12:38 UTC (permalink / raw)
To: syzbot+39b2fb0f2638669008ec
Cc: almaz.alexandrovich, linux-kernel, ntfs3, syzkaller-bugs, skhan,
linux-kernel-mentees, Andrew Ballance
#syz test
a incorrectly formatted chunk may decompress into
more than LZNT_CHUNK_SIZE bytes and a index out of bounds
will occur in s_max_off.
Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
---
fs/ntfs3/lznt.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/ntfs3/lznt.c b/fs/ntfs3/lznt.c
index 4aae598d6d88..fdc9b2ebf341 100644
--- a/fs/ntfs3/lznt.c
+++ b/fs/ntfs3/lznt.c
@@ -236,6 +236,9 @@ static inline ssize_t decompress_chunk(u8 *unc, u8 *unc_end, const u8 *cmpr,
/* Do decompression until pointers are inside range. */
while (up < unc_end && cmpr < cmpr_end) {
+ // return err if more than LZNT_CHUNK_SIZE bytes are written
+ if (up - unc > LZNT_CHUNK_SIZE)
+ return -EINVAL;
/* Correct index */
while (unc + s_max_off[index] < up)
index += 1;
--
2.45.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [syzbot] test
2024-05-14 16:19 [syzbot] [ntfs3?] UBSAN: array-index-out-of-bounds in decompress_lznt syzbot
2024-05-15 12:38 ` [PATCH] ntfs3: check if more than chunk-size bytes are written Andrew Ballance
@ 2024-07-01 21:55 ` syzbot
2024-08-23 16:04 ` [syzbot] UBSAN: array-index-out-of-bounds in decompress_lznt syzbot
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2024-07-01 21:55 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: test
Author: mukattreyee@gmail.com
#syz test:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [syzbot] UBSAN: array-index-out-of-bounds in decompress_lznt
2024-05-14 16:19 [syzbot] [ntfs3?] UBSAN: array-index-out-of-bounds in decompress_lznt syzbot
2024-05-15 12:38 ` [PATCH] ntfs3: check if more than chunk-size bytes are written Andrew Ballance
2024-07-01 21:55 ` [syzbot] test syzbot
@ 2024-08-23 16:04 ` syzbot
2026-04-17 10:12 ` Forwarded: [PATCH] ntfs3: fix " syzbot
2026-04-17 16:20 ` Forwarded: Re: [syzbot] KASAN: slab-out-of-bounds " syzbot
4 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2024-08-23 16:04 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: UBSAN: array-index-out-of-bounds in decompress_lznt
Author: almaz.alexandrovich@paragon-software.com
#syz test: https://github.com/Paragon-Software-Group/linux-ntfs3.git master
^ permalink raw reply [flat|nested] 7+ messages in thread
* Forwarded: [PATCH] ntfs3: fix array-index-out-of-bounds in decompress_lznt
2024-05-14 16:19 [syzbot] [ntfs3?] UBSAN: array-index-out-of-bounds in decompress_lznt syzbot
` (2 preceding siblings ...)
2024-08-23 16:04 ` [syzbot] UBSAN: array-index-out-of-bounds in decompress_lznt syzbot
@ 2026-04-17 10:12 ` syzbot
2026-04-17 16:20 ` Forwarded: Re: [syzbot] KASAN: slab-out-of-bounds " syzbot
4 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2026-04-17 10:12 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] ntfs3: fix array-index-out-of-bounds in decompress_lznt
Author: tristmd@gmail.com
From: Tristan Madani <tristan@talencesecurity.com>
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
The index correction loop in decompress_chunk() increments the index
variable without checking against the s_max_off[] array size:
while (unc + s_max_off[index] < up)
index += 1;
When a crafted NTFS image causes the decompressed output pointer (up) to
advance beyond unc + s_max_off[8] (0x1000), the loop reads s_max_off[9]
which is past the end of the 9-element array, triggering UBSAN:
UBSAN: array-index-out-of-bounds in fs/ntfs3/lznt.c:243:16
index 9 is out of range for type 'const size_t[9]'
Commit 9931122d04c6 ("fs/ntfs3: Check if more than chunk-size bytes are
written") partially addressed this by adding a check for up - unc >
LZNT_CHUNK_SIZE before the loop. However, this relies on the implicit
invariant that LZNT_CHUNK_SIZE equals s_max_off[ARRAY_SIZE(s_max_off)-1],
and the check uses strict greater-than which still allows index to reach
the boundary value in edge cases with concurrent modifications to the
unc_end bound.
Add a direct bounds check on index within the while loop condition to
make the code robust regardless of the relationship between
LZNT_CHUNK_SIZE and s_max_off[] values. If index reaches the maximum,
break out of the correction loop -- the entry at s_max_off[8] (0x1000)
already covers the full chunk range.
Found by syzbot.
Reported-by: syzbot+39b2fb0f2638669008ec@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=39b2fb0f2638669008ec
Fixes: 522e010b5837 ("fs/ntfs3: Add compression")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
fs/ntfs3/lznt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ntfs3/lznt.c b/fs/ntfs3/lznt.c
index XXXXXXX..XXXXXXX 100644
--- a/fs/ntfs3/lznt.c
+++ b/fs/ntfs3/lznt.c
@@ -240,7 +240,7 @@ static inline ssize_t decompress_chunk(u8 *unc, u8 *unc_end, const u8 *cmpr,
if (up - unc > LZNT_CHUNK_SIZE)
return -EINVAL;
/* Correct index */
- while (unc + s_max_off[index] < up)
+ while (index < ARRAY_SIZE(s_max_off) - 1 && unc + s_max_off[index] < up)
index += 1;
/* Check the current flag for zero. */
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread* Forwarded: Re: [syzbot] KASAN: slab-out-of-bounds in decompress_lznt
2024-05-14 16:19 [syzbot] [ntfs3?] UBSAN: array-index-out-of-bounds in decompress_lznt syzbot
` (3 preceding siblings ...)
2026-04-17 10:12 ` Forwarded: [PATCH] ntfs3: fix " syzbot
@ 2026-04-17 16:20 ` syzbot
4 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2026-04-17 16:20 UTC (permalink / raw)
To: linux-kernel, syzkaller-bugs
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: Re: [syzbot] KASAN: slab-out-of-bounds in decompress_lznt
Author: tristmd@gmail.com
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
>From 6cfb2c5508cbe3c057fc4fe83808ef6cf8fc9868 Mon Sep 17 00:00:00 2001
From: Tristan Madani <tristan@talencesecurity.com>
Date: Fri, 17 Apr 2026 16:15:16 +0000
Subject: [PATCH] ntfs3: fix array-index-out-of-bounds in decompress_lznt
decompress_chunk() increments index without checking array bounds,
leading to an out-of-bounds access on s_max_off when processing
corrupted compressed data.
Add an upper bound check on index to prevent the overflow.
Reported-by: syzbot+39b2fb0f2638669008ec@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=39b2fb0f2638669008ec
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
fs/ntfs3/lznt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ntfs3/lznt.c b/fs/ntfs3/lznt.c
index fdc9b2e..f818d97 100644
--- a/fs/ntfs3/lznt.c
+++ b/fs/ntfs3/lznt.c
@@ -240,7 +240,7 @@ static inline ssize_t decompress_chunk(u8 *unc, u8 *unc_end, const u8 *cmpr,
if (up - unc > LZNT_CHUNK_SIZE)
return -EINVAL;
/* Correct index */
- while (unc + s_max_off[index] < up)
+ while (index < ARRAY_SIZE(s_max_off) - 1 && unc + s_max_off[index] < up)
index += 1;
/* Check the current flag for zero. */
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread