fsnotify, lsm: Decouple fsnotify from lsm

Currently, fsnotify_open_perm() is called from security_file_open().
This is a a bit unexpected and creates otherwise unnecessary dependency
of CONFIG_FANOTIFY_ACCESS_PERMISSIONS on CONFIG_SECURITY. Fix this by
calling fsnotify_open_perm() directly.

Signed-off-by: Song Liu <song@kernel.org>
Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20241013002248.3984442-1-song@kernel.org
This commit is contained in:
Song Liu 2024-10-12 17:22:48 -07:00 committed by Jan Kara
parent 6485cf5ea2
commit 1cda52f1b4
3 changed files with 5 additions and 9 deletions

View File

@ -15,7 +15,6 @@ config FANOTIFY
config FANOTIFY_ACCESS_PERMISSIONS
bool "fanotify permissions checking"
depends on FANOTIFY
depends on SECURITY
default n
help
Say Y here is you want fanotify listeners to be able to make permissions

View File

@ -946,6 +946,10 @@ static int do_dentry_open(struct file *f,
if (error)
goto cleanup_all;
error = fsnotify_open_perm(f);
if (error)
goto cleanup_all;
error = break_lease(file_inode(f), f->f_flags);
if (error)
goto cleanup_all;

View File

@ -19,7 +19,6 @@
#include <linux/kernel.h>
#include <linux/kernel_read_file.h>
#include <linux/lsm_hooks.h>
#include <linux/fsnotify.h>
#include <linux/mman.h>
#include <linux/mount.h>
#include <linux/personality.h>
@ -3104,13 +3103,7 @@ int security_file_receive(struct file *file)
*/
int security_file_open(struct file *file)
{
int ret;
ret = call_int_hook(file_open, file);
if (ret)
return ret;
return fsnotify_open_perm(file);
return call_int_hook(file_open, file);
}
/**