fs/partitions: Validate map_count in Mac partition tables

Validate number of blocks in map and remove redundant variable.

Signed-off-by: Timo Warns <warns@pre-sense.de>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Timo Warns and committed by Linus Torvalds fa7ea87a ee715087

+9 -8
+9 -8
fs/partitions/mac.c
··· 29 29 30 30 int mac_partition(struct parsed_partitions *state) 31 31 { 32 - int slot = 1; 33 32 Sector sect; 34 33 unsigned char *data; 35 - int blk, blocks_in_map; 34 + int slot, blocks_in_map; 36 35 unsigned secsize; 37 36 #ifdef CONFIG_PPC_PMAC 38 37 int found_root = 0; ··· 58 59 put_dev_sector(sect); 59 60 return 0; /* not a MacOS disk */ 60 61 } 61 - strlcat(state->pp_buf, " [mac]", PAGE_SIZE); 62 62 blocks_in_map = be32_to_cpu(part->map_count); 63 - for (blk = 1; blk <= blocks_in_map; ++blk) { 64 - int pos = blk * secsize; 63 + if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) { 64 + put_dev_sector(sect); 65 + return 0; 66 + } 67 + strlcat(state->pp_buf, " [mac]", PAGE_SIZE); 68 + for (slot = 1; slot <= blocks_in_map; ++slot) { 69 + int pos = slot * secsize; 65 70 put_dev_sector(sect); 66 71 data = read_part_sector(state, pos/512, &sect); 67 72 if (!data) ··· 116 113 } 117 114 118 115 if (goodness > found_root_goodness) { 119 - found_root = blk; 116 + found_root = slot; 120 117 found_root_goodness = goodness; 121 118 } 122 119 } 123 120 #endif /* CONFIG_PPC_PMAC */ 124 - 125 - ++slot; 126 121 } 127 122 #ifdef CONFIG_PPC_PMAC 128 123 if (found_root_goodness)