From nobody Tue Mar 29 21:33:37 2022 X-Original-To: dev-commits-src-main@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 F3DD61A48BCF; Tue, 29 Mar 2022 21:33:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KSjVT6YGBz3mkW; Tue, 29 Mar 2022 21:33:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648589617; 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; bh=lVmWl2Yk/ewTTHPMW9nV37Ol85kEMVIVqpzamvzRze8=; b=PY+phBB6j9CPMevsytaO3uafZbYVdQbCXw0O/Jhd7uTrn4AVU3T6Hxbj5iyaR/BnehetUB OdGIjW6LAuEtkxlPV6MDb8A/v37alOdoRYWVLP7/KJ73hAIPpn31GMpxFDnrefpqVWfBHA 1L7EKLtXL2M8ttflDrZv03M7omWhQlh/CviTqEXML7s3REal+tHxxA3n9tzZHicsJWrY8/ 2CnrOU0dchiV0Wh62Q4Q9oEFkjmuhe9Qh3UjSVSdpanOEbFMtb0OTd8/KRqmXvCk6F84Qf vOXFKOslBBdh+tXD4iMBOAUQYttCW22Ml1xSjXNFoLV5QxWmDUN5m87NwRVprQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C0FBE26726; Tue, 29 Mar 2022 21:33:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22TLXb0o035668; Tue, 29 Mar 2022 21:33:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22TLXbxW035667; Tue, 29 Mar 2022 21:33:37 GMT (envelope-from git) Date: Tue, 29 Mar 2022 21:33:37 GMT Message-Id: <202203292133.22TLXbxW035667@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 868c1b8431f2 - main - fstyp: detect Raspberry Pi Pico boot filesystem as FAT List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 868c1b8431f297ade8deba5baf903f73cf5e11c6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648589617; 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; bh=lVmWl2Yk/ewTTHPMW9nV37Ol85kEMVIVqpzamvzRze8=; b=JM/PNd1ow4AgiaZaFtZGeDFiNk+IcNF94Fpa7twRE4HAJluMD5HS+UZKNBoYNUHF813KmO AknJDONFFfbXLB77O9vHUdaY/uK+Lu1sHGVHVVmLj2RLUNdodfOYPsIw+zdnBt1NE42ngN ZCd39oEFnqTrhLPA+PH+/fGStqbVeoHgFEDt2IdieLp7DW60LkIX13HPdZl4lPGbi7I8PN KgqZC63T/iFJyoPBGdmVcDqarc13HDTVkMrMFQPQMiLIqWk28fuhATbPURGZcYJBnwfXg6 8qI6L7cTTEqXEor5eMNnIpW6Jn9P/LlIrR+c4sOdw64VD4Hpuj61TgZ7TbYeCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648589617; a=rsa-sha256; cv=none; b=prF2SkDro92r8cjdi6wHy60OTjnr1FGYAJgOBkDtnCCvmhO4YURWJ00Myk1jMxqeScmNW9 vd+pVWdjfHSGjQBPyfVbMOowIrAWFoE4hzFW2DPVLyXF8oMH1gIHxQupg8tvHWOSj1mT1B op0V7FiUoSAwpzjaEBZHtPf/g6VMBbz/gJ7kNJcrcKWxGYhlNWt+cD6eXTVqZDclYFoiQ3 ARFHVQ6XuQ/fkrXvqK3G4ZeQSJld5bHnTvCJoTuduCSk/yBbXajALV10QdnTSbdAwUYz8K mcY9ucmS9df8LpGctyvtut2kPSKh76GE/1Q+ibswH3xDNHil+PgOsa/zSgTPpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=868c1b8431f297ade8deba5baf903f73cf5e11c6 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 not 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 new 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 required + * by specifications, but was historically required by fstyp. This check + * 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] == 0x55 && sector0[511] == 0xaa) + return (true); + /* Special case for Raspberry Pi Nano bootloader. */ + if (sector0[510] == 0 && sector0[511] == 0 && + sector0[0] == 0xeb && sector0[1] == 0x3c && sector0[2] == 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 == NULL) return (1); - /* Check for the FAT boot sector signature. */ - if (sector0[510] != 0x55 || sector0[511] != 0xaa) { + if (!check_signature(sector0)) { goto error; }