]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/fanotify-split-fsid-check-from-other-fid-mode-checks.patch
Fixes for 5.15
[thirdparty/kernel/stable-queue.git] / queue-5.15 / fanotify-split-fsid-check-from-other-fid-mode-checks.patch
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
5
6 From: Gabriel Krisman Bertazi <krisman@collabora.com>
7
8 [ Upstream commit 8299212cbdb01a5867e230e961f82e5c02a6de34 ]
9
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.
13
14 While there, update a comment about tmpfs having 0 fsid, which is no
15 longer true.
16
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>
23 ---
24 fs/notify/fanotify/fanotify_user.c | 27 ++++++++++++++++++---------
25 1 file changed, 18 insertions(+), 9 deletions(-)
26
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)
32 return fd;
33 }
34
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)
38 {
39 __kernel_fsid_t root_fsid;
40 int err;
41
42 /*
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).
45 */
46 - err = vfs_get_fsid(path->dentry, fsid);
47 + err = vfs_get_fsid(dentry, fsid);
48 if (err)
49 return err;
50
51 @@ -1317,10 +1316,10 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid)
52 return -ENODEV;
53
54 /*
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.
58 */
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);
61 if (err)
62 return err;
63
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])
66 return -EXDEV;
67
68 + return 0;
69 +}
70 +
71 +/* Check if filesystem can encode a unique fid */
72 +static int fanotify_test_fid(struct dentry *dentry)
73 +{
74 /*
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.
80 */
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)
85 return -EOPNOTSUPP;
86
87 return 0;
88 @@ -1505,7 +1510,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
89 }
90
91 if (fid_mode) {
92 - ret = fanotify_test_fid(&path, &__fsid);
93 + ret = fanotify_test_fsid(path.dentry, &__fsid);
94 + if (ret)
95 + goto path_put_and_out;
96 +
97 + ret = fanotify_test_fid(path.dentry);
98 if (ret)
99 goto path_put_and_out;
100
101 --
102 2.43.0
103