public inbox for linux-security-module@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fsnotify, lsm: Separate fsnotify_open_perm() and security_file_open()
@ 2024-10-11 20:37 Song Liu
  2024-10-11 21:42 ` Paul Moore
  2024-10-14 14:11 ` Jan Kara
  0 siblings, 2 replies; 5+ messages in thread
From: Song Liu @ 2024-10-11 20:37 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel, linux-security-module
  Cc: viro, brauner, jack, paul, jmorris, serge, kernel-team, song

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.

Signed-off-by: Song Liu <song@kernel.org>

---

PS: I didn't included a Fixes tag. This issue was probably introduced 15
years ago in [1]. If we want to back port this to stable, we will need
another version for older kernel because of [2].

[1] c4ec54b40d33 ("fsnotify: new fsnotify hooks and events types for access decisions")
[2] 36e28c42187c ("fsnotify: split fsnotify_perm() into two hooks")
---
 fs/open.c           | 4 ++++
 security/security.c | 9 +--------
 2 files changed, 5 insertions(+), 8 deletions(-)

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-14 14:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-11 20:37 [PATCH] fsnotify, lsm: Separate fsnotify_open_perm() and security_file_open() Song Liu
2024-10-11 21:42 ` Paul Moore
2024-10-12  7:09   ` Amir Goldstein
2024-10-12 17:26     ` Song Liu
2024-10-14 14:11 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox