From nobody Tue Apr 05 18:54:33 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 D07211A86873; Tue, 5 Apr 2022 18:54:33 +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 4KXxdj5STgz3sTt; Tue, 5 Apr 2022 18:54:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649184873; 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=6AewzhBmoAyee3cfpuVOdx/xeWr44NAEX3lReNpOtj4=; b=l0q43xVbEryxDfcxo7/DAVasL8eBiYy+jyZQyfRvIG19Vf/GW2a12O9xBKZkUv5jmWhodO F+E3+ld724sx7sqmjXmW9MnE9T1xdlLob7EvvqMPN6x10O9Ud9iPn/DiZxUe1K3yZQKpw7 jvPhwSKmlk9NPzfqjMWsM6UjREpih3QoNXYTdPekTZ0Ud4hFe4YJCdLX6n0zfDEWLJ8V0d uH1m6mVM5EYw97oNUZwPu+2SGHOInln8BCUvM7iYcJVberIg/ymEjbrOuT+LA2x/Gt0vCx TvHgwoY76pjzw0o2HQoGHFYOSrQSsojYBXR0vir+7VxODY+CXAV0qluqyWrnEA== 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 9BEA53CC8; Tue, 5 Apr 2022 18:54:33 +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 235IsXDK071236; Tue, 5 Apr 2022 18:54:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 235IsXdg071235; Tue, 5 Apr 2022 18:54:33 GMT (envelope-from git) Date: Tue, 5 Apr 2022 18:54:33 GMT Message-Id: <202204051854.235IsXdg071235@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 7b03cfcb24c2 - releng/13.1 - fstyp: detect Raspberry Pi Pico boot filesystem as FAT 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: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.1 X-Git-Reftype: branch X-Git-Commit: 7b03cfcb24c201a25e92eca854c95dbbca2bc60f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649184873; 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=6AewzhBmoAyee3cfpuVOdx/xeWr44NAEX3lReNpOtj4=; b=Io3ixedQHrr9+RecxzLGJnBjEKUuFnKjxDgxlG4fU8la8DffH5ecj261IJnVl4bb3Ne0UR ClEMfdkx8I7rRvEc36432y3anOQaG3CCFzqTj4iGYPBXY5Ri5O0MHocAKmXClSZ+XcV1Db uzpVtiL0D7zmbTX0AEOh+yXH8QjkXsS7cT8Gu5Sf8aTioO9nmDJYG2beryob06lf3m2TDB eFzojOCgVetApK/mQ+xQutnWVdNw28Y5a4fnambAVc9O6i1eMTqVT2P8HgGIv+nMhO6+Kj 4uGg5va5OpM3d2fX9RcsxcauV+DeP9DemF9OEPIiKNn7zNKb8Z9mQpcllmoPiQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649184873; a=rsa-sha256; cv=none; b=KWg2Rc3fhNpkYdCTPU8BCGzlwTdpweenXHGjhhIOsXft4orlPHqhyjJE3V0ZFtzeqXrrof LyaLuXpQavOOUF9n6Tqq9ixLN7gka2uViSZgnkzz58ZSefLoRj6GeIyER/ToCqrCZrg2nI 4EC4Lz7edUEZwuriirz2uDyyDXWk3000st+wfRlHFRQiBFQXd4GusIzm0kZmld+ke9jz0k NLsRJY3J8SCA9cGFMNyRL04E3RkfHP1wTQfSf1VhAWRtCG30hrmnNOq7v8HtcENrcL2skf raY9uo9R3/Dn2vEU2eZzEigD49wE+nteQRC7gr1uO8IOjAPyrwiSBzv9F3oNhA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.1 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=7b03cfcb24c201a25e92eca854c95dbbca2bc60f commit 7b03cfcb24c201a25e92eca854c95dbbca2bc60f Author: Ed Maste AuthorDate: 2022-03-28 21:03:10 +0000 Commit: Ed Maste CommitDate: 2022-04-05 18:54:04 +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 provided by the Raspberry Pi Pico 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 Pico 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 (cherry picked from commit 868c1b8431f297ade8deba5baf903f73cf5e11c6) (cherry picked from commit 27c2f016b86744aa5d4c6031b4ef2fc16bbf6546) (cherry picked from commit e06ce938ddc0222c6ed10a70108f71685923bd45) Approved by: re (gjb) --- 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 3d86802f6a2e..2e74f769ca97 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 Pico 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) { @@ -57,8 +75,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; }