]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
btrfs: make root id query unprivileged
authorDavid Sterba <dsterba@suse.cz>
Tue, 12 May 2015 17:14:49 +0000 (19:14 +0200)
committerChris Mason <clm@fb.com>
Wed, 3 Jun 2015 02:34:36 +0000 (19:34 -0700)
The INO_LOOKUP ioctl can lookup path for a given inode number and is
thus restricted. As a sideefect it can find the root id of the
containing subvolume and we're using this int the 'btrfs inspect rootid'
command.

The restriction is unnecessary in case we set the ioctl args
 args::treeid    = 0
 args::objectid  = 256 (BTRFS_FIRST_FREE_OBJECTID)

Then the path will be empty and the treeid is filled with the root id of
the inode on which the ioctl is called. This behaviour is unchanged,
after the root restriction is removed.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/ioctl.c

index f77f6b3d24b9db7e30297db291058002ed73354e..f7c65ca056f8d498146c17182af678ce467cf434 100644 (file)
@@ -2271,10 +2271,7 @@ static noinline int btrfs_ioctl_ino_lookup(struct file *file,
 {
         struct btrfs_ioctl_ino_lookup_args *args;
         struct inode *inode;
-        int ret;
-
-       if (!capable(CAP_SYS_ADMIN))
-               return -EPERM;
+       int ret = 0;
 
        args = memdup_user(argp, sizeof(*args));
        if (IS_ERR(args))
@@ -2282,13 +2279,28 @@ static noinline int btrfs_ioctl_ino_lookup(struct file *file,
 
        inode = file_inode(file);
 
+       /*
+        * Unprivileged query to obtain the containing subvolume root id. The
+        * path is reset so it's consistent with btrfs_search_path_in_tree.
+        */
        if (args->treeid == 0)
                args->treeid = BTRFS_I(inode)->root->root_key.objectid;
 
+       if (args->objectid == BTRFS_FIRST_FREE_OBJECTID) {
+               args->name[0] = 0;
+               goto out;
+       }
+
+       if (!capable(CAP_SYS_ADMIN)) {
+               ret = -EPERM;
+               goto out;
+       }
+
        ret = btrfs_search_path_in_tree(BTRFS_I(inode)->root->fs_info,
                                        args->treeid, args->objectid,
                                        args->name);
 
+out:
        if (ret == 0 && copy_to_user(argp, args, sizeof(*args)))
                ret = -EFAULT;