Commit 87038c2d authored by Karel Zak's avatar Karel Zak Committed by Jens Axboe

partitions: read whole sector with EFI GPT header

The size of EFI GPT header is not static, but whole sector is
allocated for the header. The HeaderSize field must be greater
than 92 (= sizeof(struct gpt_header) and must be less than or
equal to the logical block size.

It means we have to read whole sector with the header, because the
header crc32 checksum is calculated according to HeaderSize.

For more details see UEFI standard (version 2.3, May 2009):
  - 5.3.1 GUID Format overview, page 93
  - Table 13. GUID Partition Table Header, page 96
Signed-off-by: default avatarKarel Zak <kzak@redhat.com>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 7d13af32
...@@ -262,15 +262,16 @@ static gpt_header * ...@@ -262,15 +262,16 @@ static gpt_header *
alloc_read_gpt_header(struct block_device *bdev, u64 lba) alloc_read_gpt_header(struct block_device *bdev, u64 lba)
{ {
gpt_header *gpt; gpt_header *gpt;
unsigned ssz = bdev_logical_block_size(bdev);
if (!bdev) if (!bdev)
return NULL; return NULL;
gpt = kzalloc(sizeof (gpt_header), GFP_KERNEL); gpt = kzalloc(ssz, GFP_KERNEL);
if (!gpt) if (!gpt)
return NULL; return NULL;
if (read_lba(bdev, lba, (u8 *) gpt, if (read_lba(bdev, lba, (u8 *) gpt, ssz) < ssz) {
sizeof (gpt_header)) < sizeof (gpt_header)) {
kfree(gpt); kfree(gpt);
gpt=NULL; gpt=NULL;
return NULL; return NULL;
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#define EFI_PMBR_OSTYPE_EFI 0xEF #define EFI_PMBR_OSTYPE_EFI 0xEF
#define EFI_PMBR_OSTYPE_EFI_GPT 0xEE #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
#define GPT_BLOCK_SIZE 512
#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
#define GPT_HEADER_REVISION_V1 0x00010000 #define GPT_HEADER_REVISION_V1 0x00010000
#define GPT_PRIMARY_PARTITION_TABLE_LBA 1 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1
...@@ -79,7 +78,12 @@ typedef struct _gpt_header { ...@@ -79,7 +78,12 @@ typedef struct _gpt_header {
__le32 num_partition_entries; __le32 num_partition_entries;
__le32 sizeof_partition_entry; __le32 sizeof_partition_entry;
__le32 partition_entry_array_crc32; __le32 partition_entry_array_crc32;
u8 reserved2[GPT_BLOCK_SIZE - 92];
/* The rest of the logical block is reserved by UEFI and must be zero.
* EFI standard handles this by:
*
* uint8_t reserved2[ BlockSize - 92 ];
*/
} __attribute__ ((packed)) gpt_header; } __attribute__ ((packed)) gpt_header;
typedef struct _gpt_entry_attributes { typedef struct _gpt_entry_attributes {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment