From: Thorsten Blum <thorsten.blum@linux.dev>
To: Andrew Morton <akpm@linux-foundation.org>,
wangzijie <wangzijie1@honor.com>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Alexey Dobriyan <adobriyan@gmail.com>,
Wei Yang <albinwyang@tencent.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>, Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH] proc: use strnlen() for name validation in __proc_create
Date: Tue, 21 Apr 2026 14:26:47 +0200 [thread overview]
Message-ID: <20260421122648.56723-2-thorsten.blum@linux.dev> (raw)
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.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
fs/proc/generic.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 8bb81e58c9d8..3063080f3bb2 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -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] == '.') {
next reply other threads:[~2026-04-21 12:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 12:26 Thorsten Blum [this message]
2026-04-21 12:39 ` [PATCH] proc: use strnlen() for name validation in __proc_create Jan Kara
2026-04-21 13:02 ` Alexey Dobriyan
2026-04-21 14:17 ` Thorsten Blum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260421122648.56723-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=albinwyang@tencent.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=wangzijie1@honor.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.