FatPkg: Check BlockIo Device Has Supported BlockSize

Per the FAT spec, FAT32 supports block sizes of 512B, 1KB, 2KB, or 4KB.
This patch adds a check to the FAT driver initialization to ensure that
the underlying BlockIo device supports one of those block sizes and fails
initialization otherwise. The underlying BlockIo blocksize is used when
we flush the FatDiskCache back to disk and if the block size is an
unsupported size, we could cause file corruption.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
This commit is contained in:
Oliver Smith-Denny 2024-08-05 14:54:27 -07:00 committed by mergify[bot]
parent 4c3bffaeb3
commit 3ef6a71ed1

View File

@ -61,6 +61,30 @@ FatAllocateVolume (
// //
Volume->RootDirEnt.FileString = Volume->RootFileString; Volume->RootDirEnt.FileString = Volume->RootFileString;
Volume->RootDirEnt.Entry.Attributes = FAT_ATTRIBUTE_DIRECTORY; Volume->RootDirEnt.Entry.Attributes = FAT_ATTRIBUTE_DIRECTORY;
//
// Check to see if the underlying block device's BlockSize meets what the FAT spec requires
//
if ((BlockIo == NULL) || (BlockIo->Media == NULL)) {
DEBUG ((DEBUG_ERROR, "%a BlockIo or BlockIo is NULL!\n", __func__));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if ((BlockIo->Media->BlockSize > (1 << MAX_BLOCK_ALIGNMENT)) ||
(BlockIo->Media->BlockSize < (1 << MIN_BLOCK_ALIGNMENT)))
{
Status = EFI_UNSUPPORTED;
DEBUG ((
DEBUG_ERROR,
"%a invalid BlockIo BlockSize %u for FAT filesystem on MediaId %u. Min 512b, max 4kb\n",
__func__,
BlockIo->Media->BlockSize,
BlockIo->Media->MediaId
));
goto Done;
}
// //
// Check to see if there's a file system on the volume // Check to see if there's a file system on the volume
// //