Re: [PATCH 2/6] disk: part_efi: Add missing endianness conversions

Heinrich Schuchardt <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <[email protected]>
On 7/31/26 14:40, Alexey Charkov wrote:
> Several GPT header fields are read without converting from
> little-endian, which is wrong on big-endian hosts.
> 
> gpt_fill_pte() takes my_lba and partition_entry_lba raw when working out
> the region a partition must not overlap, so on a big-endian host both
> bounds are byte-swapped garbage and the overlap check does not do
> anything useful.
> 
> gpt_verify_partitions() compares the loop counter against
> num_partition_entries raw, so its "More partitions than allowed!" guard
> never triggers.
> 
> It also swaps gpt_part_size, which is already in host order, having been
> computed from two le64_to_cpu() results a few lines above. Drop the
> conversion rather than adding one.
> 
> All of this is a no-op on little-endian targets.
> 
> Signed-off-by: Alexey Charkov <[email protected]>

This change is not covered by the test in patch 6/6 as it runs only on 
the sandbox.

Please, ensure that the GPT tests are also executed on a big-endian 
systems, e.g malta64_defconfig which run in the CI via QEMU.

Reviewed-by: Heinrich Schuchardt <[email protected]>

> ---
>   disk/part_efi.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/disk/part_efi.c b/disk/part_efi.c
> index af311867a285..062389c3af0c 100644
> --- a/disk/part_efi.c
> +++ b/disk/part_efi.c
> @@ -462,10 +462,10 @@ int gpt_fill_pte(struct blk_desc *desc,
>   	char *str_type_guid;
>   	unsigned char *bin_type_guid;
>   #endif
> -	size_t hdr_start = gpt_h->my_lba;
> +	size_t hdr_start = le64_to_cpu(gpt_h->my_lba);
>   	size_t hdr_end = hdr_start + 1;
>   
> -	size_t pte_start = gpt_h->partition_entry_lba;
> +	size_t pte_start = le64_to_cpu(gpt_h->partition_entry_lba);
>   	size_t pte_end = pte_start + gpt_pte_blocks(desc, gpt_h);
>   
>   	for (i = 0; i < parts; i++) {
> @@ -851,7 +851,7 @@ int gpt_verify_partitions(struct blk_desc *desc,
>   	gpt_e = *gpt_pte;
>   
>   	for (i = 0; i < parts; i++) {
> -		if (i == gpt_head->num_partition_entries) {
> +		if (i == le32_to_cpu(gpt_head->num_partition_entries)) {
>   			pr_err("More partitions than allowed!\n");
>   			return -1;
>   		}
> @@ -877,7 +877,7 @@ int gpt_verify_partitions(struct blk_desc *desc,
>   		      (unsigned long long)gpt_part_size,
>   		      (unsigned long long)partitions[i].size);
>   
> -		if (le64_to_cpu(gpt_part_size) != partitions[i].size) {
> +		if (gpt_part_size != partitions[i].size) {
>   			/* We do not check the extend partition size */
>   			if ((i == parts - 1) && (partitions[i].size == 0))
>   				continue;
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.