[PATCH RFC 1/3] lsm: Call inode_init_security hooks without xattrs
Farid Zakaria
farid.m.zakaria at gmail.com
Sat Oct 24 20:39:17 UTC 2026
security_inode_init_security() returns early when no LSM reserves an
xattr slot, so the inode_init_security hooks never run on a kernel
whose LSMs provide no xattr. An LSM can then not use the hook to
observe inode creation unless some other LSM happens to label inodes.
Call the hooks regardless of the reserved xattr count, and only skip
allocating the xattr array when no slot is reserved. LSMs that write
xattrs still need a reserved slot, so they are unaffected. Landlock
uses the hook in the next patch to track the files a sandboxed task
creates.
Assisted-by: LLM
Signed-off-by: Farid Zakaria <farid.m.zakaria at gmail.com>
---
security/security.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/security/security.c b/security/security.c
index b284e24e3771..bb94c94d97a5 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1353,10 +1353,11 @@ int security_inode_init_security(struct inode *inode, struct inode *dir,
if (unlikely(IS_PRIVATE(inode)))
return 0;
- if (!blob_sizes.lbs_xattr_count)
- return 0;
-
- if (initxattrs) {
+ /*
+ * Even without any xattr to provide, LSMs (e.g. Landlock) may need to
+ * track inode creations.
+ */
+ if (initxattrs && blob_sizes.lbs_xattr_count) {
/* Allocate +1 as terminator. */
new_xattrs = kcalloc(blob_sizes.lbs_xattr_count + 1,
sizeof(*new_xattrs), GFP_NOFS);
--
2.55.0
More information about the Linux-security-module-archive
mailing list