Skip to content

eBPF-based security platform

kernel: carry patches for sleepable entry hooks and a trusted d_parent

Daniel Borkmannf9cdf62158d1
diff --git a/Documentation/internals/kernel-patches.rst b/Documentation/internals/kernel-patches.rst
index 9709519f..049a4699 100644
--- a/Documentation/internals/kernel-patches.rst
+++ b/Documentation/internals/kernel-patches.rst
@@ -34,13 +34,24 @@ Summary
- Daniel Borkmann
- No
- All
+ * - ``0004-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch``
+ - Daniel Borkmann
+ - No
+ - All
+ * - ``0005-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch``
+ - Daniel Borkmann
+ - No
+ - All
"In bpf-next" was checked against the bpf-next tree at commit
``cd5bc55288d4``: ``include/linux/ftrace.h`` there still marks jmp mode
with bit 0, ``include/linux/lsm_hook_defs.h`` has no ``tpm_command``
-hook, and ``fs/bpf_fs_kfuncs.c`` checks the calling task's read
-permission before it returns a ``security.bpf.`` xattr to an LSM
-program.
+hook, ``fs/bpf_fs_kfuncs.c`` checks the calling task's read permission
+before it returns a ``security.bpf.`` xattr to an LSM program, the
+sleepable hook set of ``kernel/bpf/bpf_lsm.c`` lacks ``inode_mkdir``,
+``inode_link``, ``inode_set_acl``, ``inode_remove_acl``,
+``inode_file_setattr`` and ``inode_copy_up``, and the verifier trusts
+``d_inode`` of a dentry but not ``d_parent``.
How the test kernel applies them
--------------------------------
diff --git a/Documentation/operate/plan/system-requirements.rst b/Documentation/operate/plan/system-requirements.rst
index 6eb22ca2..78defc2a 100644
--- a/Documentation/operate/plan/system-requirements.rst
+++ b/Documentation/operate/plan/system-requirements.rst
@@ -83,6 +83,17 @@ Kernel source
LSMs read their labels. Without it the seal takes a label its
caller may not read for a missing one unless the inode carries a
mark, which root can arrange with an idmapped mount or an ACL.
+ * - :src:`kernel/0004-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch`
+ - Lets a sleepable LSM program attach to ``inode_mkdir``,
+ ``inode_link``, ``inode_set_acl``, ``inode_remove_acl``,
+ ``inode_file_setattr`` and ``inode_copy_up``. The seal reads
+ labels in those hooks and ``shirudo init`` fails to attach them
+ without it.
+ * - :src:`kernel/0005-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch`
+ - Lets an LSM program pass ``dentry->d_parent`` to the xattr kfunc.
+ The seal reads the label of the directory a new entry goes into
+ from it; without the patch the verifier refuses the seal's entry
+ hooks.
:doc:`/internals/kernel-patches` gives the upstream status of the
carried patches.
diff --git a/kernel/0004-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch b/kernel/0004-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch
new file mode 100644
index 00000000..ce1c7fc1
--- /dev/null
+++ b/kernel/0004-bpf-Let-sleepable-LSM-programs-attach-to-the-remaining-inode-hooks.patch
@@ -0,0 +1,61 @@
+From 4394d88fc34a232779f9b1322c5cf6169e3fab13 Mon Sep 17 00:00:00 2001
+From: Daniel Borkmann <[email protected]>
+Date: Tue, 3 Nov 2026 13:52:42 +0000
+Subject: [PATCH] bpf: Let sleepable LSM programs attach to the remaining inode
+ hooks
+
+A BPF LSM program reads an xattr with bpf_get_dentry_xattr() or
+bpf_get_file_xattr(), which sleep, so only a sleepable program can
+decide an operation by the label an inode carries. The set of hooks
+such a program may attach to holds inode_create, inode_symlink,
+inode_mknod, inode_unlink, inode_rename, inode_rmdir, inode_setattr,
+inode_setxattr and inode_removexattr, but not inode_mkdir and
+inode_link, the other two hooks that decide a new directory entry, nor
+inode_set_acl, inode_remove_acl and inode_file_setattr, which decide
+an ACL and an inode flag change, nor inode_copy_up, which decides an
+overlay copy-up. Each of them is called from process context with the
+inode lock held, as the hooks already in the set are, and may sleep.
+
+Add them, so that a program which labels directories can read the
+label of the directory a mkdir or a link changes, the label of the
+inode an ACL or flag change targets, and the label of the inode an
+overlay copies up, instead of a cache of its own that the inode's
+eviction empties.
+
+Signed-off-by: Daniel Borkmann <[email protected]>
+---
+ kernel/bpf/bpf_lsm.c | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
+index f58dce888ff4..688c249680ef 100644
+--- a/kernel/bpf/bpf_lsm.c
++++ b/kernel/bpf/bpf_lsm.c
+@@ -333,18 +333,24 @@ BTF_ID(func, bpf_lsm_file_open)
+ BTF_ID(func, bpf_lsm_file_post_open)
+ BTF_ID(func, bpf_lsm_file_receive)
+
++BTF_ID(func, bpf_lsm_inode_copy_up)
+ BTF_ID(func, bpf_lsm_inode_create)
++BTF_ID(func, bpf_lsm_inode_file_setattr)
+ BTF_ID(func, bpf_lsm_inode_free_security)
+ BTF_ID(func, bpf_lsm_inode_getattr)
+ BTF_ID(func, bpf_lsm_inode_getxattr)
++BTF_ID(func, bpf_lsm_inode_link)
++BTF_ID(func, bpf_lsm_inode_mkdir)
+ BTF_ID(func, bpf_lsm_inode_mknod)
+ BTF_ID(func, bpf_lsm_inode_need_killpriv)
+ BTF_ID(func, bpf_lsm_inode_post_setxattr)
+ BTF_ID(func, bpf_lsm_inode_post_removexattr)
+ BTF_ID(func, bpf_lsm_inode_readlink)
++BTF_ID(func, bpf_lsm_inode_remove_acl)
+ BTF_ID(func, bpf_lsm_inode_removexattr)
+ BTF_ID(func, bpf_lsm_inode_rename)
+ BTF_ID(func, bpf_lsm_inode_rmdir)
++BTF_ID(func, bpf_lsm_inode_set_acl)
+ BTF_ID(func, bpf_lsm_inode_setattr)
+ BTF_ID(func, bpf_lsm_inode_setxattr)
+ BTF_ID(func, bpf_lsm_inode_symlink)
+--
+2.43.0
+
diff --git a/kernel/0005-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch b/kernel/0005-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch
new file mode 100644
index 00000000..6375790c
--- /dev/null
+++ b/kernel/0005-bpf-Treat-dentry-d_parent-as-a-trusted-pointer.patch
@@ -0,0 +1,39 @@
+From 66a9f20316aea80c61881a1c4c722261587375ee Mon Sep 17 00:00:00 2001
+From: Daniel Borkmann <[email protected]>
+Date: Tue, 3 Nov 2026 13:52:42 +0000
+Subject: [PATCH] bpf: Treat dentry->d_parent as a trusted pointer
+
+An LSM program that decides a new directory entry in inode_create,
+inode_mkdir, inode_symlink, inode_mknod or inode_link receives the
+directory as a struct inode and the new entry as a dentry. The
+directory's label lives in an xattr that bpf_get_dentry_xattr() reads
+from a dentry, and the one the program has for it is dentry->d_parent,
+which the verifier treats as an untrusted pointer, so the kfunc refuses
+it and the program cannot read the label of the directory it decides
+on.
+
+d_parent of a dentry an inode hook receives is stable while the hook
+runs, under the parent's inode lock the caller holds, and is never NULL,
+since the root's points to itself. Add it beside d_inode as trusted or
+null, which keeps a program checking it before use.
+
+Signed-off-by: Daniel Borkmann <[email protected]>
+---
+ kernel/bpf/verifier.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
+index 935b163f81e4..0ef1d5076485 100644
+--- a/kernel/bpf/verifier.c
++++ b/kernel/bpf/verifier.c
+@@ -6509,6 +6509,7 @@ BTF_TYPE_SAFE_TRUSTED(struct scx_sub_detach_args) {
+
+ BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct dentry) {
+ struct inode *d_inode;
++ struct dentry *d_parent;
+ };
+
+ BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct linux_binprm) {
+--
+2.43.0
+