disk: part_dos: Allocate at least one block size for mbr
authorFaiz Abbas <faiz_abbas@ti.com>
Wed, 4 Sep 2019 14:40:12 +0000 (20:10 +0530)
committerTom Rini <trini@konsulko.com>
Thu, 19 Sep 2019 16:54:29 +0000 (12:54 -0400)
The blk_dread() following the mbr allocation reads one block from the
device. This will lead to overflow if block size is greater than the
size of legacy_mbr. Fix this by allocating at least one block size.

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Acked-by: Alexey Brodkin <abrodkin@synopsys.com>
disk/part_dos.c

index aae9d9590639edfa774fdab47b7dec9494039295..8ddc13b50c6ea379364ece7b45def29c73d66609 100644 (file)
@@ -93,7 +93,8 @@ static int test_block_type(unsigned char *buffer)
 static int part_test_dos(struct blk_desc *dev_desc)
 {
 #ifndef CONFIG_SPL_BUILD
-       ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, 1);
+       ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr,
+                       DIV_ROUND_UP(dev_desc->blksz, sizeof(legacy_mbr)));
 
        if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1)
                return -1;