Skip to contentSkip to conversation

ntfs3: fix out-of-bounds read in decompress_lznt

PATCH In review Tristan Madani 2 participants 2 messages Apr 18 – Apr 30 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ntfs3: fix out-of-bounds read in decompress_lznt

From: Tristan Madani <[email protected]>

decompress_lznt() does not validate array index bounds before accessing the decompression table. A corrupted NTFS3 image with invalid compressed data can trigger an out-of-bounds read.

Add index bounds checking to prevent the OOB access.

---
 fs/ntfs3/lznt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/lznt.c +1 -1
index fdc9b2ebf3410..f818d97850049 100644
@@ -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. */
Signature · 1 line
2.47.3
#1 lore raw
Quoted 31 lines · Tristan Madani

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

From: Tristan Madani <[email protected]>

decompress_lznt() does not validate array index bounds before accessing the decompression table. A corrupted NTFS3 image with invalid compressed data can trigger an out-of-bounds read.

Add index bounds checking to prevent the OOB access.

---
  fs/ntfs3/lznt.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/lznt.c +1 -2
index fdc9b2ebf3410..f818d97850049 100644
@@ -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. */
--
Quoted 2 lines

2.47.3

Hello,

Sorry for the delay.
Your patch is applied, thank you.

Regards,
Konstantin