geom label msdosfs: sanity check BPB before using it for io request

It must be greater than zero, and be multiple of the device block size.

In collaboration with:	pho
Reviewed by:	markj, mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33721
This commit is contained in:
Konstantin Belousov 2021-12-30 15:17:59 +02:00
parent 1849bc5f3f
commit 9f4073d446

View File

@ -156,6 +156,12 @@ g_label_msdosfs_taste(struct g_consumer *cp, char *label, size_t size)
G_LABEL_DEBUG(2,
"MSDOSFS: FAT_FirstDataSector=0x%x, FAT_BytesPerSector=%d",
fat_FirstDataSector, fat_BytesPerSector);
if (fat_BytesPerSector == 0 ||
fat_BytesPerSector % pp->sectorsize != 0) {
G_LABEL_DEBUG(1, "MSDOSFS: %s: corrupted BPB",
pp->name);
goto error;
}
for (offset = fat_BytesPerSector * fat_FirstDataSector;;
offset += fat_BytesPerSector) {