* [PATCH RFC] dcache: permit dynamic_dname()s up to NAME_MAX
@ 2026-03-31 14:46 Aleksa Sarai
2026-03-31 17:50 ` Luca Boccassi
2026-04-07 10:32 ` Christian Brauner
0 siblings, 2 replies; 3+ messages in thread
From: Aleksa Sarai @ 2026-03-31 14:46 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner, Jan Kara, Pratyush Yadav,
Dan Carpenter, Andrew Morton, Pasha Tatashin,
Mike Rapoport (Microsoft),
Eric Dumazet, Christoph Hellwig
Cc: Aleksa Sarai, linux-fsdevel, linux-kernel, Aleksa Sarai
dynamic_dname() has had an implicit limit of 64 characters since it was
introduced in commit c23fbb6bcb3e ("VFS: delay the dentry name
generation on sockets and pipes"), however it seems that this was a
fairly arbitrary number (suspiciously it was double the previously
hardcoded buffer size).
NAME_MAX seems like a more reasonable and consistent limit for d_name
lengths. While we're at it, we can also remove the unnecessary
stack-allocated array and just memmove() the formatted string to the end
of the buffer.
It should also be noted that at least one driver (in particular,
liveupdate's usage of anon_inode for session files) already exceeded
this limit without noticing that readlink(/proc/self/fd/$n) always
returns -ENAMETOOLONG, so this fixes those drivers as well.
Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
Fixes: c23fbb6bcb3e ("VFS: delay the dentry name generation on sockets and pipes")
Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
---
fs/d_path.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/fs/d_path.c b/fs/d_path.c
index bb365511066b..a48957c0971e 100644
--- a/fs/d_path.c
+++ b/fs/d_path.c
@@ -301,18 +301,19 @@ EXPORT_SYMBOL(d_path);
char *dynamic_dname(char *buffer, int buflen, const char *fmt, ...)
{
va_list args;
- char temp[64];
+ char *start;
int sz;
va_start(args, fmt);
- sz = vsnprintf(temp, sizeof(temp), fmt, args) + 1;
+ sz = vsnprintf(buffer, buflen, fmt, args) + 1;
va_end(args);
- if (sz > sizeof(temp) || sz > buflen)
+ if (sz > NAME_MAX || sz > buflen)
return ERR_PTR(-ENAMETOOLONG);
- buffer += buflen - sz;
- return memcpy(buffer, temp, sz);
+ /* Move the formatted d_name to the end of the buffer. */
+ start = buffer + (buflen - sz);
+ return memmove(start, buffer, sz);
}
char *simple_dname(struct dentry *dentry, char *buffer, int buflen)
---
base-commit: 84f524dca4b8bc9e9aca8ea1dbbd2aa3a239d998
change-id: 20260401-dynamic-dname-name_max-8d14dcb9acd0
Kind regards,
--
Aleksa Sarai
https://www.cyphar.com/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RFC] dcache: permit dynamic_dname()s up to NAME_MAX
2026-03-31 14:46 [PATCH RFC] dcache: permit dynamic_dname()s up to NAME_MAX Aleksa Sarai
@ 2026-03-31 17:50 ` Luca Boccassi
2026-04-07 10:32 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Luca Boccassi @ 2026-03-31 17:50 UTC (permalink / raw)
To: Aleksa Sarai; +Cc: Christian Brauner, linux-fsdevel, linux-kernel
On Tue, 31 Mar 2026 at 15:46, Aleksa Sarai <aleksa@amutable.com> wrote:
>
> dynamic_dname() has had an implicit limit of 64 characters since it was
> introduced in commit c23fbb6bcb3e ("VFS: delay the dentry name
> generation on sockets and pipes"), however it seems that this was a
> fairly arbitrary number (suspiciously it was double the previously
> hardcoded buffer size).
>
> NAME_MAX seems like a more reasonable and consistent limit for d_name
> lengths. While we're at it, we can also remove the unnecessary
> stack-allocated array and just memmove() the formatted string to the end
> of the buffer.
>
> It should also be noted that at least one driver (in particular,
> liveupdate's usage of anon_inode for session files) already exceeded
> this limit without noticing that readlink(/proc/self/fd/$n) always
> returns -ENAMETOOLONG, so this fixes those drivers as well.
>
> Fixes: 0153094d03df ("liveupdate: luo_session: add sessions support")
> Fixes: c23fbb6bcb3e ("VFS: delay the dentry name generation on sockets and pipes")
> Signed-off-by: Aleksa Sarai <aleksa@amutable.com>
> ---
> fs/d_path.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
Tested-by: Luca Boccassi <luca.boccassi@gmail.com>
Thanks, works nicely, tested on top of 7.0-rc5
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RFC] dcache: permit dynamic_dname()s up to NAME_MAX
2026-03-31 14:46 [PATCH RFC] dcache: permit dynamic_dname()s up to NAME_MAX Aleksa Sarai
2026-03-31 17:50 ` Luca Boccassi
@ 2026-04-07 10:32 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2026-04-07 10:32 UTC (permalink / raw)
To: Aleksa Sarai
Cc: Christian Brauner, Alexander Viro, Jan Kara, Pratyush Yadav,
Dan Carpenter, Andrew Morton, Pasha Tatashin,
Mike Rapoport (Microsoft),
Eric Dumazet, Christoph Hellwig, Aleksa Sarai, linux-fsdevel,
linux-kernel
On Wed, 01 Apr 2026 01:46:21 +1100, Aleksa Sarai wrote:
> dynamic_dname() has had an implicit limit of 64 characters since it was
> introduced in commit c23fbb6bcb3e ("VFS: delay the dentry name
> generation on sockets and pipes"), however it seems that this was a
> fairly arbitrary number (suspiciously it was double the previously
> hardcoded buffer size).
>
> NAME_MAX seems like a more reasonable and consistent limit for d_name
> lengths. While we're at it, we can also remove the unnecessary
> stack-allocated array and just memmove() the formatted string to the end
> of the buffer.
>
> [...]
Applied to the vfs-7.1.misc branch of the vfs/vfs.git tree.
Patches in the vfs-7.1.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.1.misc
[1/1] dcache: permit dynamic_dname()s up to NAME_MAX
https://git.kernel.org/vfs/vfs/c/97b67e64affb
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-07 10:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-31 14:46 [PATCH RFC] dcache: permit dynamic_dname()s up to NAME_MAX Aleksa Sarai
2026-03-31 17:50 ` Luca Boccassi
2026-04-07 10:32 ` 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®