aboutsummaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
authorMarek Vasut <marek.vasut+renesas@mailbox.org>2023-08-14 01:46:45 +0200
committerTom Rini <trini@konsulko.com>2023-08-22 15:17:52 -0400
commitbfd98b9a634e5922ca60597f59d83afdaa7c99ad (patch)
tree946b1effd7e17939421e44eece60642e5fc53c23 /disk
parent2bc0dfef9f27c03f24784f4f2382079caff05df1 (diff)
downloadu-boot-bfd98b9a634e5922ca60597f59d83afdaa7c99ad.zip
u-boot-bfd98b9a634e5922ca60597f59d83afdaa7c99ad.tar.gz
u-boot-bfd98b9a634e5922ca60597f59d83afdaa7c99ad.tar.bz2
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 <marek.vasut+renesas@mailbox.org>
Diffstat (limited to 'disk')
-rw-r--r--disk/disk-uclass.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c
index 32722cf..f262105 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;
}