Re: [PATCH 1/2] hfs: abort hfs_lookup if name is too long
From: Viacheslav Dubeyko
Date: Fri Aug 08 2025 - 18:05:41 EST
On Wed, 2025-08-06 at 11:11 -0600, Yangtao Li wrote:
> Long file names for hfs is 31 characters.
>
Could this max name length affects the xfstests in the case if we
finally restricts the creation of files/folders with longer names?
> Signed-off-by: Yangtao Li <frank.li@xxxxxxxx>
> ---
> fs/hfs/dir.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/hfs/dir.c b/fs/hfs/dir.c
> index 86a6b317b474..30f6194da939 100644
> --- a/fs/hfs/dir.c
> +++ b/fs/hfs/dir.c
> @@ -25,6 +25,9 @@ static struct dentry *hfs_lookup(struct inode *dir,
> struct dentry *dentry,
> struct inode *inode = NULL;
> int res;
>
> + if (dentry->d_name.len > HFS_NAMELEN)
> + return ERR_PTR(-ENAMETOOLONG);
> +
I think it makes sense to follow the HFS+ logic. We need to rework
hfs_cat_build_key() [1, 2] and hfs_asc2mac() [3]. It already operates
by -ENAMETOOLONG [4] but it is not we would like to have.
Thanks,
Slava.
> res = hfs_find_init(HFS_SB(dir->i_sb)->cat_tree, &fd);
> if (res)
> return ERR_PTR(res);
[1] https://elixir.bootlin.com/linux/v6.16/source/fs/hfs/dir.c#L31
[2] https://elixir.bootlin.com/linux/v6.16/source/fs/hfs/catalog.c#L28
[3] https://elixir.bootlin.com/linux/v6.16/source/fs/hfs/trans.c#L97
[4] https://elixir.bootlin.com/linux/v6.16/source/fs/hfs/trans.c#L125