Skip to content

Commit b62567b

Browse files
tobgaertneraalexandrovich
authored andcommitted
ntfs3: add buffer boundary checks to run_unpack()
run_unpack() checks `run_buf < run_last` at the top of the while loop but then reads size_size and offset_size bytes via run_unpack_s64() without verifying they fit within the remaining buffer. A crafted NTFS image with truncated run data in an MFT attribute triggers an OOB heap read of up to 15 bytes when the filesystem is mounted. Add boundary checks before each run_unpack_s64() call to ensure the declared field size does not exceed the remaining buffer. Found by fuzzing with a source-patched harness (LibAFL + QEMU). Fixes: 82cae26 ("fs/ntfs3: Add initialization of super block") Cc: stable@vger.kernel.org Signed-off-by: Tobias Gaertner <tob.gaertner@me.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 6d979b6 commit b62567b

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

fs/ntfs3/run.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,9 @@ int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,
10081008
if (size_size > sizeof(len))
10091009
return -EINVAL;
10101010

1011+
if (run_buf + size_size > run_last)
1012+
return -EINVAL;
1013+
10111014
len = run_unpack_s64(run_buf, size_size, 0);
10121015
/* Skip size_size. */
10131016
run_buf += size_size;
@@ -1020,6 +1023,9 @@ int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,
10201023
else if (offset_size <= sizeof(s64)) {
10211024
s64 dlcn;
10221025

1026+
if (run_buf + offset_size > run_last)
1027+
return -EINVAL;
1028+
10231029
/* Initial value of dlcn is -1 or 0. */
10241030
dlcn = (run_buf[offset_size - 1] & 0x80) ? (s64)-1 : 0;
10251031
dlcn = run_unpack_s64(run_buf, offset_size, dlcn);

0 commit comments

Comments
 (0)