Re: [PATCH v3] ntfs: validate error codes from untrusted disk data

From: Namjae Jeon

Date: Wed Jul 01 2026 - 03:25:53 EST


> diff --git a/fs/ntfs/namei.c b/fs/ntfs/namei.c
> index a19626a135bd..5229522b29ba 100644
> --- a/fs/ntfs/namei.c
> +++ b/fs/ntfs/namei.c
> @@ -233,9 +233,17 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent,
> ntfs_debug("Done.");
> return d_splice_alias(NULL, dent);
> }
> - ntfs_error(vol->sb, "ntfs_lookup_ino_by_name() failed with error code %i.",
> - -MREF_ERR(mref));
> - return ERR_PTR(MREF_ERR(mref));
> +
> + long err = MREF_ERR(mref);
I prefer declaring all local variables at the beginning of the function.
> +
> + if (err < 0 && err >= -MAX_ERRNO) {
> + ntfs_error(vol->sb, "ntfs_lookup_ino_by_name() failed with error code %li.",
> + err);
> + return ERR_PTR(err);
> + }
> + ntfs_error(vol->sb, "ntfs_lookup_ino_by_name() returned invalid error code %li, treating as disk corruption.",
> + err);
WARNING: line length of 118 exceeds 100 columns
#108: FILE: fs/ntfs/namei.c:244:
+ ntfs_error(vol->sb, "ntfs_lookup_ino_by_name() returned invalid
error code %li, treating as disk corruption.",

Thanks.