Skip to content

Commit 83a8914

Browse files
WOnder93gregkh
authored andcommitted
fanotify: call fanotify_events_supported() before path_permission() and security_path_notify()
[ Upstream commit 66052a7 ] The latter trigger LSM (e.g. SELinux) checks, which will log a denial when permission is denied, so it's better to do them after validity checks to avoid logging a denial when the operation would fail anyway. Fixes: 0b3b094 ("fanotify: Disallow permission events for proc filesystem") Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Paul Moore <paul@paul-moore.com> Link: https://patch.msgid.link/20260216150625.793013-3-omosnace@redhat.com Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0879970 commit 83a8914

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

fs/notify/fanotify/fanotify_user.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ static int fanotify_find_path(int dfd, const char __user *filename,
10251025

10261026
*path = fd_file(f)->f_path;
10271027
path_get(path);
1028+
ret = 0;
10281029
} else {
10291030
unsigned int lookup_flags = 0;
10301031

@@ -1034,22 +1035,7 @@ static int fanotify_find_path(int dfd, const char __user *filename,
10341035
lookup_flags |= LOOKUP_DIRECTORY;
10351036

10361037
ret = user_path_at(dfd, filename, lookup_flags, path);
1037-
if (ret)
1038-
goto out;
1039-
}
1040-
1041-
/* you can only watch an inode if you have read permissions on it */
1042-
ret = path_permission(path, MAY_READ);
1043-
if (ret) {
1044-
path_put(path);
1045-
goto out;
10461038
}
1047-
1048-
ret = security_path_notify(path, mask, obj_type);
1049-
if (ret)
1050-
path_put(path);
1051-
1052-
out:
10531039
return ret;
10541040
}
10551041

@@ -1841,6 +1827,15 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
18411827
goto path_put_and_out;
18421828
}
18431829

1830+
/* you can only watch an inode if you have read permissions on it */
1831+
ret = path_permission(&path, MAY_READ);
1832+
if (ret)
1833+
goto path_put_and_out;
1834+
1835+
ret = security_path_notify(&path, mask, obj_type);
1836+
if (ret)
1837+
goto path_put_and_out;
1838+
18441839
if (fid_mode) {
18451840
ret = fanotify_test_fsid(path.dentry, flags, &__fsid);
18461841
if (ret)

0 commit comments

Comments
 (0)