From: Samuel Moelius <sam.moelius@trailofbits.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Samuel Moelius <sam.moelius@trailofbits.com>,
Chao Yu <chao@kernel.org>,
linux-f2fs-devel@lists.sourceforge.net (open list:F2FS FILE
SYSTEM), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] f2fs: validate dentry name length before lookup compares it
Date: Wed, 3 Jun 2026 16:11:26 +0000 [thread overview]
Message-ID: <20260603161127.17464-1-sam.moelius@trailofbits.com> (raw)
The f2fs dentry lookup path can use the on-disk name length before
checking that the name fits in the dentry filename area. A corrupted
dentry can then make lookup read beyond the filename slots.
The bounds check needs to happen before any comparison that consumes
the name length from disk.
Reject dentries with invalid name lengths before comparing their names.
Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
fs/f2fs/dir.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 38802ee2e40d..14161d5a1af0 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -249,6 +249,11 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d,
continue;
}
+ if (unlikely(le16_to_cpu(de->name_len) > F2FS_NAME_LEN ||
+ bit_pos + GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)) >
+ d->max))
+ return ERR_PTR(-EFSCORRUPTED);
+
if (!use_hash || de->hash_code == fname->hash) {
res = f2fs_match_name(d->inode, fname,
d->filename[bit_pos],
--
2.43.0
next reply other threads:[~2026-06-03 16:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 16:11 Samuel Moelius [this message]
2026-06-15 3:16 ` Chao Yu
2026-06-16 2:50 ` [f2fs-dev] " patchwork-bot+f2fs
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=20260603161127.17464-1-sam.moelius@trailofbits.com \
--to=sam.moelius@trailofbits.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®