[RFC] bpf: Is an open-coded bpf_iter_mount kfunc wanted?
From: Abhishek Khade
Date: Fri Nov 27 2026 - 05:16:53 EST
Hi all,
Before writing any code, I wanted to check if there is interest in an
open-coded BPF iterator for struct mnt_namespace mounts
(bpf_iter_mount_{new,next,destroy}).
I tested doing this without a kfunc in a BPF program first:
- Using bpf_probe_read_kernel() + bpf_for(), a BPF program can walk
ns->mounts (rb_node) and read scalar fields like mnt_id and
mnt_flags, though without namespace_sem protection.
- However, pointers obtained via bpf_probe_read_kernel() become
untrusted scalars, so the verifier rejects passing them to VFS kfuncs
such as bpf_path_d_path() or bpf_get_dentry_xattr().
If an open-coded sleepable iterator (taking namespace_sem during step
lookup and returning a trusted struct vfsmount * or struct path) would
be useful for BPF LSM / tracing use cases, I would be happy to work on
an RFC patch and selftests. If bpf_probe_read_kernel() or userspace
listmount() is preferred instead, please let me know.
Thanks,
Abhishek Khade