1 From 31d4d90185c99b8856cba30e84c926750b343221 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 25 Oct 2021 16:27:21 -0300
4 Subject: fanotify: Split fsid check from other fid mode checks
6 From: Gabriel Krisman Bertazi <krisman@collabora.com>
8 [ Upstream commit 8299212cbdb01a5867e230e961f82e5c02a6de34 ]
10 FAN_FS_ERROR will require fsid, but not necessarily require the
11 filesystem to expose a file handle. Split those checks into different
12 functions, so they can be used separately when setting up an event.
14 While there, update a comment about tmpfs having 0 fsid, which is no
17 Link: https://lore.kernel.org/r/20211025192746.66445-7-krisman@collabora.com
18 Reviewed-by: Amir Goldstein <amir73il@gmail.com>
19 Reviewed-by: Jan Kara <jack@suse.cz>
20 Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
21 Signed-off-by: Jan Kara <jack@suse.cz>
22 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
24 fs/notify/fanotify/fanotify_user.c | 27 ++++++++++++++++++---------
25 1 file changed, 18 insertions(+), 9 deletions(-)
27 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
28 index 20b743b05b997..8cf8e63a2c3e8 100644
29 --- a/fs/notify/fanotify/fanotify_user.c
30 +++ b/fs/notify/fanotify/fanotify_user.c
31 @@ -1300,16 +1300,15 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
35 -/* Check if filesystem can encode a unique fid */
36 -static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
37 +static int fanotify_test_fsid(struct dentry *dentry, __kernel_fsid_t *fsid)
39 __kernel_fsid_t root_fsid;
43 - * Make sure path is not in filesystem with zero fsid (e.g. tmpfs).
44 + * Make sure dentry is not of a filesystem with zero fsid (e.g. fuse).
46 - err = vfs_get_fsid(path->dentry, fsid);
47 + err = vfs_get_fsid(dentry, fsid);
51 @@ -1317,10 +1316,10 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
55 - * Make sure path is not inside a filesystem subvolume (e.g. btrfs)
56 + * Make sure dentry is not of a filesystem subvolume (e.g. btrfs)
57 * which uses a different fsid than sb root.
59 - err = vfs_get_fsid(path->dentry->d_sb->s_root, &root_fsid);
60 + err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid);
64 @@ -1328,6 +1327,12 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
65 root_fsid.val[1] != fsid->val[1])
71 +/* Check if filesystem can encode a unique fid */
72 +static int fanotify_test_fid(struct dentry *dentry)
75 * We need to make sure that the file system supports at least
76 * encoding a file handle so user can use name_to_handle_at() to
77 @@ -1335,8 +1340,8 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
78 * objects. However, name_to_handle_at() requires that the
79 * filesystem also supports decoding file handles.
81 - if (!path->dentry->d_sb->s_export_op ||
82 - !path->dentry->d_sb->s_export_op->fh_to_dentry)
83 + if (!dentry->d_sb->s_export_op ||
84 + !dentry->d_sb->s_export_op->fh_to_dentry)
88 @@ -1505,7 +1510,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
92 - ret = fanotify_test_fid(&path, &__fsid);
93 + ret = fanotify_test_fsid(path.dentry, &__fsid);
95 + goto path_put_and_out;
97 + ret = fanotify_test_fid(path.dentry);
99 goto path_put_and_out;