From: Marek Vasut Date: Sun, 13 Aug 2023 23:46:45 +0000 (+0200) Subject: disk: Extend disk_blk_part_validate() with range checking X-Git-Url: http://git.dujemihanovic.xyz/html/index.html?a=commitdiff_plain;h=bfd98b9a634e5922ca60597f59d83afdaa7c99ad;p=u-boot.git disk: Extend disk_blk_part_validate() with range checking 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 --- diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 32722cf917..f262105375 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; }