fsnotify, lsm: Separate fsnotify_open_perm() and security_file_open()
PATCH 1/1 fsnotify, lsm: Separate fsnotify_open_perm() and security_file_open()
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.
---
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(-)
fs/open.c +4 -0
@@ -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;
security/security.c +1 -8
@@ -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); }/**
Signature · 1 line
2.43.5
Quoted 12 lines · On Oct 11, 2024 Song Liu <[email protected]> wrote:
Currently,
fsnotify_open_perm()is called fromsecurity_file_open(). This is not right forCONFIG_SECURITY=nandCONFIG_FSNOTIFY=ycase, assecurity_file_open()in this combination will be a no-op and not callfsnotify_open_perm(). Fix this by callingfsnotify_open_perm()directly.Signed-off-by Song Liu <[email protected]>---
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].
Quoted 6 lines
[1]
c4ec54b40d33("fsnotify: new fsnotify hooks and events types for access decisions")
[2]36e28c42187c("fsnotify: splitfsnotify_perm()into two hooks")--- fs/open.c | 4 ++++ security/security.c | 9 +-------- 2 files changed, 5 insertions(+), 8 deletions(-)
This looks fine to me, if we can get an ACK from the VFS folks I can merge this into the lsm/stable-6.12 tree and send it to Linus, or the VFS folks can do it if they prefer (my ACK is below just in case).
As far as stable prior to v6.8 is concerned, once this hits Linus' tree you can submit an adjusted backport for the older kernels to the stable team.
--
paul-moore.com
Amir Goldstein
reviewerQuoted 14 lines · Paul Moore
Quoted 12 lines · On Oct 11, 2024 Song Liu <[email protected]> wrote:
Currently,
fsnotify_open_perm()is called fromsecurity_file_open(). This is not right forCONFIG_SECURITY=nandCONFIG_FSNOTIFY=ycase, assecurity_file_open()in this combination will be a no-op and not callfsnotify_open_perm(). Fix this by callingfsnotify_open_perm()directly.Signed-off-by Song Liu <[email protected]>---
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].
Quoted 6 lines
Quoted 6 lines
[1]
c4ec54b40d33("fsnotify: new fsnotify hooks and events types for access decisions")
[2]36e28c42187c("fsnotify: splitfsnotify_perm()into two hooks")--- fs/open.c | 4 ++++ security/security.c | 9 +-------- 2 files changed, 5 insertions(+), 8 deletions(-)
Nice cleanup, but please finish off the coupling of lsm/fsnotify altogether. I would either change the title to "decouple fsnotify from lsm" or submit an additional patch with that title.
fs/notify/fanotify/Kconfig +0 -1
@@ -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
security/security.c +0 -1
@@ -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>
Quoted 4 lines
This looks fine to me, if we can get an ACK from the VFS folks I can merge this into the lsm/stable-6.12 tree and send it to Linus, or the VFS folks can do it if they prefer (my ACK is below just in case).
My preference would be to take this via the vfs or fsnotify tree.
Quoted 4 lines
As far as stable prior to v6.8 is concerned, once this hits Linus' tree you can submit an adjusted backport for the older kernels to the stable team.
Please do NOT submit an adjustable backport.
Instead please include the following tags for the decoupling patch:
Depends-on: 36e28c42187c fsnotify: split fsnotify_perm() into two hooks
Depends-on: d9e5d31084b0 fsnotify: optionally pass access range in file permission hooks
Quoted 3 lines
Acked-by Paul Moore <[email protected]>
Thanks,
Amir.
Hi Amir,
Thanks for the review.
Quoted 33 lines · Amir Goldstein
Quoted 14 lines · Paul Moore
Quoted 12 lines · On Oct 11, 2024 Song Liu <[email protected]> wrote:
Currently,
fsnotify_open_perm()is called fromsecurity_file_open(). This is not right forCONFIG_SECURITY=nandCONFIG_FSNOTIFY=ycase, assecurity_file_open()in this combination will be a no-op and not callfsnotify_open_perm(). Fix this by callingfsnotify_open_perm()directly.Signed-off-by Song Liu <[email protected]>---
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].Quoted 6 lines
Quoted 6 lines
[1]
c4ec54b40d33("fsnotify: new fsnotify hooks and events types for access decisions")
[2]36e28c42187c("fsnotify: splitfsnotify_perm()into two hooks")
---fs/open.c| 4 ++++security/security.c| 9 +--------2 files changed, 5 insertions(+), 8 deletions(-)Nice cleanup, but please finish off the coupling of lsm/fsnotify altogether. I would either change the title to "decouple fsnotify from lsm" or submit an additional patch with that title.
fs/notify/fanotify/Kconfig +0
-0@@ -15,7 +15,6 @@ config FANOTIFY
Quoted 8 lines
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
I will send v2 with this change.
Quoted 25 lines
security/security.c +0
-1@@ -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> Quoted 5 lines
This looks fine to me, if we can get an ACK from the VFS folks I can merge this into the lsm/stable-6.12 tree and send it to Linus, or the VFS folks can do it if they prefer (my ACK is below just in case).
My preference would be to take this via the vfs or fsnotify tree.
Quoted 4 lines
As far as stable prior to v6.8 is concerned, once this hits Linus' tree you can submit an adjusted backport for the older kernels to the stable team.
Quoted 6 lines
Please do NOT submit an adjustable backport.
Instead please include the following tags for the decoupling patch:Depends-on:
36e28c42187cfsnotify: splitfsnotify_perm()into two hooks
Depends-on:d9e5d31084b0fsnotify: optionally pass access range in file permission hooks
IIUC, FANOTIFY_ACCESS_PERMISSIONS is the only user of FS_OPEN_EXEC_PERM and FS_OPEN_PERM. In this case, I think we don't need to back port this to stable, because there is no user of fsnotify_open_perm without CONFIG_SECURITY. Did I miss something?
Thanks,
Song
Jan Kara
maintainerQuoted 5 lines · Song Liu
Currently,
fsnotify_open_perm()is called fromsecurity_file_open(). This is not right forCONFIG_SECURITY=nandCONFIG_FSNOTIFY=ycase, assecurity_file_open()in this combination will be a no-op and not callfsnotify_open_perm(). Fix this by callingfsnotify_open_perm()directly.
Quoted 7 lines
Signed-off-by Song Liu <[email protected]>---
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].
Well, this is not a problem because CONFIG_FANOTIFY_ACCESS_PERMISSIONS has "depends on SECURITY". So fsnotify_open_perm() can have anything to do only if CONFIG_SECURITY is enabled. That being said I agree it makes sense to decouple security & fsnotify because there's no significant benefit and only confusion. So I like the patch but please update the changelog and also finish the split as Amir suggests.
Honza
Quoted 52 lines
[1]
c4ec54b40d33("fsnotify: new fsnotify hooks and events types for access decisions")
[2]36e28c42187c("fsnotify: splitfsnotify_perm()into two hooks")--- fs/open.c | 4 ++++ security/security.c | 9 +-------- 2 files changed, 5 insertions(+), 8 deletions(-)fs/open.c +4
-0@@ -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;security/security.c +1
-8@@ -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); }/** Signature · 1 line
2.43.5
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR