[PATCH 5/8] disk: Extend disk_blk_part_validate() with range checking

Marek Vasut marek.vasut+renesas at mailbox.org
Mon Aug 14 01:46:45 CEST 2023


Check whether access is out of bounds of the partition and
return an error. This way there is no danger of esp. write
or erase outside of the confines of partition.

Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
Cc: AKASHI Takahiro <takahiro.akashi at linaro.org>
Cc: Abdellatif El Khlifi <abdellatif.elkhlifi at arm.com>
Cc: Bin Meng <bmeng.cn at gmail.com>
Cc: Heinrich Schuchardt <xypron.glplk at gmx.de>
Cc: Joshua Watt <jpewhacker at gmail.com>
Cc: Michal Suchanek <msuchanek at suse.de>
Cc: Simon Glass <sjg at chromium.org>
Cc: Tobias Waldekranz <tobias at waldekranz.com>
---
 disk/disk-uclass.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 32722cf9176..f262105375b 100644
--- a/disk/disk-uclass.c
+++ b/disk/disk-uclass.c
@@ -27,9 +27,17 @@
  */
 static int disk_blk_part_validate(struct udevice *dev, lbaint_t start, lbaint_t blkcnt)
 {
+	struct disk_part *part = dev_get_uclass_plat(dev);
+
 	if (device_get_uclass_id(dev) != UCLASS_PARTITION)
 		return -ENOSYS;
 
+	if (start >= part->gpt_part_info.size)
+		return -E2BIG;
+
+	if ((start + blkcnt) > part->gpt_part_info.size)
+		return -ERANGE;
+
 	return 0;
 }
 
-- 
2.40.1



More information about the U-Boot mailing list