From: Qu Wenruo Date: Wed, 23 Aug 2017 07:57:57 +0000 (+0900) Subject: btrfs: Check if item pointer overlaps with the item itself X-Git-Tag: v4.4.171~35 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dc7a1fbccd957904f7a0a9f665c38b6431f30b60;p=profile%2Fcommon%2Fplatform%2Fkernel%2Flinux-artik7.git 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 Reviewed-by: Nikolay Borisov Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d513650..d2725a8 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -621,6 +621,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;