Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

dcache: permit dynamic_dname()s up to NAME_MAX

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>
Link: https://patch.msgid.link/20260401-dynamic-dname-name_max-v1-1-8ca20ab2642e@amutable.com
Tested-by: Luca Boccassi <luca.boccassi@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Aleksa Sarai and committed by
Christian Brauner
97b67e64 4639f1cf

+6 -5
+6 -5
fs/d_path.c
··· 301 301 char *dynamic_dname(char *buffer, int buflen, const char *fmt, ...) 302 302 { 303 303 va_list args; 304 - char temp[64]; 304 + char *start; 305 305 int sz; 306 306 307 307 va_start(args, fmt); 308 - sz = vsnprintf(temp, sizeof(temp), fmt, args) + 1; 308 + sz = vsnprintf(buffer, buflen, fmt, args) + 1; 309 309 va_end(args); 310 310 311 - if (sz > sizeof(temp) || sz > buflen) 311 + if (sz > NAME_MAX || sz > buflen) 312 312 return ERR_PTR(-ENAMETOOLONG); 313 313 314 - buffer += buflen - sz; 315 - return memcpy(buffer, temp, sz); 314 + /* Move the formatted d_name to the end of the buffer. */ 315 + start = buffer + (buflen - sz); 316 + return memmove(start, buffer, sz); 316 317 } 317 318 318 319 char *simple_dname(struct dentry *dentry, char *buffer, int buflen)