Skip to contentSkip to conversation

disk: part_efi: fix check of the max partition size

PATCH New Patrick Delaunay 2 participants 2 messages May 2, 2016 – May 30, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 disk: part_efi: fix check of the max partition size

the last value acceptable value for offset is last_usable_lba + 1 and not last_usable_lba - 1

issue found with SDCARD partition commands on u-boot 2015.10 but this part of code don't change

1- create GPT partion on all the card

Quoted 2 lines

gpt write mmc 0 name=test,start=0,size=0
part list mmc 0

Partition Map for MMC device 0 -- Partition Type: EFI

Part Start LBA End LBA Name
Attributes
Type GUID
Partition GUID
1 0x00000022 0x003a9fde "test"

            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     b710eb04-45b9-e94a-8d0b-21458d596f54

=> Start = 0x22*512 = 0x4400
=> Size = (0x003a9fde-0x22+1) * 512 = 0x753F7A00

2- try to recreate the same partition with the next command
(block size:512 bytes = 0x200)

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7A00

Writing GPT: Partitions layout exceds disk size

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7800

Writing GPT: Partitions layout exceds disk size

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7600

Writing GPT: success!

Partition Map for MMC device 0 -- Partition Type: EFI

Part Start LBA End LBA Name
Attributes
Type GUID
Partition GUID
1 0x00000022 0x003a9fdc "test"

            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     36ec30ef-7ca4-cd48-97cd-ea9fb95185d0

the max LBA when the size is indicated (0x003a9fdc) is lower than when u-boot compute the max allowed value with size=0 (0x003a9fde)

in the code :

     /* partition ending lba */
     if ((i == parts - 1) && (partitions[i].size == 0))
		/* extend the last partition to maximuim */
		gpt_e[i].ending_lba = gpt_h->last_usable_lba;
     else
		gpt_e[i].ending_lba = cpu_to_le64(offset - 1);

so offset = gpt_h->last_usable_lba + 1 is acceptable ! but the test (offset >= last_usable_lba) cause the error

END

the last value acceptable value for offset is (last_usable_lba + 1) and not (last_usable_lba - 1)

issue found with SDCARD partition commands on u-boot 2015.10 but this part of code don't change

1- I create GPT partion on all the card (start and size undefined)

Quoted 2 lines

gpt write mmc 0 name=test,start=0,size=0
part list mmc 0

Partition Map for MMC device 0 -- Partition Type: EFI

Part Start LBA End LBA Name
Attributes
Type GUID
Partition GUID
1 0x00000022 0x003a9fde "test"

            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     b710eb04-45b9-e94a-8d0b-21458d596f54

=> Start = 0x22*512 = 0x4400
=> Size = (0x003a9fde-0x22+1) * 512 = 0x753F7A00

2- I try to recreate the same partition with the command gpt write
and with start and size values (block size:512 bytes = 0x200)

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7A00

Writing GPT: Partitions layout exceds disk size

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7800

Writing GPT: Partitions layout exceds disk size

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7600

Writing GPT: success!

I check the partition created :

Quoted 1 line

part list mmc 0

Partition Map for MMC device 0 -- Partition Type: EFI

Part Start LBA End LBA Name
Attributes
Type GUID
Partition GUID
1 0x00000022 0x003a9fdc "test"

            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     36ec30ef-7ca4-cd48-97cd-ea9fb95185d0

=> but the max LBA when the size is indicated (0x003a9fdc) is lower than
when u-boot compute the max allowed value with size=0 (0x003a9fde)

3- in the code, just after my patch, line 446

     /* partition ending lba */
     if ((i == parts - 1) && (partitions[i].size == 0))
		/* extend the last partition to maximuim */
		gpt_e[i].ending_lba = gpt_h->last_usable_lba;
     else
		gpt_e[i].ending_lba = cpu_to_le64(offset - 1);

so offset = gpt_h->last_usable_lba + 1 is acceptable ! (it the value used when size is 0)

but today the test (offset >= last_usable_lba) cause the error my patch only solve this issue

END

---

 disk/part_efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
disk/part_efi.c +1 -1
index fe308d7..0af1e92 100644
@@ -439,7 +439,7 @@ int gpt_fill_pte(gpt_header *gpt_h, gpt_entry *gpt_e,
 			gpt_e[i].starting_lba = cpu_to_le64(offset);
 			offset += partitions[i].size;
 		}
-		if (offset >= last_usable_lba) {
+		if (offset > (last_usable_lba + 1)) {
 			printf("Partitions layout exceds disk size\n");
 			return -1;
 		}
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 disk: part_efi: fix check of the max partition size

Quoted 138 lines · Patrick Delaunay

the last value acceptable value for offset is last_usable_lba + 1 and not last_usable_lba - 1

issue found with SDCARD partition commands on u-boot 2015.10 but this part of code don't change

1- create GPT partion on all the card

Quoted 2 lines

gpt write mmc 0 name=test,start=0,size=0
part list mmc 0

Partition Map for MMC device 0 -- Partition Type: EFI

Part Start LBA End LBA Name
Attributes
Type GUID
Partition GUID
1 0x00000022 0x003a9fde "test"

            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     b710eb04-45b9-e94a-8d0b-21458d596f54

=> Start = 0x22*512 = 0x4400
=> Size = (0x003a9fde-0x22+1) * 512 = 0x753F7A00

2- try to recreate the same partition with the next command
(block size:512 bytes = 0x200)

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7A00

Writing GPT: Partitions layout exceds disk size

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7800

Writing GPT: Partitions layout exceds disk size

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7600

Writing GPT: success!

Partition Map for MMC device 0 -- Partition Type: EFI

Part Start LBA End LBA Name
Attributes
Type GUID
Partition GUID
1 0x00000022 0x003a9fdc "test"

            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     36ec30ef-7ca4-cd48-97cd-ea9fb95185d0

the max LBA when the size is indicated (0x003a9fdc) is lower than when u-boot compute the max allowed value with size=0 (0x003a9fde)

in the code :

     /* partition ending lba */
     if ((i == parts - 1) && (partitions[i].size == 0))
		/* extend the last partition to maximuim */
		gpt_e[i].ending_lba = gpt_h->last_usable_lba;
     else
		gpt_e[i].ending_lba = cpu_to_le64(offset - 1);

so offset = gpt_h->last_usable_lba + 1 is acceptable ! but the test (offset >= last_usable_lba) cause the error

END

the last value acceptable value for offset is (last_usable_lba + 1) and not (last_usable_lba - 1)

issue found with SDCARD partition commands on u-boot 2015.10 but this part of code don't change

1- I create GPT partion on all the card (start and size undefined)

Quoted 2 lines

gpt write mmc 0 name=test,start=0,size=0
part list mmc 0

Partition Map for MMC device 0 -- Partition Type: EFI

Part Start LBA End LBA Name
Attributes
Type GUID
Partition GUID
1 0x00000022 0x003a9fde "test"

            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     b710eb04-45b9-e94a-8d0b-21458d596f54

=> Start = 0x22*512 = 0x4400
=> Size = (0x003a9fde-0x22+1) * 512 = 0x753F7A00

2- I try to recreate the same partition with the command gpt write
and with start and size values (block size:512 bytes = 0x200)

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7A00

Writing GPT: Partitions layout exceds disk size

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7800

Writing GPT: Partitions layout exceds disk size

Quoted 1 line

gpt write mmc 0 name=test,start=0x4400,size=0x753F7600

Writing GPT: success!

I check the partition created :

Quoted 1 line

part list mmc 0

Partition Map for MMC device 0 -- Partition Type: EFI

Part Start LBA End LBA Name
Attributes
Type GUID
Partition GUID
1 0x00000022 0x003a9fdc "test"

            attrs:     0x0000000000000000
            type:     ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
            type:     data
            guid:     36ec30ef-7ca4-cd48-97cd-ea9fb95185d0

=> but the max LBA when the size is indicated (0x003a9fdc) is lower than
when u-boot compute the max allowed value with size=0 (0x003a9fde)

3- in the code, just after my patch, line 446

     /* partition ending lba */
     if ((i == parts - 1) && (partitions[i].size == 0))
		/* extend the last partition to maximuim */
		gpt_e[i].ending_lba = gpt_h->last_usable_lba;
     else
		gpt_e[i].ending_lba = cpu_to_le64(offset - 1);

so offset = gpt_h->last_usable_lba + 1 is acceptable ! (it the value used when size is 0)

Quoted 6 lines

but today the test (offset >= last_usable_lba) cause the error my patch only solve this issue

END

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160530/08ff5e8d/attachment.sig>