]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: tree-checker: fix the incorrect inode ref size check
authorQu Wenruo <wqu@suse.com>
Mon, 15 Sep 2025 22:24:06 +0000 (07:54 +0930)
committerDavid Sterba <dsterba@suse.com>
Thu, 18 Sep 2025 03:47:25 +0000 (05:47 +0200)
[BUG]
Inside check_inode_ref(), we need to make sure every structure,
including the btrfs_inode_extref header, is covered by the item.  But
our code is incorrectly using "sizeof(iref)", where @iref is just a
pointer.

This means "sizeof(iref)" will always be "sizeof(void *)", which is much
smaller than "sizeof(struct btrfs_inode_extref)".

This will allow some bad inode extrefs to sneak in, defeating tree-checker.

[FIX]
Fix the typo by calling "sizeof(*iref)", which is the same as
"sizeof(struct btrfs_inode_extref)", and will be the correct behavior we
want.

Fixes: 71bf92a9b877 ("btrfs: tree-checker: Add check for INODE_REF")
CC: stable@vger.kernel.org # 6.1+
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-checker.c

index 0f556f4de3f924bfe41615e4f3a32ad0789a4a34..a997c7cc35a26fdbbd00bd8cbc7d326c5be1bacf 100644 (file)
@@ -1756,10 +1756,10 @@ static int check_inode_ref(struct extent_buffer *leaf,
        while (ptr < end) {
                u16 namelen;
 
-               if (unlikely(ptr + sizeof(iref) > end)) {
+               if (unlikely(ptr + sizeof(*iref) > end)) {
                        inode_ref_err(leaf, slot,
                        "inode ref overflow, ptr %lu end %lu inode_ref_size %zu",
-                               ptr, end, sizeof(iref));
+                               ptr, end, sizeof(*iref));
                        return -EUCLEAN;
                }