]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
msdosfs: fix potential inode collision on FAT12 and FAT16
authorStefan Eßer <se@FreeBSD.org>
Tue, 20 Feb 2024 12:02:24 +0000 (13:02 +0100)
committerStefan Eßer <se@FreeBSD.org>
Fri, 23 Feb 2024 12:42:34 +0000 (13:42 +0100)
commit6831288c8c4091c533c590d2d3cbb07459f2d28b
tree16583e3fd6f34fd5c61867688a00b7bb5a899c6a
parente99479f817c4714d396de1d403daa6f9bc3a32bb
msdosfs: fix potential inode collision on FAT12 and FAT16

FAT file systems do not use inodes, instead all file meta-information
is stored in directory entries.

FAT12 and FAT16 use a fixed size area for root directories, with
typically 512 entries of 32 bytes each (for a total of 16 KB) on hard
disk formats. The file system data is stored in clusters of typically
512 to 4096 bytes, depending on the size of the file system.

The current code uses the offset of a DOS 8.3 style directory entry as
a pseudo-inode, which leads to inode values of 0 to 16368 for typical
root directories with 512 entries.

Sub-directories use 2 cluster length plus the byte offset of the
directory entry in the data area for the pseudo-inode, which may be
as low as 1024 in case of 512 byte clusters. A sub-directory in
cluster 2 and with 512 byte clusters will therefore lead to a
re-use of inode 1024 when there are at least 32 DOS 8.3 style
filenames in the root directory (or 11 14-character Windows
long file names, each of which takes up 3 directory entries).

FAT32 file systems are not affected by this issue and FAT12/FAT16
file systems with larger cluster sizes are unlikely to have as
many directory entries in the root directory as are required to
cause the collision.

This commit leads to inode numbers that are guaranteed to not collide
for all valid FAT12 and FAT16 file system parameters. It does also
provide a small speed-up due to more efficient use of the vnode cache.

PR:             277239
Reviewed by: mckusick
Approved by:    re (cperciva)

(cherry picked from commit 445d3d227e68f85157d0301d1706aa488e8423da)
(cherry picked from commit a495e7f5c5c2088bf32cd7349e2ca344ee089552)
sys/fs/msdosfs/denode.h
sys/fs/msdosfs/msdosfs_denode.c
sys/fs/msdosfs/msdosfs_lookup.c