Re: [PATCH 10/13] ovl: return the error from the lazy lowerdata lookup in ovl_d_real()
From: Amir Goldstein
Date: Sun Nov 15 2026 - 09:48:07 EST
On Sun, Nov 15, 2026 at 3:02 PM Christian Brauner <brauner@xxxxxxxxxx> wrote:
>
> All callers have been converted to d_real_data_inode() and handle an
> error now. So return the error from ovl_verify_lowerdata() just like
> ovl_open() does. The lowerdata dentry missing after a successful
> ovl_verify_lowerdata() would be an overlayfs bug, so keep warning about
> that but return -EIO like ovl_open() does when it has no real path.
> D_REAL_METADATA never looks anything up and still can't fail.
>
> Update the comment in ovl_d_real() and the documentation of d_real() in
> dcache.h and vfs.rst accordingly.
>
> Suggested-by: Amir Goldstein <amir73il@xxxxxxxxx>
> Link: https://lore.kernel.org/all/CAOQ4uxhGxpBtMZ5kfuzR1tQAewiecoX7UjXQRo91QjJHH9T_Yw@xxxxxxxxxxxxxx
> Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
Nice!
Thanks for cleaning up this mess.
Reviewed-by: Amir Goldstein <amir73il@xxxxxxxxx>
> ---
> Documentation/filesystems/vfs.rst | 6 ++++++
> fs/overlayfs/super.c | 17 +++++++++--------
> include/linux/dcache.h | 6 ++++++
> 3 files changed, 21 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst
> index 1824462a43711..6953f399672f3 100644
> --- a/Documentation/filesystems/vfs.rst
> +++ b/Documentation/filesystems/vfs.rst
> @@ -1374,6 +1374,12 @@ defined:
> for returning the real underlying dentry that refers to the inode
> hosting the file's data or metadata respectively.
>
> + For D_REAL_DATA the filesystem may have to look up the data first,
> + e.g., for a file that was never opened. If that fails an ERR_PTR()
> + is returned and callers must handle it. D_REAL_METADATA must not
> + fail. Most callers should use d_real_data_inode() or
> + d_real_metadata_inode() instead of calling d_real() directly.
> +
> For non-regular files, the 'dentry' argument is returned.
>
> ``d_unalias_trylock``
> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> index 1985b553a47b7..39d4d57dec230 100644
> --- a/fs/overlayfs/super.c
> +++ b/fs/overlayfs/super.c
> @@ -42,7 +42,7 @@ static struct dentry *ovl_d_real(struct dentry *dentry, enum d_real_type type)
> }
>
> if (!d_is_reg(dentry)) {
> - /* d_real_inode() is only relevant for regular files */
> + /* d_real() is only relevant for regular files */
> return dentry;
> }
>
> @@ -57,17 +57,18 @@ static struct dentry *ovl_d_real(struct dentry *dentry, enum d_real_type type)
> }
>
> /*
> - * Best effort lazy lookup of lowerdata for D_REAL_DATA case to return
> - * the real lowerdata dentry. Callers may ask for files that were never
> - * opened, e.g. for uprobes or O_PATH files, so the lookup can fail
> - * here. Return the overlayfs dentry then.
> + * Lazy lookup of lowerdata for the D_REAL_DATA case to return the real
> + * lowerdata dentry. Callers may ask for files that were never opened,
> + * e.g., for uprobes or O_PATH files, and the lookup or the verity
> + * validation can fail. Return the error then, just like ovl_open()
> + * would. Callers of d_real() have to deal with that.
> */
> err = ovl_verify_lowerdata(dentry);
> if (err)
> - return dentry;
> + return ERR_PTR(err);
> lower = ovl_dentry_lowerdata(dentry);
> - if (!lower)
> - goto bug;
> + if (WARN_ON_ONCE(!lower))
> + return ERR_PTR(-EIO);
>
> real_lower:
> /* Handle recursion into stacked lower fs */
> diff --git a/include/linux/dcache.h b/include/linux/dcache.h
> index 674bc50b81827..5b3b34d271bd0 100644
> --- a/include/linux/dcache.h
> +++ b/include/linux/dcache.h
> @@ -638,7 +638,13 @@ static inline struct inode *d_backing_inode(const struct dentry *upper)
> * If dentry is on a union/overlay, then return the underlying, real dentry.
> * Otherwise return the dentry itself.
> *
> + * For D_REAL_DATA the union/overlay may have to look up the data first. This
> + * can sleep and it can fail. D_REAL_METADATA never fails.
> + *
> * See also: Documentation/filesystems/vfs.rst
> + *
> + * Return: The real dentry, or an ERR_PTR() for D_REAL_DATA if the data can't
> + * be resolved.
> */
> static inline struct dentry *d_real(struct dentry *dentry, enum d_real_type type)
> {
>
> --
> 2.53.0
>