diff options
author | Xin LI <delphij@FreeBSD.org> | 2018-06-27 06:49:20 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2018-06-27 06:49:20 +0000 |
commit | 6f0f107256915c4ba37ee06062a3163cd42614d4 (patch) | |
tree | 674762ef53a8a4478027a0759a0f393d811ed782 /sbin | |
parent | bc6cb3f6b40b05e0d6017f65180e2b874224e890 (diff) | |
download | src-6f0f107256915c4ba37ee06062a3163cd42614d4.tar.gz src-6f0f107256915c4ba37ee06062a3163cd42614d4.zip |
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
Notes
Notes:
svn path=/head/; revision=335696
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fsck_msdosfs/Makefile | 2 | ||||
-rw-r--r-- | sbin/fsck_msdosfs/boot.c | 26 |
2 files changed, 23 insertions, 5 deletions
diff --git a/sbin/fsck_msdosfs/Makefile b/sbin/fsck_msdosfs/Makefile index b101724a8801..522594cd28d8 100644 --- a/sbin/fsck_msdosfs/Makefile +++ b/sbin/fsck_msdosfs/Makefile @@ -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> diff --git a/sbin/fsck_msdosfs/boot.c b/sbin/fsck_msdosfs/boot.c index 9fe5e15b396a..9a954d07ae9e 100644 --- a/sbin/fsck_msdosfs/boot.c +++ b/sbin/fsck_msdosfs/boot.c @@ -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; |