mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] bpf: have bpf_real_inode() take a struct file
@ 2026-06-22 13:58 Christian Brauner
  2026-06-22 17:15 ` Amir Goldstein
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2026-06-22 13:58 UTC (permalink / raw)
  To: bpf
  Cc: Alexander Viro, Christian Brauner, Jan Kara, Amir Goldstein,
	linux-fsdevel, linux-kernel

bpf_real_inode() must be usable from the bprm_check_security, mmap_file
and file_mprotect hooks for systemd's RestrictFilesystemAccess BPF LSM
program. It should take a file instead. The kfunc landed this cycle so
changing the signature is safe.

Fixes: 9af8c8a54f6e ("bpf: add bpf_real_inode() kfunc")
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/bpf_fs_kfuncs.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
index 768aca2dc0f0..f941c29d26ef 100644
--- a/fs/bpf_fs_kfuncs.c
+++ b/fs/bpf_fs_kfuncs.c
@@ -360,18 +360,18 @@ __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
+ * bpf_real_inode - get the real inode backing a file
+ * @file: file to resolve
  *
- * If the dentry is on a union/overlay filesystem, return the underlying, real
+ * If the file is on a union/overlay filesystem, return the underlying, real
  * inode that hosts the data.  Otherwise return the inode attached to the
- * dentry itself.
+ * file itself.
  *
- * Return: The real inode backing the dentry, or NULL for a negative dentry.
+ * Return: The real inode backing the file, or NULL.
  */
-__bpf_kfunc struct inode *bpf_real_inode(struct dentry *dentry)
+__bpf_kfunc struct inode *bpf_real_inode(struct file *file)
 {
-	return d_real_inode(dentry);
+	return d_real_inode(file_dentry(file));
 }
 
 __bpf_kfunc_end_defs();

---
base-commit: 5b33fc6492a7b7a62359157db0f92f5b6e9af690
change-id: 20260622-work-bpf-real_inode-c3202dbaf0ab


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

* Re: [PATCH] bpf: have bpf_real_inode() take a struct file
  2026-06-22 13:58 [PATCH] bpf: have bpf_real_inode() take a struct file Christian Brauner
@ 2026-06-22 17:15 ` Amir Goldstein
  2026-06-23  8:44   ` Christian Brauner
  0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2026-06-22 17:15 UTC (permalink / raw)
  To: Christian Brauner
  Cc: bpf, Alexander Viro, Jan Kara, linux-fsdevel, linux-kernel

On Mon, Jun 22, 2026 at 3:58 PM Christian Brauner <brauner@kernel.org> wrote:
>
> bpf_real_inode() must be usable from the bprm_check_security, mmap_file
> and file_mprotect hooks for systemd's RestrictFilesystemAccess BPF LSM
> program. It should take a file instead. The kfunc landed this cycle so
> changing the signature is safe.
>
> Fixes: 9af8c8a54f6e ("bpf: add bpf_real_inode() kfunc")
> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
> ---
>  fs/bpf_fs_kfuncs.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
> index 768aca2dc0f0..f941c29d26ef 100644
> --- a/fs/bpf_fs_kfuncs.c
> +++ b/fs/bpf_fs_kfuncs.c
> @@ -360,18 +360,18 @@ __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
> + * bpf_real_inode - get the real inode backing a file
> + * @file: file to resolve
>   *
> - * If the dentry is on a union/overlay filesystem, return the underlying, real
> + * If the file is on a union/overlay filesystem, return the underlying, real
>   * inode that hosts the data.  Otherwise return the inode attached to the
> - * dentry itself.
> + * file itself.
>   *
> - * Return: The real inode backing the dentry, or NULL for a negative dentry.
> + * Return: The real inode backing the file, or NULL.
>   */
> -__bpf_kfunc struct inode *bpf_real_inode(struct dentry *dentry)
> +__bpf_kfunc struct inode *bpf_real_inode(struct file *file)
>  {
> -       return d_real_inode(dentry);
> +       return d_real_inode(file_dentry(file));
>  }

The problem with this API is that for special files it is a bit ambiguous
to say "the real inode backing the file".
Is it d_real_inode(file_dentry(file))? or is it file_inode(file)?
The old API avoided this question.
BTW, did you notice that for non-regular files, this helper returns
the overlayfs inode?
This may be important information to document when exporting a kfunc.

If you take my suggestion from the previous round to name the kfunc
bpf_real_data_inode(struct file *file)
the intention becomes a little (bit) less ambiguous. huh?

Thanks,
Amir.

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

* Re: [PATCH] bpf: have bpf_real_inode() take a struct file
  2026-06-22 17:15 ` Amir Goldstein
@ 2026-06-23  8:44   ` Christian Brauner
  0 siblings, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2026-06-23  8:44 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Christian Brauner, bpf, Alexander Viro, Jan Kara, linux-fsdevel,
	linux-kernel

On 2026-06-22 19:15 +0200, Amir Goldstein wrote:
> On Mon, Jun 22, 2026 at 3:58 PM Christian Brauner <brauner@kernel.org> wrote:
> >
> > bpf_real_inode() must be usable from the bprm_check_security, mmap_file
> > and file_mprotect hooks for systemd's RestrictFilesystemAccess BPF LSM
> > program. It should take a file instead. The kfunc landed this cycle so
> > changing the signature is safe.
> >
> > Fixes: 9af8c8a54f6e ("bpf: add bpf_real_inode() kfunc")
> > Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
> > ---
> >  fs/bpf_fs_kfuncs.c | 14 +++++++-------
> >  1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
> > index 768aca2dc0f0..f941c29d26ef 100644
> > --- a/fs/bpf_fs_kfuncs.c
> > +++ b/fs/bpf_fs_kfuncs.c
> > @@ -360,18 +360,18 @@ __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
> > + * bpf_real_inode - get the real inode backing a file
> > + * @file: file to resolve
> >   *
> > - * If the dentry is on a union/overlay filesystem, return the underlying, real
> > + * If the file is on a union/overlay filesystem, return the underlying, real
> >   * inode that hosts the data.  Otherwise return the inode attached to the
> > - * dentry itself.
> > + * file itself.
> >   *
> > - * Return: The real inode backing the dentry, or NULL for a negative dentry.
> > + * Return: The real inode backing the file, or NULL.
> >   */
> > -__bpf_kfunc struct inode *bpf_real_inode(struct dentry *dentry)
> > +__bpf_kfunc struct inode *bpf_real_inode(struct file *file)
> >  {
> > -       return d_real_inode(dentry);
> > +       return d_real_inode(file_dentry(file));
> >  }
> 
> The problem with this API is that for special files it is a bit ambiguous
> to say "the real inode backing the file".
> Is it d_real_inode(file_dentry(file))? or is it file_inode(file)?
> The old API avoided this question.
> BTW, did you notice that for non-regular files, this helper returns
> the overlayfs inode?

Yes. Very aware.

> This may be important information to document when exporting a kfunc.

Ok.

> If you take my suggestion from the previous round to name the kfunc
> bpf_real_data_inode(struct file *file)
> the intention becomes a little (bit) less ambiguous. huh?

I don't remember that suggestion. Maybe I missed this. I like it!
Let me send a new version.


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

end of thread, other threads:[~2026-06-23  8:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-22 13:58 [PATCH] bpf: have bpf_real_inode() take a struct file Christian Brauner
2026-06-22 17:15 ` Amir Goldstein
2026-06-23  8:44   ` Christian Brauner

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

all inboxes | Powered by JetHome®