Skip to contentSkip to conversation

f2fs: validate dentry name length before lookup compares it

PATCH Applied Samuel Moelius 3 participants 3 messages Jun 3 – Jun 16 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: validate dentry name length before lookup compares it

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
---
 fs/f2fs/dir.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/f2fs/dir.c +5 -0
index 38802ee2e40d..14161d5a1af0 100644
@@ -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],
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Samuel Moelius

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.

Will be better to merge two patch into one:

f2fs: validate inline dentry name lengths before conversion
f2fs: validate dentry name length before lookup compares it

Quoted 3 lines
Assisted-by Codex:gpt-5.5-cyber-preview

Anyway, this patch looks good to me.

Thanks,

#2 lore raw
In reply to Samuel Moelius
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:

Quoted 8 lines · On Wed, 3 Jun 2026 16:11:26 +0000 you wrote:

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.

[...]

Here is the summary with links:
- [f2fs-dev] f2fs: validate dentry name length before lookup compares it

    https://git.kernel.org/jaegeuk/f2fs/c/d6d43742e65d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html