freebsd-dev/sys/fs/msdosfs
Stefan Eßer 0728695c63 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.

2) 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
2023-04-25 09:58:29 +02:00
..
bootsect.h
bpb.h
denode.h msdosfs: drop now unused DE_RENAME 2021-08-27 18:39:45 +03:00
direntry.h
fat.h msdosfs: clusterfree() is used only in error handling cases 2022-01-08 05:41:44 +02:00
msdosfs_conv.c
msdosfs_denode.c msdosfs: fix debug print format and parameter 2023-03-08 17:58:00 +01:00
msdosfs_fat.c fs/msdosfs: Fix potential panic and size calculations 2023-04-25 09:58:29 +02:00
msdosfs_iconv.c
msdosfs_lookup.c fs/msdosfs: add tracking of free root directory entries 2023-03-29 08:46:01 +02:00
msdosfs_vfsops.c fs/msdosfs: Fix potential panic and size calculations 2023-04-25 09:58:29 +02:00
msdosfs_vnops.c fs/msdosfs: Fix potential panic and size calculations 2023-04-25 09:58:29 +02:00
msdosfsmount.h fs/msdosfs: add tracking of free root directory entries 2023-03-29 08:46:01 +02:00