Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: ntfs3: Fix integer overflow in run_unpack()

The MFT record relative to the file being opened contains its runlist,
an array containing information about the file's location on the physical
disk. Analysis of all Call Stack paths showed that the values of the
runlist array, from which LCNs are calculated, are not validated before
run_unpack function.

The run_unpack function decodes the compressed runlist data format
from MFT attributes (for example, $DATA), converting them into a runs_tree
structure, which describes the mapping of virtual clusters (VCN) to
logical clusters (LCN). The NTFS3 subsystem also has a shortcut for
deleting files from MFT records - in this case, the RUN_DEALLOCATE
command is sent to the run_unpack input, and the function logic
provides that all data transferred to the runlist about file or
directory is deleted without creating a runs_tree structure.

Substituting the runlist in the $DATA attribute of the MFT record for an
arbitrary file can lead either to access to arbitrary data on the disk
bypassing access checks to them (since the inode access check
occurs above) or to destruction of arbitrary data on the disk.

Add overflow check for addition operation.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Signed-off-by: Vitaly Grigoryev <Vitaly.Grigoryev@kaspersky.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>

authored by

Vitaly Grigoryev and committed by
Konstantin Komarov
736fc7bf 4e8011ff

+9 -3
+9 -3
fs/ntfs3/run.c
··· 9 9 #include <linux/blkdev.h> 10 10 #include <linux/fs.h> 11 11 #include <linux/log2.h> 12 + #include <linux/overflow.h> 12 13 13 14 #include "debug.h" 14 15 #include "ntfs.h" ··· 983 982 984 983 if (!dlcn) 985 984 return -EINVAL; 986 - lcn = prev_lcn + dlcn; 985 + 986 + if (check_add_overflow(prev_lcn, dlcn, &lcn)) 987 + return -EINVAL; 987 988 prev_lcn = lcn; 988 989 } else { 989 990 /* The size of 'dlcn' can't be > 8. */ 990 991 return -EINVAL; 991 992 } 992 993 993 - next_vcn = vcn64 + len; 994 + if (check_add_overflow(vcn64, len, &next_vcn)) 995 + return -EINVAL; 996 + 994 997 /* Check boundary. */ 995 998 if (next_vcn > evcn + 1) 996 999 return -EINVAL; ··· 1158 1153 return -EINVAL; 1159 1154 1160 1155 run_buf += size_size + offset_size; 1161 - vcn64 += len; 1156 + if (check_add_overflow(vcn64, len, &vcn64)) 1157 + return -EINVAL; 1162 1158 1163 1159 #ifndef CONFIG_NTFS3_64BIT_CLUSTER 1164 1160 if (vcn64 > 0x100000000ull)