]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: Check if item pointer overlaps with the item itself
authorQu Wenruo <quwenruo.btrfs@gmx.com>
Wed, 23 Aug 2017 07:57:57 +0000 (16:57 +0900)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 28 Apr 2020 18:02:29 +0000 (19:02 +0100)
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/btrfs/disk-io.c

index 80a3550be7b6332018312a6c9b3729b52d9ca272..3d90ed7095be71053dfe526154f8789df1b725eb 100644 (file)
@@ -606,6 +606,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;