From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 1/6] fs: skip directory entries whose name does not fit struct dirent
Date: Fri, 2 Oct 2026 13:40:04 +0200 [thread overview]
Message-ID: <20261002114253.2906535-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20261002114253.2906535-1-a.fatoum@pengutronix.de>
From: Ahmad Fatoum <a.fatoum@barebox.org>
fillonedir() copies whatever name length the file system reports into
the fixed 256 byte d_name of struct dirent. A longer name overruns the
heap allocation and a 256 byte one is left without a terminating NUL.
Such names do exist: ubootvarfs lists U-Boot environment variables,
whose names have no length limit and come from a medium the OS can
rewrite, and ramfs accepts file names of any length. An environment
with a 300 byte variable name corrupts the heap as soon as the
directory is listed.
Let's skip these entries with a warning instead. The rest of the
directory is still listed and the file remains accessible by name.
Fixes: b3fbfad7aeaf ("fs: dentry cache implementation")
Assisted-by: Claude:opus-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
fs/fs.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index 1426ce4bc883..e18e3b9cd7b2 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1088,6 +1088,11 @@ static int fillonedir(struct dir_context *ctx, const char *name, int namlen,
struct readdir_callback *rd = container_of(ctx, struct readdir_callback, ctx);
struct readdir_entry *entry;
+ if (namlen >= sizeof(entry->d.d_name)) {
+ pr_warn("skipping directory entry %.32s...: name too long\n", name);
+ return 0;
+ }
+
entry = xzalloc(sizeof(*entry));
memcpy(entry->d.d_name, name, namlen);
list_add_tail(&entry->list, &rd->dir->entries);
--
2.47.3
next prev parent reply other threads:[~2026-10-02 13:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 11:40 [PATCH 0/6] fs: ubootvarfs: harden parser Ahmad Fatoum
2026-10-02 11:40 ` Ahmad Fatoum [this message]
2026-10-02 11:40 ` [PATCH 2/6] fs: reject negative lengths in ftruncate() Ahmad Fatoum
2026-10-02 11:40 ` [PATCH 3/6] fs: ubootvarfs: range-check the new size in truncate Ahmad Fatoum
2026-10-02 11:40 ` [PATCH 4/6] fs: ubootvarfs: do not form pointers past the end of the environment Ahmad Fatoum
2026-10-02 11:40 ` [PATCH 5/6] fs: ubootvarfs: reject variable names containing '=' Ahmad Fatoum
2026-10-02 11:40 ` [PATCH 6/6] fs: ubootvarfs: handle removal of variables that are still open Ahmad Fatoum
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=20261002114253.2906535-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox