Skip to content

Commit 66052a7

Browse files
WOnder93jankara
authored andcommitted
fanotify: call fanotify_events_supported() before path_permission() and security_path_notify()
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 <[email protected]> Reviewed-by: Amir Goldstein <[email protected]> Reviewed-by: Paul Moore <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jan Kara <[email protected]>
1 parent 0d5ee33 commit 66052a7

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
@@ -1210,6 +1210,7 @@ static int fanotify_find_path(int dfd, const char __user *filename,
12101210

12111211
*path = fd_file(f)->f_path;
12121212
path_get(path);
1213+
ret = 0;
12131214
} else {
12141215
unsigned int lookup_flags = 0;
12151216

@@ -1219,22 +1220,7 @@ static int fanotify_find_path(int dfd, const char __user *filename,
12191220
lookup_flags |= LOOKUP_DIRECTORY;
12201221

12211222
ret = user_path_at(dfd, filename, lookup_flags, path);
1222-
if (ret)
1223-
goto out;
12241223
}
1225-
1226-
/* you can only watch an inode if you have read permissions on it */
1227-
ret = path_permission(path, MAY_READ);
1228-
if (ret) {
1229-
path_put(path);
1230-
goto out;
1231-
}
1232-
1233-
ret = security_path_notify(path, mask, obj_type);
1234-
if (ret)
1235-
path_put(path);
1236-
1237-
out:
12381224
return ret;
12391225
}
12401226

@@ -2058,6 +2044,15 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,
20582044
goto path_put_and_out;
20592045
}
20602046

2047+
/* you can only watch an inode if you have read permissions on it */
2048+
ret = path_permission(&path, MAY_READ);
2049+
if (ret)
2050+
goto path_put_and_out;
2051+
2052+
ret = security_path_notify(&path, mask, obj_type);
2053+
if (ret)
2054+
goto path_put_and_out;
2055+
20612056
if (fid_mode) {
20622057
ret = fanotify_test_fsid(path.dentry, flags, &__fsid);
20632058
if (ret)

0 commit comments

Comments
 (0)