summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2015-11-19 17:18:54 -0800
committerBen Hutchings <ben@decadent.org.uk>2015-12-30 02:25:56 +0000
commit81a319c5c29913a23947f3d28513974682f3af03 (patch)
treebfe8b4928304513b7c3a320442a70a4a81cf8b06 /fs
parent645fd470312a5327fbe39d7343af390330d5003c (diff)
downloadlinux-81a319c5c29913a23947f3d28513974682f3af03.tar.gz
linux-81a319c5c29913a23947f3d28513974682f3af03.tar.bz2
linux-81a319c5c29913a23947f3d28513974682f3af03.zip
mac: validate mac_partition is within sector
commit 02e2a5bfebe99edcf9d694575a75032d53fe1b73 upstream. 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> Signed-off-by: Jens Axboe <axboe@fb.com> [bwh: Backported to 3.2: adjust filename] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'fs')
-rw-r--r--fs/partitions/mac.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/fs/partitions/mac.c b/fs/partitions/mac.c
index 11f688bd76c5..f51c9305d1e1 100644
--- a/fs/partitions/mac.c
+++ b/fs/partitions/mac.c
@@ -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, &sect);
+ datasize = round_down(secsize, 512);
+ data = read_part_sector(state, datasize / 512, &sect);
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 */