Skip to contentSkip to conversation

fsnotify: compile out fsnotify permission hooks if !FANOTIFY_ACCESS_PERMISSIONS

PATCH Applied Amir Goldstein 4 participants 5 messages Jan 9, 2024 – Jan 10, 2024

Subsystems (2)
lore
Share & tools
lore

Amir Goldstein

author reviewer
#0 lore raw

PATCH 1/1 fsnotify: compile out fsnotify permission hooks if !FANOTIFY_ACCESS_PERMISSIONS

The depency of FANOTIFY_ACCESS_PERMISSIONS on SECURITY made sure that the fsnotify permission hooks were never called when SECURITY was disabled.

Moving the fsnotify permission hook out of the secutiy hook broke that optimisation.

Reported-and-tested-by Jens Axboe <[email protected]>
Fixes d9e5d31084b0 ("fsnotify: optionally pass access range in file permission hooks")
---
 include/linux/fsnotify.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
include/linux/fsnotify.h +19 -0
index 11e6434b8e71..8300a5286988 100644
@@ -100,6 +100,7 @@ static inline int fsnotify_file(struct file *file, __u32 mask)
 	return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
 }
 
+#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
 /*
  * fsnotify_file_area_perm - permission hook before access to file range
  */
@@ -145,6 +146,24 @@ static inline int fsnotify_open_perm(struct file *file)
 	return fsnotify_file(file, FS_OPEN_PERM);
 }
 
+#else
+static inline int fsnotify_file_area_perm(struct file *file, int perm_mask,
+					  const loff_t *ppos, size_t count)
+{
+	return 0;
+}
+
+static inline int fsnotify_file_perm(struct file *file, int perm_mask)
+{
+	return 0;
+}
+
+static inline int fsnotify_open_perm(struct file *file)
+{
+	return 0;
+}
+#endif
+
 /*
  * fsnotify_link_count - inode's link count changed
  */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line · Amir Goldstein

The depency of FANOTIFY_ACCESS_PERMISSIONS on SECURITY made sure that

dependency

Quoted 4 lines

the fsnotify permission hooks were never called when SECURITY was disabled.

Moving the fsnotify permission hook out of the secutiy hook broke that

security

Quoted 1 line

optimisation.

Patch obviously looks good to me, as I already tested it :-)

Thanks for fixing this up.

Signature · 1 line
Jens Axboe
maintainer
#2 lore raw
Quoted 10 lines · Jens Axboe
Quoted 1 line · Amir Goldstein

The depency of FANOTIFY_ACCESS_PERMISSIONS on SECURITY made sure that

dependency

Quoted 4 lines

the fsnotify permission hooks were never called when SECURITY was disabled.

Moving the fsnotify permission hook out of the secutiy hook broke that

Quoted 7 lines

security

Quoted 1 line

optimisation.

Patch obviously looks good to me, as I already tested it :-)

Thanks for fixing this up.

Thanks Amir for the fix and Jens for the spelling fixes. I'll fix them on commit.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#3 lore raw
In reply to Amir Goldstein
Quoted 8 lines · Amir Goldstein

The depency of FANOTIFY_ACCESS_PERMISSIONS on SECURITY made sure that the fsnotify permission hooks were never called when SECURITY was disabled.

Moving the fsnotify permission hook out of the secutiy hook broke that optimisation.

[...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] fsnotify: compile out fsnotify permission hooks if !FANOTIFY_ACCESS_PERMISSIONS

      https://git.kernel.org/vfs/vfs/c/b0f2ac4fe541
maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Amir Goldstein
Quoted 11 lines · Amir Goldstein

The depency of FANOTIFY_ACCESS_PERMISSIONS on SECURITY made sure that the fsnotify permission hooks were never called when SECURITY was disabled.

Moving the fsnotify permission hook out of the secutiy hook broke that optimisation.

Reported-and-tested-by Jens Axboe <[email protected]>
Fixes d9e5d31084b0 ("fsnotify: optionally pass access range in file permission hooks")

Originally I didn't notice this was directed to Christian but it makes sense since he merged the original patches. The fix looks good (modulo the typo fixes from Jens). Feel free to add:

Honza

Quoted 44 lines
---
 include/linux/fsnotify.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
include/linux/fsnotify.h +19 -0
index 11e6434b8e71..8300a5286988 100644
@@ -100,6 +100,7 @@ static inline int fsnotify_file(struct file *file, __u32 mask)
 	return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
 }
 
+#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
 /*
  * fsnotify_file_area_perm - permission hook before access to file range
  */
@@ -145,6 +146,24 @@ static inline int fsnotify_open_perm(struct file *file)
 	return fsnotify_file(file, FS_OPEN_PERM);
 }
 
+#else
+static inline int fsnotify_file_area_perm(struct file *file, int perm_mask,
+					  const loff_t *ppos, size_t count)
+{
+	return 0;
+}
+
+static inline int fsnotify_file_perm(struct file *file, int perm_mask)
+{
+	return 0;
+}
+
+static inline int fsnotify_open_perm(struct file *file)
+{
+	return 0;
+}
+#endif
+
 /*
  * fsnotify_link_count - inode's link count changed
  */
Signature · 1 line
2.34.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR