Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Mar 2022 16:05:21 -0700
From:      Ravi Pokala <rpokala@freebsd.org>
To:        Ed Maste <emaste@FreeBSD.org>, <src-committers@FreeBSD.org>, <dev-commits-src-all@FreeBSD.org>, <dev-commits-src-main@FreeBSD.org>
Subject:   Re: 868c1b8431f2 - main - fstyp: detect Raspberry Pi Pico boot filesystem as FAT
Message-ID:  <ED18364E-18F5-4662-89AA-2838F3A253C1@panasas.com>
In-Reply-To: <202203292133.22TLXbxW035667@gitrepo.freebsd.org>
References:  <202203292133.22TLXbxW035667@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
"0x55 0xaa" at offset 510 is the signature for a (P)MBR partition table, no=
t a FAT filesystem.

-Ravi (rpokala@)

=EF=BB=BF-----Original Message-----
From: <owner-src-committers@freebsd.org> on behalf of Ed Maste <emaste@Free=
BSD.org>
Date: 2022-03-29, Tuesday at 14:33
To: <src-committers@FreeBSD.org>, <dev-commits-src-all@FreeBSD.org>, <dev-c=
ommits-src-main@FreeBSD.org>
Subject: git: 868c1b8431f2 - main - fstyp: detect Raspberry Pi Pico boot fi=
lesystem as FAT

    The branch main has been updated by emaste:

    URL: https://cgit.FreeBSD.org/src/commit/?id=3D868c1b8431f297ade8deba5baf=
903f73cf5e11c6

    commit 868c1b8431f297ade8deba5baf903f73cf5e11c6
    Author:     Ed Maste <emaste@FreeBSD.org>
    AuthorDate: 2022-03-28 21:03:10 +0000
    Commit:     Ed Maste <emaste@FreeBSD.org>
    CommitDate: 2022-03-29 21:33:15 +0000

        fstyp: detect Raspberry Pi Pico boot filesystem as FAT

        fstyp looks for a 0x55 0xAA signature at offset 510, but this is no=
t
        required by specifications and is not proivded by the Raspberry Pi =
Nano
        bootloader.

        We should really remove the signature check and implement a more
        comprehensive BPB validation instead, but it will require more
        investigation and testing.  For now just add a special case for the
        Raspberry Pi Nano bootloader, to avoid introducing regressions or n=
ew
        false positives.

        PR:             262896
        Reviewed by:    delphij
        MFC after:      3 days
        Sponsored by:   The FreeBSD Foundation
        Differential Revision:  https://reviews.freebsd.org/D34699
    ---
     usr.sbin/fstyp/msdosfs.c | 21 +++++++++++++++++++--
     1 file changed, 19 insertions(+), 2 deletions(-)

    diff --git a/usr.sbin/fstyp/msdosfs.c b/usr.sbin/fstyp/msdosfs.c
    index 47d2383fbc8f..b2144fa46cb1 100644
    --- a/usr.sbin/fstyp/msdosfs.c
    +++ b/usr.sbin/fstyp/msdosfs.c
    @@ -41,6 +41,24 @@ __FBSDID("$FreeBSD$");

     #define LABEL_NO_NAME		"NO NAME    "

    +/*
    + * XXX the signature 0x55 0xAA as the last two bytes of 512 is not req=
uired
    + * by specifications, but was historically required by fstyp.  This ch=
eck
    + * should be removed, with a more comprehensive BPB validation instead=
.
    + */
    +static bool
    +check_signature(uint8_t sector0[512])
    +{
    +	/* Check for the FAT boot sector signature. */
    +	if (sector0[510] =3D=3D 0x55 && sector0[511] =3D=3D 0xaa)
    +		return (true);
    +	/* Special case for Raspberry Pi Nano bootloader. */
    +	if (sector0[510] =3D=3D 0 && sector0[511] =3D=3D 0 &&
    +	    sector0[0] =3D=3D 0xeb && sector0[1] =3D=3D 0x3c && sector0[2] =3D=3D 0x90)
    +		return (true);
    +	return (false);
    +}
    +
     int
     fstyp_msdosfs(FILE *fp, char *label, size_t size)
     {
    @@ -58,8 +76,7 @@ fstyp_msdosfs(FILE *fp, char *label, size_t size)
     	if (sector0 =3D=3D NULL)
     		return (1);

    -	/* Check for the FAT boot sector signature. */
    -	if (sector0[510] !=3D 0x55 || sector0[511] !=3D 0xaa) {
    +	if (!check_signature(sector0)) {
     		goto error;
     	}






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ED18364E-18F5-4662-89AA-2838F3A253C1>