Author: delphij
Date: Thu Jul 12 05:37:52 2018
New Revision: 336218
URL: https://svnweb.freebsd.org/changeset/base/336218

Log:
  MFC r335696,r335697:
  
  Detect exFAT filesystems and abort if found and tighten BPB sanity
  check.
  
  Obtained from:        Android https://android-review.googlesource.com/61827

Modified:
  stable/11/sbin/fsck_msdosfs/boot.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sbin/fsck_msdosfs/boot.c
==============================================================================
--- stable/11/sbin/fsck_msdosfs/boot.c  Thu Jul 12 02:51:50 2018        
(r336217)
+++ stable/11/sbin/fsck_msdosfs/boot.c  Thu Jul 12 05:37:52 2018        
(r336218)
@@ -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;
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to