diff options
author | Oliver Smith-Denny <osde@linux.microsoft.com> | 2024-08-05 14:54:27 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-09-23 16:50:39 +0000 |
commit | 3ef6a71ed186d1e8e44c26c24a1cbea5533e3554 (patch) | |
tree | a507b80ad9ea13718fe464b6aaf62d683ed0bd6d /FatPkg/EnhancedFatDxe | |
parent | 4c3bffaeb3cff662686e33c506802132147c4fbf (diff) | |
download | edk2-3ef6a71ed186d1e8e44c26c24a1cbea5533e3554.tar.gz edk2-3ef6a71ed186d1e8e44c26c24a1cbea5533e3554.tar.bz2 edk2-3ef6a71ed186d1e8e44c26c24a1cbea5533e3554.zip |
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>
Diffstat (limited to 'FatPkg/EnhancedFatDxe')
-rw-r--r-- | FatPkg/EnhancedFatDxe/Init.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/FatPkg/EnhancedFatDxe/Init.c b/FatPkg/EnhancedFatDxe/Init.c index 3a946199e7..8563b950a4 100644 --- a/FatPkg/EnhancedFatDxe/Init.c +++ b/FatPkg/EnhancedFatDxe/Init.c @@ -61,6 +61,30 @@ FatAllocateVolume ( //
Volume->RootDirEnt.FileString = Volume->RootFileString;
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
//
|