From owner-svn-src-all@freebsd.org Thu Jul 12 05:37:53 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0F2141030D6B; Thu, 12 Jul 2018 05:37:53 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B98607D52C; Thu, 12 Jul 2018 05:37:52 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 97ACB1D311; Thu, 12 Jul 2018 05:37:52 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6C5bqW5008488; Thu, 12 Jul 2018 05:37:52 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6C5bqF1008487; Thu, 12 Jul 2018 05:37:52 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201807120537.w6C5bqF1008487@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Thu, 12 Jul 2018 05:37:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r336218 - stable/11/sbin/fsck_msdosfs X-SVN-Group: stable-11 X-SVN-Commit-Author: delphij X-SVN-Commit-Paths: stable/11/sbin/fsck_msdosfs X-SVN-Commit-Revision: 336218 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jul 2018 05:37:53 -0000 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;