svn commit: r335696 - head/sbin/fsck_msdosfs

Xin LI delphij at FreeBSD.org
Wed Jun 27 06:49:21 UTC 2018


Author: delphij
Date: Wed Jun 27 06:49:20 2018
New Revision: 335696
URL: https://svnweb.freebsd.org/changeset/base/335696

Log:
  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

Modified:
  head/sbin/fsck_msdosfs/Makefile
  head/sbin/fsck_msdosfs/boot.c

Modified: head/sbin/fsck_msdosfs/Makefile
==============================================================================
--- head/sbin/fsck_msdosfs/Makefile	Wed Jun 27 04:58:39 2018	(r335695)
+++ head/sbin/fsck_msdosfs/Makefile	Wed Jun 27 06:49:20 2018	(r335696)
@@ -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>

Modified: head/sbin/fsck_msdosfs/boot.c
==============================================================================
--- head/sbin/fsck_msdosfs/boot.c	Wed Jun 27 04:58:39 2018	(r335695)
+++ head/sbin/fsck_msdosfs/boot.c	Wed Jun 27 06:49:20 2018	(r335696)
@@ -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;


More information about the svn-src-all mailing list