mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] partitions: efi: fix GPT header size exceeding allocation size
@ 2024-10-22 16:27 Abdelrahman Youssef
  2024-10-22 17:06 ` Ahmad Fatoum
  2024-10-23 12:43 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Abdelrahman Youssef @ 2024-10-22 16:27 UTC (permalink / raw)
  To: s.hauer; +Cc: barebox, Abdelrahman Youssef

The buffer gets allocated with the block device of size SECTOR_SIZE, but an
ill-formed GPT header_size may exceed it resulting in heap-overflow.

Signed-off-by: Abdelrahman Youssef <abdelrahmanyossef12@gmail.com>
---
 common/partitions/efi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 829360da6e..9a04b7014d 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -173,6 +173,9 @@ static int is_gpt_valid(struct block_device *blk, u64 lba,
 		goto fail;
 	}
 
+	if (le32_to_cpu((*gpt)->header_size) > bdev_logical_block_size(blk))
+		goto fail;
+
 	/* Check the GUID Partition Table CRC */
 	origcrc = le32_to_cpu((*gpt)->header_crc32);
 	(*gpt)->header_crc32 = 0;
-- 
2.43.0




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] partitions: efi: fix GPT header size exceeding allocation size
  2024-10-22 16:27 [PATCH] partitions: efi: fix GPT header size exceeding allocation size Abdelrahman Youssef
@ 2024-10-22 17:06 ` Ahmad Fatoum
  2024-10-23 12:43 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-10-22 17:06 UTC (permalink / raw)
  To: Abdelrahman Youssef, s.hauer; +Cc: barebox

Hello Abdelrahman,

Thanks for your patch.

On 22.10.24 18:27, Abdelrahman Youssef wrote:
> The buffer gets allocated with the block device of size SECTOR_SIZE, but an

I guess you meant to say here "with the length of the block device's sector size".

> ill-formed GPT header_size may exceed it resulting in heap-overflow.

Nice catch. Been there since nearly 10 years too:

Fixes: 760689e5ccf1 ("disk: partitions: add EFI GUID Partition Table")

> Signed-off-by: Abdelrahman Youssef <abdelrahmanyossef12@gmail.com>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

Cheers,
Ahmad

> ---
>  common/partitions/efi.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/common/partitions/efi.c b/common/partitions/efi.c
> index 829360da6e..9a04b7014d 100644
> --- a/common/partitions/efi.c
> +++ b/common/partitions/efi.c
> @@ -173,6 +173,9 @@ static int is_gpt_valid(struct block_device *blk, u64 lba,
>  		goto fail;
>  	}
>  
> +	if (le32_to_cpu((*gpt)->header_size) > bdev_logical_block_size(blk))
> +		goto fail;
> +
>  	/* Check the GUID Partition Table CRC */
>  	origcrc = le32_to_cpu((*gpt)->header_crc32);
>  	(*gpt)->header_crc32 = 0;


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] partitions: efi: fix GPT header size exceeding allocation size
  2024-10-22 16:27 [PATCH] partitions: efi: fix GPT header size exceeding allocation size Abdelrahman Youssef
  2024-10-22 17:06 ` Ahmad Fatoum
@ 2024-10-23 12:43 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-10-23 12:43 UTC (permalink / raw)
  To: Abdelrahman Youssef; +Cc: barebox


On Tue, 22 Oct 2024 19:27:26 +0300, Abdelrahman Youssef wrote:
> The buffer gets allocated with the block device of size SECTOR_SIZE, but an
> ill-formed GPT header_size may exceed it resulting in heap-overflow.
> 
> 

Applied, thanks!

[1/1] partitions: efi: fix GPT header size exceeding allocation size
      https://git.pengutronix.de/cgit/barebox/commit/?id=a9c6ad764144 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-23 12:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-22 16:27 [PATCH] partitions: efi: fix GPT header size exceeding allocation size Abdelrahman Youssef
2024-10-22 17:06 ` Ahmad Fatoum
2024-10-23 12:43 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox