From 6cca2ea9bea9137fba30b48242868e3d757906dc Mon Sep 17 00:00:00 2001 From: David Sterba Date: Fri, 30 Sep 2016 16:19:20 +0200 Subject: btrfs-progs: more sanity checks in read_tree_block_fs_info If blocksize is 0, it passes the IS_ALIGNED check but fails later as the length of ebs will be zero. Reported-by: Lukas Lueg Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=169311 Signed-off-by: David Sterba --- disk-io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'disk-io.c') diff --git a/disk-io.c b/disk-io.c index 29d22fb1..bfc2879c 100644 --- a/disk-io.c +++ b/disk-io.c @@ -326,16 +326,17 @@ struct extent_buffer* read_tree_block_fs_info( * Such unaligned tree block will free overlapping extent buffer, * causing use-after-free bugs for fuzzed images. */ - if (!IS_ALIGNED(bytenr, sectorsize)) { + if (bytenr < sectorsize || !IS_ALIGNED(bytenr, sectorsize)) { error("tree block bytenr %llu is not aligned to sectorsize %u", bytenr, sectorsize); return ERR_PTR(-EIO); } - if (!IS_ALIGNED(blocksize, nodesize)) { + if (blocksize < nodesize || !IS_ALIGNED(blocksize, nodesize)) { error("tree block size %u is not aligned to nodesize %u", blocksize, nodesize); return ERR_PTR(-EIO); } + eb = btrfs_find_create_tree_block(fs_info, bytenr, blocksize); if (!eb) return ERR_PTR(-ENOMEM); -- cgit v1.2.3