HomeFreeBSD

fs/msdosfs: Fix potential panic and size calculations

Description

fs/msdosfs: Fix potential panic and size calculations

Some combinations of FAT12 file system parameters could cause a kernel
panic due to an unmapped access if the size of the FAT was larger than
the CPU page size. The reason is that FAT12 uses 3 bytes to store
2 FAT pointers, leading to partial FAT pointers at the end of buffers
of a size that is not a multiple of 3.

With a typical page size of 4 KB, this caused the FAT entry at byte
offsets 4095 and 4096 to cross the page boundary, with only the first
page mapped. This was fixed by adjusting the mapping to always cover
both bytes of each FAT entry.

Testing revealed 2 other inconsistencies that are fixed by this commit:

  1. The calculation of the size of the data area did not take into account the fact that the first two data block numbers are reserved and that the data area starts with block 2. This could cause a FAT12 file system created with the maximum supported number of blocks to be incorrectly identified as FAT16.
  1. The root directory does not take up space in the data area of a FAT12 or FAT16 file system, since it is placed into a reserved area outside of that data area. This commits makes stat() report the logical size of the root directory, but with 0 blocks allocated from the data area.

PR: 270587
Reviewed by: mckusick
Differential Revision: https://reviews.freebsd.org/D39386

Details

Provenance
seAuthored on Apr 25 2023, 6:35 AM
Reviewer
mckusick
Differential Revision
D39386: Fix panic and other issues in msdosfs
Parents
rG4b932c2c9ef7: Set MK_host_egacy=yes earlier
Branches
Unknown
Tags
Unknown