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