fanotify: Split fsid check from other fid mode checks
[ Upstream commit 8299212cbdb01a5867e230e961f82e5c02a6de34 ] FAN_FS_ERROR will require fsid, but not necessarily require the filesystem to expose a file handle. Split those checks into different functions, so they can be used separately when setting up an event. While there, update a comment about tmpfs having 0 fsid, which is no longer true. Link: https://lore.kernel.org/r/20211025192746.66445-7-krisman@collabora.com Reviewed-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
326be73a59
commit
9539a89f28
@@ -1295,16 +1295,15 @@ out_destroy_group:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if filesystem can encode a unique fid */
|
static int fanotify_test_fsid(struct dentry *dentry, __kernel_fsid_t *fsid)
|
||||||
static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
|
|
||||||
{
|
{
|
||||||
__kernel_fsid_t root_fsid;
|
__kernel_fsid_t root_fsid;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure path is not in filesystem with zero fsid (e.g. tmpfs).
|
* Make sure dentry is not of a filesystem with zero fsid (e.g. fuse).
|
||||||
*/
|
*/
|
||||||
err = vfs_get_fsid(path->dentry, fsid);
|
err = vfs_get_fsid(dentry, fsid);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -1312,10 +1311,10 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
|
|||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure path is not inside a filesystem subvolume (e.g. btrfs)
|
* Make sure dentry is not of a filesystem subvolume (e.g. btrfs)
|
||||||
* which uses a different fsid than sb root.
|
* which uses a different fsid than sb root.
|
||||||
*/
|
*/
|
||||||
err = vfs_get_fsid(path->dentry->d_sb->s_root, &root_fsid);
|
err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@@ -1323,6 +1322,12 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
|
|||||||
root_fsid.val[1] != fsid->val[1])
|
root_fsid.val[1] != fsid->val[1])
|
||||||
return -EXDEV;
|
return -EXDEV;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if filesystem can encode a unique fid */
|
||||||
|
static int fanotify_test_fid(struct dentry *dentry)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* We need to make sure that the file system supports at least
|
* We need to make sure that the file system supports at least
|
||||||
* encoding a file handle so user can use name_to_handle_at() to
|
* encoding a file handle so user can use name_to_handle_at() to
|
||||||
@@ -1330,8 +1335,8 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
|
|||||||
* objects. However, name_to_handle_at() requires that the
|
* objects. However, name_to_handle_at() requires that the
|
||||||
* filesystem also supports decoding file handles.
|
* filesystem also supports decoding file handles.
|
||||||
*/
|
*/
|
||||||
if (!path->dentry->d_sb->s_export_op ||
|
if (!dentry->d_sb->s_export_op ||
|
||||||
!path->dentry->d_sb->s_export_op->fh_to_dentry)
|
!dentry->d_sb->s_export_op->fh_to_dentry)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1500,7 +1505,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fid_mode) {
|
if (fid_mode) {
|
||||||
ret = fanotify_test_fid(&path, &__fsid);
|
ret = fanotify_test_fsid(path.dentry, &__fsid);
|
||||||
|
if (ret)
|
||||||
|
goto path_put_and_out;
|
||||||
|
|
||||||
|
ret = fanotify_test_fid(path.dentry);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto path_put_and_out;
|
goto path_put_and_out;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user