Detect exFAT filesystems and abort if found and tighten BPB sanity

check.

Obtained from:	Android https://android-review.googlesource.com/61827
MFC after:	2 weeks
This commit is contained in:
Xin LI 2018-06-27 06:49:20 +00:00
parent bc6cb3f6b4
commit 6f0f107256
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=335696
2 changed files with 23 additions and 5 deletions

View File

@ -9,6 +9,8 @@ PROG= fsck_msdosfs
MAN= fsck_msdosfs.8
SRCS= main.c check.c boot.c fat.c dir.c fsutil.c
DEBUG_FLAGS+= -g
CFLAGS+= -I${FSCK}
.include <bsd.prog.mk>

View File

@ -82,6 +82,11 @@ readboot(int dosfs, struct bootblock *boot)
boot->FATsecs = boot->bpbFATsmall;
if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE_REAL != 0 ||
boot->bpbBytesPerSec / DOSBOOTBLOCKSIZE_REAL == 0) {
pfatal("Invalid sector size: %u", boot->bpbBytesPerSec);
return FSFATAL;
}
if (!boot->bpbRootDirEnts)
boot->flags |= FAT32;
if (boot->flags & FAT32) {
@ -102,6 +107,22 @@ readboot(int dosfs, struct bootblock *boot)
boot->bpbFSInfo = block[48] + (block[49] << 8);
boot->bpbBackup = block[50] + (block[51] << 8);
/* If the OEM Name field is EXFAT, it's not FAT32, so bail */
if (!memcmp(&block[3], "EXFAT ", 8)) {
pfatal("exFAT filesystem is not supported.");
return FSFATAL;
}
/* check basic parameters */
if ((boot->bpbFSInfo == 0) || (boot->bpbSecPerClust == 0)) {
/*
* Either the BIOS Parameter Block has been corrupted,
* or this is not a FAT32 filesystem, most likely an
* exFAT filesystem.
*/
pfatal("Invalid FAT32 Extended BIOS Parameter Block");
return FSFATAL;
}
if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec,
SEEK_SET) != boot->bpbFSInfo * boot->bpbBytesPerSec
|| read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) {
@ -178,11 +199,6 @@ readboot(int dosfs, struct bootblock *boot)
/* Check backup bpbFSInfo? XXX */
}
if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE_REAL != 0 ||
boot->bpbBytesPerSec == 0) {
pfatal("Invalid sector size: %u", boot->bpbBytesPerSec);
return FSFATAL;
}
if (boot->bpbSecPerClust == 0) {
pfatal("Invalid cluster size: %u", boot->bpbSecPerClust);
return FSFATAL;