]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ntfs3: add buffer boundary checks to run_unpack()
authorTobias Gaertner <tob.gaertner@me.com>
Sun, 29 Mar 2026 11:17:02 +0000 (04:17 -0700)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Tue, 7 Apr 2026 16:43:38 +0000 (18:43 +0200)
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: 82cae269cfa95 ("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>
fs/ntfs3/run.c

index c0324cdc174dd03f7dc4bce05ac7ef15c470d76d..29817ecb1c7d4f946074b48f1232881373bc082b 100644 (file)
@@ -1008,6 +1008,9 @@ int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,
                if (size_size > sizeof(len))
                        return -EINVAL;
 
+               if (run_buf + size_size > run_last)
+                       return -EINVAL;
+
                len = run_unpack_s64(run_buf, size_size, 0);
                /* Skip size_size. */
                run_buf += size_size;
@@ -1020,6 +1023,9 @@ int run_unpack(struct runs_tree *run, struct ntfs_sb_info *sbi, CLST ino,
                else if (offset_size <= sizeof(s64)) {
                        s64 dlcn;
 
+                       if (run_buf + offset_size > run_last)
+                               return -EINVAL;
+
                        /* Initial value of dlcn is -1 or 0. */
                        dlcn = (run_buf[offset_size - 1] & 0x80) ? (s64)-1 : 0;
                        dlcn = run_unpack_s64(run_buf, offset_size, dlcn);