]> 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>
Tue, 20 Feb 2024 12:02:24 +0000 (13:02 +0100)
commit445d3d227e68f85157d0301d1706aa488e8423da
tree96f8123065d72624443f3273b92445147e2a769e
parent81dc3a4d3bb9fd0847530a3530f860e08a9b3ad3
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.

Approved by: mckusick
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D43978
sys/fs/msdosfs/denode.h
sys/fs/msdosfs/msdosfs_denode.c
sys/fs/msdosfs/msdosfs_lookup.c