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
This commit is contained in:
Ed Maste 2022-03-28 17:03:10 -04:00
parent e7e65008ff
commit 868c1b8431

View File

@ -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;
}