From 41fd83773361923f668f54796ff563660b77e96c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 27 Dec 2014 18:43:13 +0100 Subject: block/dmg: validate more offsets and lengths Patch "block/dmg: validate chunk size to avoid overflow" is not enough to catch boundary issues as "info_length" was unchecked. This patch ensures that the read boundaries are valid. Signed-off-by: Peter Wu --- block/dmg.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/block/dmg.c b/block/dmg.c index b84ba7e690..dd8551cf27 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -450,6 +450,10 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (ds.data_fork_offset > offset) { + ret = -EINVAL; + goto fail; + } /* offset of resource fork (RsrcForkOffset) */ ret = read_uint64(bs, offset + 0x28, &rsrc_fork_offset); @@ -460,6 +464,11 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (rsrc_fork_offset >= offset || + rsrc_fork_length > offset - rsrc_fork_offset) { + ret = -EINVAL; + goto fail; + } /* offset of property list (XMLOffset) */ ret = read_uint64(bs, offset + 0xd8, &plist_xml_offset); if (ret < 0) { @@ -469,6 +478,11 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (plist_xml_offset >= offset || + plist_xml_length > offset - plist_xml_offset) { + ret = -EINVAL; + goto fail; + } ret = read_uint64(bs, offset + 0x1ec, (uint64_t *)&bs->total_sectors); if (ret < 0) { goto fail; -- cgit v1.2.1