summaryrefslogtreecommitdiff
path: root/fs/btrfs
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo.btrfs@gmx.com>2017-08-23 10:57:57 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-12-05 21:41:11 +0300
commitac6ea50bb6306ed056222a5967b2bad3c3a9e2dd (patch)
tree3c70c8971f4541d698a22e9958ac04d66f522462 /fs/btrfs
parenta5cc85fe139c181e53cc557230c5ea4001a90c80 (diff)
downloadlinux-ac6ea50bb6306ed056222a5967b2bad3c3a9e2dd.tar.xz
btrfs: Check if item pointer overlaps with the item itself
commit 7f43d4affb2a254d421ab20b0cf65ac2569909fb upstream. Function check_leaf() checks if any item pointer points outside of the leaf, but it doesn't check if the pointer overlaps with the item itself. Normally only the last item may be the victim, but adding such check is never a bad idea anyway. Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/disk-io.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 4a1e63df1183..da7b2039e4cb 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -644,6 +644,13 @@ static noinline int check_leaf(struct btrfs_root *root,
return -EUCLEAN;
}
+ /* Also check if the item pointer overlaps with btrfs item. */
+ if (btrfs_item_nr_offset(slot) + sizeof(struct btrfs_item) >
+ btrfs_item_ptr_offset(leaf, slot)) {
+ CORRUPT("slot overlap with its data", leaf, root, slot);
+ return -EUCLEAN;
+ }
+
prev_key.objectid = key.objectid;
prev_key.type = key.type;
prev_key.offset = key.offset;