Skip to content

Commit bf7ac4a

Browse files
tobgaertnergregkh
authored andcommitted
ntfs3: add buffer boundary checks to run_unpack()
commit b62567b upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 98f4ba3 commit bf7ac4a

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
@@ -963,6 +963,9 @@ int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,
963963
if (size_size > 8)
964964
return -EINVAL;
965965

966+
if (run_buf + size_size > run_last)
967+
return -EINVAL;
968+
966969
len = run_unpack_s64(run_buf, size_size, 0);
967970
/* Skip size_size. */
968971
run_buf += size_size;
@@ -975,6 +978,9 @@ int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,
975978
else if (offset_size <= 8) {
976979
s64 dlcn;
977980

981+
if (run_buf + offset_size > run_last)
982+
return -EINVAL;
983+
978984
/* Initial value of dlcn is -1 or 0. */
979985
dlcn = (run_buf[offset_size - 1] & 0x80) ? (s64)-1 : 0;
980986
dlcn = run_unpack_s64(run_buf, offset_size, dlcn);

0 commit comments

Comments
 (0)