From: Adarsh Das Date: Tue, 3 Feb 2026 17:23:56 +0000 (+0530) Subject: btrfs: handle unexpected exact match in btrfs_set_inode_index_count() X-Git-Tag: v7.0-rc1~33^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1c88823a1958011343fa33b12a40fe42e829d9d9;p=thirdparty%2Fkernel%2Flinux.git btrfs: handle unexpected exact match in btrfs_set_inode_index_count() We search with offset (u64)-1 which should never match exactly. Previously the code silently returned success without setting the index count. Now logs an error and return -EUCLEAN instead. Reviewed-by: Qu Wenruo Signed-off-by: Adarsh Das Reviewed-by: David Sterba , Signed-off-by: David Sterba --- diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 1aebd2ee2704e..b6c763a17406b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6149,9 +6149,18 @@ static int btrfs_set_inode_index_count(struct btrfs_inode *inode) ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) return ret; - /* FIXME: we should be able to handle this */ - if (ret == 0) - return ret; + + if (unlikely(ret == 0)) { + /* + * Key with offset -1 found, there would have to exist a dir + * index item with such offset, but this is out of the valid + * range. + */ + btrfs_err(root->fs_info, + "unexpected exact match for DIR_INDEX key, inode %llu", + btrfs_ino(inode)); + return -EUCLEAN; + } if (path->slots[0] == 0) { inode->index_cnt = BTRFS_DIR_START_INDEX;