]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
disk: Extend disk_blk_part_validate() with range checking
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Sun, 13 Aug 2023 23:46:45 +0000 (01:46 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 22 Aug 2023 19:17:52 +0000 (15:17 -0400)
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>
disk/disk-uclass.c

index 32722cf91760c41c5ceacb7089c179126efb4f1c..f262105375b6ad4dd68c6d59b05306f203e508bf 100644 (file)
  */
 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;
 }