Commit Graph

700 Commits (0911ef206dc8fea68e18282a1ee5f4489cf0ca1d)

Author SHA1 Message Date
Jean-Pierre André 0911ef206d Rejected negative data length in an attribute list
The negative data length of an attribute list is an indication of a
probable corruption and must be rejected.
2021-07-19 09:23:23 +02:00
Jean-Pierre André b95b4ba1a5 Rejected negative data length in readall()
The negative data length of an attribute is an indication of a probable
corruption and must be rejected.
2021-07-19 09:23:23 +02:00
Jean-Pierre André e70d10d848 Added a check of the minimal length of some attributes
The minimal lengths of STANDARD_ATTRIBUTE and OBJECT_ID were not
checked and could lead to out-of-buffer access.
2021-07-19 09:23:23 +02:00
Jean-Pierre André 2bf5077804 Checked consistency of index blocks
Improved existing consistency checks of index blocks and grouped them
into a specific function.
2021-07-19 09:23:23 +02:00
Jean-Pierre André 55e7326350 Avoided endless recursions when allocating the main bitmap
Allocating clusters to the main bitmap may imply updating the bitmap
itself within a cluster not yet allocated. This can turn into endless
recursions and has to be rejected. Currently the bitmap is assumed
to be fully allocated.
2021-07-19 09:23:23 +02:00
Jean-Pierre André 61134117c1 Fixed checking the end of attrdef data
Incomplete attribute definitions have to be rejected.
2021-07-19 09:23:23 +02:00
Jean-Pierre André f85ce6ff2e Skipped errors for bad free clusters before they are computed
The count of free clusters may be updated while mounting before it
has been initialized, which may lead to irrelevant error messages.
Moreover the count is not computed at all in some ntfsprogs utilities.
So set up a flags to avoid outputting irrelevant errors.
2021-07-19 09:23:23 +02:00
Jean-Pierre André 67f959df96 Fixed the computation of the end of index entry
The end of an index entry is related to its full length, not to the
length of the key. Added an error message in an overflow case.
2021-07-12 08:31:18 +02:00
Jean-Pierre André 5c002438f2 Checked that indexes do not exceed the index block size
Make sure the used part of an index block fits into the allocated buffer.
Note : a negative size may cause overflow on 32-bit cpus.
(contributed by Rakesh Pandit)
2021-07-12 08:31:18 +02:00
Jean-Pierre André 20d700841b Shown in log the inode of directory read error
The unreadable directory record was poorly identified
2021-07-12 08:31:18 +02:00
Jean-Pierre André f30b52490f Restricted the attribute definition table size to 24 bits
The standard size is 2560 bytes. It can be extended for specific purposes,
but its former limit to 32 bits was unreasonable. Anyway ntfs-3g is
not committed to support non-standard situations.
2021-07-12 08:31:18 +02:00
Jean-Pierre André af1bc0f5ec Hardened the check of locations of MFT and MFTMirr
The MFT and MFTMirr may not be negative or overlap the boot sector.
2021-07-12 08:31:18 +02:00
Jean-Pierre André 7f45544ed7 Added and grouped generic attribute checks
Checked that attributes are [non-]resident when they have to be, and
grouped consistency checks on each of them in a dedicated function.
Consequenly request the checks where needed and remove existing index
checks.
2021-07-12 08:31:18 +02:00
Jean-Pierre André 436fe09f87 Checked consistency of index entries
Make sure the data and key in indexes do not overflow from index entries
2021-07-12 08:31:18 +02:00
Jean-Pierre André 32e858a87a Aborted mounting when cannot access standard information of MFT
The standard information of the MFT must be its first attribute in the
base record. If it is not accessible initially, we end up searching it
in an extent before the MFT struct is ready for that.
2021-07-12 08:31:18 +02:00
Jean-Pierre André 68ead9b8fc Checked expanded attribute does not overflow the space in use
When resizing an attribute, make sure the trailing data is moved in
the correct direction.
2021-07-12 08:31:18 +02:00
Jean-Pierre André 84478c4012 Checked attributes layout against length actually used
The end of the attributes must be checked against the space in use
rather than the allocated space. This contributes to the safety of
subsequent attribute resizing.
2021-07-12 08:31:18 +02:00
Jean-Pierre André ec7bf54377 Checked the MFTMirr lcn to be consistent with the boot sector
The lcn of the initial run of the MFTMirr data must be the same as
described in the boot sector. As a consequence this cannot be a hole.
2021-07-12 08:31:18 +02:00
Jean-Pierre André 4e094563d4 Checked $MFT data to be ready before fetching an extent 2021-07-12 08:31:18 +02:00
Jean-Pierre André e2e625065d Checked the layout of attribute list entries
Make sure the attribute list has at least one element, and that each of
them has the minimal size and does not overflow out of the end of list.
2021-07-12 08:31:17 +02:00
Jean-Pierre André 4e09b252af Checked name limits while looking up for an external attribute
Make sure the name of an attribute does not overflow beyond the
attribute length.
2021-07-12 08:31:17 +02:00
Jean-Pierre André d86c34390d Added a consistency check of attribute size in readall()
Make sure the attribute designated to readall() has a reasonable size.
Apart from a bitmap, in a valid call, the attribute size is limited to
65536, and bitmaps are limited by the number of cluster.
2021-05-17 15:39:52 +03:00
Jean-Pierre André 37a330ea8c Improved the consistency checks of standard information
Make sure the standard information attribute has a valid size.
2021-05-17 15:39:13 +03:00
Jean-Pierre André 218d93b37b Cleaned the tail of compressed buffer before writing a full cluster
When appending to an existing compressed file, the last block must first
be decompressed. When doing so, clear the tail of buffer in order to not
leak unrelated data.
2021-05-17 15:38:20 +03:00
Jean-Pierre André 02e199978b Fixed initialization of a Posix ACL
A posix ACL record was not fully initialized.
2021-05-17 15:37:45 +03:00
Jean-Pierre André 8adc9c6184 Hardened consistency checks of MFT records
Check the record is properly aligned and does not flow beyond the
expected end of the record.
2021-05-17 15:35:02 +03:00
Jean-Pierre André bb0168e56b Rejected updates of uninitialized MFTMirr
Reject updating uninitialized MFTMirr because it leads to endless
recursions as updating the MFTMirr entry of MFT implies further updating
MFTMirr.
This is probably specific to ntfsfix, as mounts are normally rejected
when MFTMirr does not match MFT.
2021-05-17 15:33:41 +03:00
Jean-Pierre André 3f3b771cb0 Added consistency checks of index root
The index root must lie within the space allocated for it.
2021-05-17 15:33:04 +03:00
Jean-Pierre André 00a5478625 Added check of layout of attributes
Make sure the attributes fully lie within the MFT record, and make sure
their variable components (name, runlist, value) fully lie within the
attribute.
2021-05-17 15:31:52 +03:00
Jean-Pierre André 1258474e07 Improved check of upcase table length
The consistency check on the upcase size was laxist.
The unicode points are limited to 1048575 (20 bits), but there is no
provision to support code points beyond 65535.
In the current implementation the upcase size must be even and <= 131072.
2021-05-17 15:30:17 +03:00
Jean-Pierre André 2ede3b67ee Improved checking of the location of MFT
Terminate cleanly when the MFT is improperly located, by making sure it
is located within the volume and that it contains its own data.
2021-03-05 10:21:36 +01:00
Jean-Pierre André 094f9b3f2d Fixed a minor endianness ajustment bug
The endianness ajustment was the wrong one though it did the correct thing.
2021-01-26 10:06:18 +01:00
Jean-Pierre André 894b7dd36e Checked the locations of MFT and MFTMirr at startup
On startup make sure the lcns of the MFT and the MFTMirr are not null and
they are different, so that the mounting is denied gracefully if they are.
2021-01-26 10:06:18 +01:00
Jean-Pierre André 5d46b32b91 Enabled Recording the special files the same way as WSL
Optionally record the special files (symlinks, fifos, sockets, character
and block devices) using reparse points instead of using Interix representation.
Doing so, the special files are interoperable with Windows Subsystem for
linux (WSL).
2021-01-26 10:06:18 +01:00
Jean-Pierre André 172da09947 Dropped rejecting having both EA and reparse data
Windows traditionally rejected having both EA and reparse data assigned
to a file, but Windows 10 has dropped the constraint and it uses this
condition massively, so do the same. Note that pre-Windows 10 chkdsk.exe
removes the EA' on reparse points, potentially damaging more recent
volumes.
2021-01-26 10:06:17 +01:00
Jean-Pierre André 8073ab6764 Supported use of WSL special file
The Windows Subsystem for Linux (WSL) of Windows 10 uses reparse points
to record special files (symlinks, fifos, sockets, char or block devices).
Honor such reparse points with the same meaning as WSL.
2021-01-26 10:06:17 +01:00
Jean-Pierre André 8fa3dd3f22 Defined ntfs_realloc() and ntfs_free()
Currently memory allocations are done through ntfs_malloc() and
ntfs_calloc(), but releases are done through free(3). Defining an
ntfs_free() relay facilitates the debugging of memory leaks in
plugins.
2021-01-26 10:06:17 +01:00
Jean-Pierre André 76fe04d03d Built reparse symlinks from mount point recorded in volume
When building a symlink to emulate a Windows junction or absolute
symlink, use the mount point recorded in the volume attributes.
This enables the plugins to emulate object as symlinks.
2021-01-26 10:06:17 +01:00
Jean-Pierre André 02673bd04a Enabled actions on directories in reparse plugins
The plugins triggered by reparse points can now act on a directory
through link(2) unlink(2) and creat(2).
2021-01-26 10:06:17 +01:00
Jean-Pierre André 4b8a660006 Fixed maintining the allocated size when updating sparse files
When filling a hole in a sparse file, the beginning of the runlist
does not need to be updated. However the allocated size is within
the extent holding its beginning and it needs to be updated.
2020-11-18 11:33:49 +01:00
Jean-Pierre André cd68a084fc Recovered space when an index root is shortened
In rare situations, removing an entry from an index root while
rebalancing the index tree, its space was not recovered from the index
root, causing chkdsk to complain. Truncate the index root when this
happens.
2020-08-14 11:57:02 +02:00
Jean-Pierre André d6558f1dea Defined option "posix_nlink" to compute a Posix compliant st_nlink
When the mount option "posix_nlink" is used, the number of links
returned by stat complies with Posix : the legacy 8.3 names are not
taken into account, and the subdirectories are taken into account
for directories. This causes some overhead for recomputing the
number of links.
2020-08-14 11:50:35 +02:00
Jean-Pierre André 1bc996f52f Avoided information leak when processing garbled compressed data
When a compressed file has been deteriorated through hardware error
or accidental overwriting, some unrelated data could be leaked.
Make sure to zero fill the buffer when this happens.
2020-08-14 11:36:57 +02:00
Jean-Pierre André 4163390f2b Fixed defining the request argument of ioctl()
An occurrence of changing the request from int to unsigned long was
missing.
2020-03-08 10:34:17 +01:00
Jean-Pierre André 3f65ccd949 Exported the translations of Windows paths
The translations of Windows paths designed for translating Windows symlinks
and mount points may also be used in plugins for translation execlinks,
so make them available.
2020-03-08 10:17:21 +01:00
Jean-Pierre André 7cd46f95df Fixed object types returned in readdir() for reparse points
The types of reparse point objects cannot be decided upon the data
available in a directory, so we must delegate their determination to a
specific plugin when available, and be consistent if there is none.
2020-03-08 10:03:23 +01:00
Jean-Pierre André b68c27ea74 Silenced warnings about string lengths in snprintf()
Adjust string lengths to the worst case estimated by the compiler, even
though they cannot be reached.
2020-03-08 09:29:04 +01:00
Jean-Pierre André c5530af508 Silenced warnings about fallthrough situations in libntfs-3g
Insert a comment when fallthrough situations are desired in switch cases.
2020-03-07 12:00:11 +01:00
Jean-Pierre André aa7af7d53b Fixed returning EPERM when not allowed as owner
For actions which may be allowed depending on the ownership rather than
permissions (such as utime()), return EPERM if the owner cannot be
determined.
2020-03-07 11:35:48 +01:00
Jean-Pierre André 314b5396bd Fixed returning errno in setxattr
In case of error in setxattr, it must be returned in errno instead
of the return value.
2020-03-07 10:51:53 +01:00