Skip to content

Commit 02e2a5b

Browse files
keesaxboe
authored andcommitted
mac: validate mac_partition is within sector
If md->signature == MAC_DRIVER_MAGIC and md->block_size == 1023, a single 512 byte sector would be read (secsize / 512). However the partition structure would be located past the end of the buffer (secsize % 512). Signed-off-by: Kees Cook <keescook@chromium.org> Cc: stable@vger.kernel.org Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 8aeea03 commit 02e2a5b

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

block/partitions/mac.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int mac_partition(struct parsed_partitions *state)
3232
Sector sect;
3333
unsigned char *data;
3434
int slot, blocks_in_map;
35-
unsigned secsize;
35+
unsigned secsize, datasize, partoffset;
3636
#ifdef CONFIG_PPC_PMAC
3737
int found_root = 0;
3838
int found_root_goodness = 0;
@@ -50,10 +50,14 @@ int mac_partition(struct parsed_partitions *state)
5050
}
5151
secsize = be16_to_cpu(md->block_size);
5252
put_dev_sector(sect);
53-
data = read_part_sector(state, secsize/512, &sect);
53+
datasize = round_down(secsize, 512);
54+
data = read_part_sector(state, datasize / 512, &sect);
5455
if (!data)
5556
return -1;
56-
part = (struct mac_partition *) (data + secsize%512);
57+
partoffset = secsize % 512;
58+
if (partoffset + sizeof(*part) > datasize)
59+
return -1;
60+
part = (struct mac_partition *) (data + partoffset);
5761
if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC) {
5862
put_dev_sector(sect);
5963
return 0; /* not a MacOS disk */

0 commit comments

Comments
 (0)