public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: add bpf_real_inode() kfunc
@ 2026-03-26 16:53 Christian Brauner
  2026-03-26 17:02 ` Amir Goldstein
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Christian Brauner @ 2026-03-26 16:53 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Alexander Viro, Jan Kara, Daniel Borkmann, Alexei Starovoitov,
	linux-fsdevel, bpf, Christian Brauner

Add a sleepable BPF kfunc that resolves the real inode backing a dentry
via d_real_inode(). On overlay/union filesystems the inode attached to
the dentry is the overlay inode which does not carry the underlying
device information. d_real_inode() resolves through the overlay and
returns the inode from the lower, real filesystem.

This is needed by the dm-verity based execution policy implemented in
systemd [1] where BPF LSM hooks must resolve a file's backing block
device via inode->i_sb->s_dev. Without looking through overlayfs the
device lookup would return the overlay's anonymous device number instead
of the actual dm-verity block device, causing all overlayfs-hosted
binaries to be incorrectly denied.

Link: https://github.com/systemd/systemd/pull/41340 [1]
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/bpf_fs_kfuncs.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
index e4e51a1d0de2..fc30aa906b8c 100644
--- a/fs/bpf_fs_kfuncs.c
+++ b/fs/bpf_fs_kfuncs.c
@@ -353,6 +353,21 @@ __bpf_kfunc int bpf_cgroup_read_xattr(struct cgroup *cgroup, const char *name__s
 }
 #endif /* CONFIG_CGROUPS */
 
+/**
+ * bpf_real_inode - get the real inode backing a dentry
+ * @dentry: dentry to resolve
+ *
+ * If the dentry is on a union/overlay filesystem, return the underlying, real
+ * inode that hosts the data.  Otherwise return the inode attached to the
+ * dentry itself.
+ *
+ * Return: The real inode backing the dentry.
+ */
+__bpf_kfunc struct inode *bpf_real_inode(struct dentry *dentry)
+{
+	return d_real_inode(dentry);
+}
+
 __bpf_kfunc_end_defs();
 
 BTF_KFUNCS_START(bpf_fs_kfunc_set_ids)
@@ -363,6 +378,7 @@ BTF_ID_FLAGS(func, bpf_get_dentry_xattr, KF_SLEEPABLE)
 BTF_ID_FLAGS(func, bpf_get_file_xattr, KF_SLEEPABLE)
 BTF_ID_FLAGS(func, bpf_set_dentry_xattr, KF_SLEEPABLE)
 BTF_ID_FLAGS(func, bpf_remove_dentry_xattr, KF_SLEEPABLE)
+BTF_ID_FLAGS(func, bpf_real_inode, KF_SLEEPABLE)
 BTF_KFUNCS_END(bpf_fs_kfunc_set_ids)
 
 static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id)

---
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
change-id: 20260326-work-bpf-verity-a43f28baa242


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

end of thread, other threads:[~2026-04-10  7:29 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26 16:53 [PATCH] bpf: add bpf_real_inode() kfunc Christian Brauner
2026-03-26 17:02 ` Amir Goldstein
2026-03-27  5:28 ` Christoph Hellwig
2026-03-27  6:05   ` Darrick J. Wong
2026-04-07 10:25     ` Christian Brauner
2026-04-07 14:54       ` Christoph Hellwig
2026-04-09 13:19         ` Christian Brauner
2026-04-09 14:24           ` Christoph Hellwig
2026-04-09 14:37             ` Gao Xiang
2026-04-09 16:11               ` Christoph Hellwig
2026-04-09 16:42                 ` Gao Xiang
2026-04-10  6:15                   ` Christoph Hellwig
2026-04-10  6:46                     ` Gao Xiang
2026-04-10  7:06                       ` Christoph Hellwig
2026-04-10  7:29                         ` Gao Xiang
2026-03-27 12:19 ` bot+bpf-ci

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