Skip to content

Commit 07ddb2d

Browse files
josefbacikkdave
authored andcommitted
btrfs: don't search back for dir inode item in INO_LOOKUP_USER
We don't need to search back to the inode item, the directory inode number is in key.offset, so simply use that. If we can't find the directory we'll get an ENOENT at the iget(). Note: The patch was taken from v5 of fscrypt patchset (https://lore.kernel.org/linux-btrfs/cover.1706116485.git.josef@toxicpanda.com/) which was handled over time by various people: Omar Sandoval, Sweet Tea Dorminy, Josef Bacik. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Daniel Vacek <neelx@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> [ add note ] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 08972de commit 07ddb2d

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

fs/btrfs/ioctl.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
18221822
struct btrfs_root_ref *rref;
18231823
struct btrfs_root *root = NULL;
18241824
struct btrfs_path *path;
1825-
struct btrfs_key key, key2;
1825+
struct btrfs_key key;
18261826
struct extent_buffer *leaf;
18271827
char *ptr;
18281828
int slot;
@@ -1877,36 +1877,19 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
18771877
read_extent_buffer(leaf, ptr,
18781878
(unsigned long)(iref + 1), len);
18791879

1880-
/* Check the read+exec permission of this directory */
1881-
ret = btrfs_previous_item(root, path, dirid,
1882-
BTRFS_INODE_ITEM_KEY);
1883-
if (ret < 0) {
1884-
goto out_put;
1885-
} else if (ret > 0) {
1886-
ret = -ENOENT;
1887-
goto out_put;
1888-
}
1889-
1890-
leaf = path->nodes[0];
1891-
slot = path->slots[0];
1892-
btrfs_item_key_to_cpu(leaf, &key2, slot);
1893-
if (key2.objectid != dirid) {
1894-
ret = -ENOENT;
1895-
goto out_put;
1896-
}
1897-
18981880
/*
18991881
* We don't need the path anymore, so release it and
19001882
* avoid deadlocks and lockdep warnings in case
19011883
* btrfs_iget() needs to lookup the inode from its root
19021884
* btree and lock the same leaf.
19031885
*/
19041886
btrfs_release_path(path);
1905-
temp_inode = btrfs_iget(key2.objectid, root);
1887+
temp_inode = btrfs_iget(key.offset, root);
19061888
if (IS_ERR(temp_inode)) {
19071889
ret = PTR_ERR(temp_inode);
19081890
goto out_put;
19091891
}
1892+
/* Check the read+exec permission of this directory */
19101893
ret = inode_permission(idmap, &temp_inode->vfs_inode,
19111894
MAY_READ | MAY_EXEC);
19121895
iput(&temp_inode->vfs_inode);

0 commit comments

Comments
 (0)