From: Song Liu <song@kernel.org>
To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com,
kernel-team@fb.com, song@kernel.org
Subject: [PATCH v2] fsnotify, lsm: Decouple fsnotify from lsm
Date: Sat, 12 Oct 2024 17:22:48 -0700 [thread overview]
Message-ID: <20241013002248.3984442-1-song@kernel.org> (raw)
Currently, fsnotify_open_perm() is called from security_file_open(). This
is not right for CONFIG_SECURITY=n and CONFIG_FSNOTIFY=y case, as
security_file_open() in this combination will be a no-op and not call
fsnotify_open_perm(). Fix this by calling fsnotify_open_perm() directly.
After this, CONFIG_FANOTIFY_ACCESS_PERMISSIONS does not require
CONFIG_SECURITY any more. Remove the dependency in the config.
Signed-off-by: Song Liu <song@kernel.org>
Acked-by: Paul Moore <paul@paul-moore.com>
---
v1: https://lore.kernel.org/linux-fsdevel/20241011203722.3749850-1-song@kernel.org/
As far as I can tell, it is necessary to back port this to stable. Because
CONFIG_FANOTIFY_ACCESS_PERMISSIONS is the only user of fsnotify_open_perm,
and CONFIG_FANOTIFY_ACCESS_PERMISSIONS depends on CONFIG_SECURITY.
Therefore, the following tags are not necessary. But I include here as
these are discussed in v1.
Fixes: c4ec54b40d33 ("fsnotify: new fsnotify hooks and events types for access decisions")
Depends-on: 36e28c42187c ("fsnotify: split fsnotify_perm() into two hooks")
Depends-on: d9e5d31084b0 ("fsnotify: optionally pass access range in file permission hooks")
---
fs/notify/fanotify/Kconfig | 1 -
fs/open.c | 4 ++++
security/security.c | 9 +--------
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/fs/notify/fanotify/Kconfig b/fs/notify/fanotify/Kconfig
index a511f9d8677b..0e36aaf379b7 100644
--- a/fs/notify/fanotify/Kconfig
+++ b/fs/notify/fanotify/Kconfig
@@ -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
diff --git a/fs/open.c b/fs/open.c
index acaeb3e25c88..6c4950f19cfb 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -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;
diff --git a/security/security.c b/security/security.c
index 6875eb4a59fc..a72cc62c0a07 100644
--- a/security/security.c
+++ b/security/security.c
@@ -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>
@@ -3102,13 +3101,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);
}
/**
--
2.43.5
next reply other threads:[~2024-10-13 0:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-13 0:22 Song Liu [this message]
2024-10-13 9:38 ` [PATCH v2] fsnotify, lsm: Decouple fsnotify from lsm Amir Goldstein
2024-10-13 14:45 ` Song Liu
2024-10-13 14:51 ` Amir Goldstein
2024-10-14 15:38 ` Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241013002248.3984442-1-song@kernel.org \
--to=song@kernel.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jmorris@namei.org \
--cc=kernel-team@fb.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).