proc: use strnlen() for name validation in __proc_create

Replace strlen(fn) with strnlen(fn, NAME_MAX + 1) when validating the
final path component in __proc_create().

This preserves the existing name limit while bounding the length scan to
one byte past the maximum name length.  Handle empty names separately, and
treat names longer than NAME_MAX as too long.

Link: https://lore.kernel.org/[email protected]
Signed-off-by: Thorsten Blum <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Thorsten Blum <[email protected]>
Cc: wangzijie <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
This commit is contained in:
Thorsten Blum authored and Andrew Morton committed 2026-05-28 21:24:39 -07:00
1 parent b8979a02f9
commit de5d0652d0
1 file changed
+7 -3
+7 -3
View File
@@ -427,9 +427,13 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
if (xlate_proc_name(name, parent, &fn) != 0)
goto out;
qstr.name = fn;
qstr.len = strlen(fn);
if (qstr.len == 0 || qstr.len >= 256) {
WARN(1, "name len %u\n", qstr.len);
qstr.len = strnlen(fn, NAME_MAX + 1);
if (qstr.len == 0) {
WARN(1, "empty name\n");
return NULL;
}
if (qstr.len > NAME_MAX) {
WARN(1, "name too long\n");
return NULL;
}
if (qstr.len == 1 && fn[0] == '.') {