mac: validate mac_partition is within sector
PATCH RESEND 1/1 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 <[email protected]>
---
There doesn't seem to be a mac partition maintainer...
--- block/partitions/mac.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
block/partitions/mac.c +7 -3
@@ -32,7 +32,7 @@ int mac_partition(struct parsed_partitions *state)Sector sect;unsigned char *data;int slot, blocks_in_map; -unsigned secsize; +unsigned secsize, datasize, partoffset;#ifdef CONFIG_PPC_PMAC int found_root =0 ;int found_root_goodness =0 ;
@@ -50,10 +50,14 @@ int mac_partition(struct parsed_partitions *state) } secsize =be16_to_cpu (md->block_size);put_dev_sector (sect); - data =read_part_sector (state, secsize/512 , §); + datasize =round_down (secsize,512 ); + data =read_part_sector (state, datasize /512 , §);if (!data)return -1 ; - part = (struct mac_partition *) (data + secsize%512 ); + partoffset = secsize %512 ; +if (partoffset +sizeof (*part) > datasize) +return -1 ; + part = (struct mac_partition *) (data + partoffset);if (be16_to_cpu (part->signature) !=MAC_PARTITION_MAGIC ) {put_dev_sector (sect);return 0 ;/* not a MacOS disk */
Signature · 6 lines
1.9.1 -- Kees Cook Chrome OS Security
Quoted 3 lines · Kees Cook
If
md->signature==MAC_DRIVER_MAGICandmd->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).
Do we even want to support non-power-of-two block sizes?
-Jeff
Quoted 41 lines
Signed-off-by Kees Cook <[email protected]>---
There doesn't seem to be a mac partition maintainer...--- block/partitions/mac.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)block/partitions/mac.c +7
-3@@ -32,7 +32,7 @@ int mac_partition(struct parsed_partitions *state)Sector sect;unsigned char *data;int slot, blocks_in_map; -unsigned secsize; +unsigned secsize, datasize, partoffset;#ifdef CONFIG_PPC_PMAC int found_root =0 ;int found_root_goodness =0 ;@@ -50,10 +50,14 @@ int mac_partition(struct parsed_partitions *state) } secsize =be16_to_cpu (md->block_size);put_dev_sector (sect); - data =read_part_sector (state, secsize/512 , §); + datasize =round_down (secsize,512 ); + data =read_part_sector (state, datasize /512 , §);if (!data)return -1 ; - part = (struct mac_partition *) (data + secsize%512 ); + partoffset = secsize %512 ; +if (partoffset +sizeof (*part) > datasize) +return -1 ; + part = (struct mac_partition *) (data + partoffset);if (be16_to_cpu (part->signature) !=MAC_PARTITION_MAGIC ) {put_dev_sector (sect);return 0 ;/* not a MacOS disk */ Signature · 1 line
1.9.1