[NTOS:FSTUB] Pack the MASTER_BOOT_RECORD structure (#6416)

Otherwise the USHORT members are aligned to 4-byte boundary space
which overflows the disk sector buffer and ultimately results in crash.
This can be reproduced by trying to format the USB drive with Rufus.

Also put some additional C_ASSERT checks for extra safety.
This commit is contained in:
Adam Słaboń 2024-02-07 23:02:19 +01:00 committed by GitHub
parent 7dd3308828
commit 1f28f715ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -41,6 +41,7 @@ typedef struct _EFI_PARTITION_HEADER
ULONG SizeOfPartitionEntry; // 84
ULONG PartitionEntryCRC32; // 88
} EFI_PARTITION_HEADER, *PEFI_PARTITION_HEADER;
C_ASSERT(sizeof(EFI_PARTITION_HEADER) == 92);
#include <poppack.h>
typedef struct _EFI_PARTITION_ENTRY
@ -52,6 +53,7 @@ typedef struct _EFI_PARTITION_ENTRY
ULONGLONG Attributes; // 48
WCHAR Name[0x24]; // 56
} EFI_PARTITION_ENTRY, *PEFI_PARTITION_ENTRY;
C_ASSERT(sizeof(EFI_PARTITION_ENTRY) == 128);
typedef struct _PARTITION_TABLE_ENTRY
{
@ -66,7 +68,9 @@ typedef struct _PARTITION_TABLE_ENTRY
ULONG SectorCountBeforePartition;
ULONG PartitionSectorCount;
} PARTITION_TABLE_ENTRY, *PPARTITION_TABLE_ENTRY;
C_ASSERT(sizeof(PARTITION_TABLE_ENTRY) == 16);
#include <pshpack1.h>
typedef struct _MASTER_BOOT_RECORD
{
UCHAR MasterBootRecordCodeAndData[0x1B8]; // 0
@ -75,6 +79,8 @@ typedef struct _MASTER_BOOT_RECORD
PARTITION_TABLE_ENTRY PartitionTable[4]; // 446
USHORT MasterBootRecordMagic; // 510
} MASTER_BOOT_RECORD, *PMASTER_BOOT_RECORD;
C_ASSERT(sizeof(MASTER_BOOT_RECORD) == 512);
#include <poppack.h>
/* Partition entry size (bytes) - FIXME: It's hardcoded as Microsoft does, but according to specs, it shouldn't be */
#define PARTITION_ENTRY_SIZE 128