From nobody Tue Mar 29 23:05:21 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E9F531A37E69; Tue, 29 Mar 2022 23:05:26 +0000 (UTC) (envelope-from rpokala@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KSlXQ6B89z4YlH; Tue, 29 Mar 2022 23:05:26 +0000 (UTC) (envelope-from rpokala@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648595126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+dfr0r62Sox75aBarsGE1YmloX6M3VN1lHkUiEmjSGg=; b=xILe1U0qgKtwPZnrcQceDq9KApbFJ4V3sHLyz1Cfabu4Q4oNnoVMato4M3V/ADbEYft4K0 NIaw/MfDYxYjEP59fX09E2epo132o9aNrFMskmMEg3exgZCg/h0BSRP+j1AVjaKnWOqzhC 0JzjxacRgMbTdwfHu3DfK1PohpEKHqis/yPe4yKlUJGytyojKMykBRyZOCRqm3iC2s8w0n lIO8PC7ORTKjImyGR0EpQ/ryG02KFH3Wk568/jmgkNidWgmWk6LwLCgnmh51Sx/3Lxrptl LLlZt1A9iB8hs0uuX8sb9GdtyGUU8Syyo80jHVZQE3ASrvEUsTVIu40fNhdDxQ== Received: from [192.168.1.10] (unknown [98.42.164.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: rpokala) by smtp.freebsd.org (Postfix) with ESMTPSA id 27875366A2; Tue, 29 Mar 2022 23:05:26 +0000 (UTC) (envelope-from rpokala@freebsd.org) User-Agent: Microsoft-MacOutlook/16.59.22031300 Date: Tue, 29 Mar 2022 16:05:21 -0700 Subject: Re: 868c1b8431f2 - main - fstyp: detect Raspberry Pi Pico boot filesystem as FAT From: Ravi Pokala To: Ed Maste , , , Message-ID: Thread-Topic: 868c1b8431f2 - main - fstyp: detect Raspberry Pi Pico boot filesystem as FAT References: <202203292133.22TLXbxW035667@gitrepo.freebsd.org> In-Reply-To: <202203292133.22TLXbxW035667@gitrepo.freebsd.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648595126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+dfr0r62Sox75aBarsGE1YmloX6M3VN1lHkUiEmjSGg=; b=cvoupvd+uF9vYADyGxg/Iin4Jb7mcz4wge8fiQ4UCVIobh5Lkpp0BTeJhQJywAfegMIDJ6 ZQbgHu/Vp0g2PbSZnd9ZNtd4spchs4hM69JoKcY3nRWIsiCA52Lh9j8b7al39Jze75krHE rp/P2Mdww2ZXP6kGgvNHyzQh4AmcTqeqH1lDbnep0DgWMNCSW/LvIX9FGTjze5qw+ix0/V PoteNLqK0oonFZndBD+i4jqnCt3VGdMKcK6M7W3qkyQUWNcWVcrDWIVE+73iV1g0vSqe3y 4j1k7BLMs9H8dBUuVaYdAmM6EOqAr1O5XbJd/69HpwPcjPtTczu9zcDRFGBgow== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648595126; a=rsa-sha256; cv=none; b=rz5UlHMFT2ZSOIeI/5InajbyPLNKjp2iT+oMyjl8etkv7Wk4vZrmTU/KKaz8T5syU7J5sY rhRPX+EbO/zux7SvR9Ia4BeeNnpl0GIRV8+zy9FxYEYpmb2u2fHG29Zw1lepmVyfTiO4K9 HKAqr3sHGX/qXQwP0wg7QSz3btTGqp9+KNrY8JBukv2EFYSR0HBU5RfLR+F+piTY5sHQNC FMr8qR2unDopz4yv/9HqFMKZKSwWxABLwWYGP+/WjOMqR2t/uobITwRy04ykfY7GnX1F0i 0YYcOvnMirxnIqMOGAlW/KEdYF+p/h4WOsUBVwZpj5ZQN6sBdGoyExDhCMZsTw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N "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: on behalf of Ed Maste Date: 2022-03-29, Tuesday at 14:33 To: , , 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 AuthorDate: 2022-03-28 21:03:10 +0000 Commit: Ed Maste 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; }