• Tomohiro Misono's avatar
    btrfs: Add unprivileged version of ino_lookup ioctl · 23d0b79d
    Tomohiro Misono authored
    Add unprivileged version of ino_lookup ioctl BTRFS_IOC_INO_LOOKUP_USER
    to allow normal users to call "btrfs subvolume list/show" etc. in
    combination with BTRFS_IOC_GET_SUBVOL_INFO/BTRFS_IOC_GET_SUBVOL_ROOTREF.
    
    This can be used like BTRFS_IOC_INO_LOOKUP but the argument is
    different. This is  because it always searches the fs/file tree
    correspoinding to the fd with which this ioctl is called and also
    returns the name of bottom subvolume.
    
    The main differences from original ino_lookup ioctl are:
    
      1. Read + Exec permission will be checked using inode_permission()
         during path construction. -EACCES will be returned in case
         of failure.
      2. Path construction will be stopped at the inode number which
         corresponds to the fd with which this ioctl is called. If
         constructed path does not exist under fd's inode, -EACCES
         will be returned.
      3. The name of bottom subvolume is also searched and filled.
    
    Note that the maximum length of path is shorter 256 (BTRFS_VOL_NAME_MAX+1)
    bytes than ino_lookup ioctl because of space of subvolume's name.
    Reviewed-by: default avatarGu Jinxiang <gujx@cn.fujitsu.com>
    Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
    Tested-by: default avatarGu Jinxiang <gujx@cn.fujitsu.com>
    Signed-off-by: default avatarTomohiro Misono <misono.tomohiro@jp.fujitsu.com>
    [ style fixes ]
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    23d0b79d
ioctl.c 145 KB