From nobody Fri Apr 01 00:42:44 2022 X-Original-To: dev-commits-src-branches@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 B31301A516F2; Fri, 1 Apr 2022 00:42:44 +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 4KV1bm4gHNz3mjT; Fri, 1 Apr 2022 00:42:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648773764; 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=fj228uNONskfRxaAWQX11Iy6fwzrm5aFyeWbc9Z4zcw=; b=vgUwIi0z0VVYr3TswgNQG6norHd6873b9x7k3QLDa7sS6kEIYFqZDjkr+/7se+gnQvYhm6 7JcZz4NQPOn3X+chnD5jFKfje2ETq9m2OWThkhV37a28mhYSpDM5Bbt/wpyELChDLNqwg9 kKrcO28OeIUOgMEH0atbUZuVtZyL29m1/a9H2jGRNzc6eN/vRaUZP1RzTxkTzHRLTEyqnS C5UHzgkDRn7TNkTjFEAkVjUmFFwsrsJEfyrozzfhkdCVVS2r1hA0l0NnMYw1e+TtwJGrvd gEjq+sY9gkDrgxS01CKmhcd4x6epY/EPOPIS140jBcBn4umn5hFvs+IlNWBJnw== 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 803EF229C; Fri, 1 Apr 2022 00:42:44 +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 2310gi4W099255; Fri, 1 Apr 2022 00:42:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2310gi7b099254; Fri, 1 Apr 2022 00:42:44 GMT (envelope-from git) Date: Fri, 1 Apr 2022 00:42:44 GMT Message-Id: <202204010042.2310gi7b099254@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: 1318b1ee9c4e - stable/12 - fstyp: detect Raspberry Pi Pico boot filesystem as FAT List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/12 X-Git-Reftype: branch X-Git-Commit: 1318b1ee9c4ee9ef6c1be600adc252a713b93961 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648773764; 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=fj228uNONskfRxaAWQX11Iy6fwzrm5aFyeWbc9Z4zcw=; b=MtetygdXZrHctzE+UHgB+j/hYGeXqidOXoLjf3i1UYg70hAJbRrxjzg4t5lY7tynBIJHTx +1I6RMEHR7pas3+Bc5YvV/cSgurEyEi+bH6MidbXFaHZBm12Y/ZrLOpG4nqHbl8JErKLRC m5kt/ibOannPJYB6enjU9L2sAhD9uutHQaBrzMpTFM/4grZ63PLhJDnIngxk5v04QZ3gPz ElpBoCYX5CR3KQfbbXqxajC33LnglZShRLixLf67H2ZQ7t0GSR7PXrQPke/UNm+QY8C7Ko 9xIwsulvWKfv44ppiMZFSsxxxCtXI0AJWDOf2x2PGikY8jEZq9509wIpQxX2Yg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648773764; a=rsa-sha256; cv=none; b=nPuFzbNN9qypT3QU+SkyOQKV+F3yERQuXbfkK1f/d3b9MqHgR+waBhXlYgV0qzjlmI+Wo2 Oq4hrUgQNfs+S+fh0wgs9HLwb+iqy0mE65Faf1VCClE3yDFRZNoOJWvrCOk5xJhUB/pFht xcIlEqAK6yoB/uQhelbcnJfPd4uqe73PdLdJIyz9chEJth2wGii4u26VSTNb5+J6iIo4yE Me8lB1rOfLQvr7gOlr2J6dA/Wdf1u8NaMRhwanGCCPtmM4B/s+BlXJCAPGUKFAj3+ycKCN 4f+FcQCqh8YetaB0jZ9DxSw20DxhccRDhgyww/iY7Iw3RrkeozXZgTVqpc8hsA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=1318b1ee9c4ee9ef6c1be600adc252a713b93961 commit 1318b1ee9c4ee9ef6c1be600adc252a713b93961 Author: Ed Maste AuthorDate: 2022-03-28 21:03:10 +0000 Commit: Ed Maste CommitDate: 2022-03-31 21:00:47 +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 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) --- 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; }