Skip to contentSkip to conversation

f2fs: validate inline dentry name lengths before conversion

PATCH In review Samuel Moelius 3 participants 4 messages Jun 3 – Jun 16 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: validate inline dentry name lengths before conversion

Inline dentry conversion copies names out of the inline dentry area before checking that each recorded name length fits in the available filename slots.

A corrupted image can therefore make the conversion path read past the inline filename storage while building the regular dentry block.

Validate each inline dentry name length against the inline filename area before copying it.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 fs/f2fs/inline.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/f2fs/inline.c +4 -0
index 7aabfc9b43cb..4584dfbe3fb8 100644
@@ -507,6 +507,10 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
 			bit_pos++;
 			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 -EFSCORRUPTED;
 
 		/*
 		 * We only need the disk_name and hash to move the dentry.
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 21 lines · Samuel Moelius

Inline dentry conversion copies names out of the inline dentry area before checking that each recorded name length fits in the available filename slots.

A corrupted image can therefore make the conversion path read past the inline filename storage while building the regular dentry block.

Validate each inline dentry name length against the inline filename area before copying it.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 fs/f2fs/inline.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/f2fs/inline.c +0 -0
index 7aabfc9b43cb..4584dfbe3fb8 100644

fs/f2fs/inline.c static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) · line 513

Quoted 7 lines
fs/f2fs/inline.c +4 -0
@@ -507,6 +507,10 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
 			bit_pos++;
 			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 -EFSCORRUPTED;
	err = -EFSCORRUPTED;
	goto punch_dentry_pages;

Thanks,

Quoted 3 lines
fs/f2fs/inline.c +0 -0
 		/*
 		 * We only need the disk_name and hash to move the dentry.
maintainer
#2 lore raw
Quoted 17 lines · Chao Yu
Quoted 16 lines · Samuel Moelius

Inline dentry conversion copies names out of the inline dentry area before checking that each recorded name length fits in the available filename slots.

A corrupted image can therefore make the conversion path read past the inline filename storage while building the regular dentry block.

Validate each inline dentry name length against the inline filename area before copying it.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 fs/f2fs/inline.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 15 lines

fs/f2fs/inline.c static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) · line 513

Quoted 12 lines
fs/f2fs/inline.c +4 -0
index 7aabfc9b43cb..4584dfbe3fb8 100644
@@ -507,6 +507,10 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
 			bit_pos++;
 			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 -EFSCORRUPTED;
	err = -EFSCORRUPTED;
	goto punch_dentry_pages;

Applied with it.

Quoted 7 lines

Thanks,

Quoted 3 lines
fs/f2fs/inline.c +0 -0
 		/*
 		 * We only need the disk_name and hash to move the dentry.
maintainer Reviewed-by
#3 lore raw
Quoted 34 lines · Jaegeuk Kim
Quoted 17 lines · Chao Yu
Quoted 16 lines · Samuel Moelius

Inline dentry conversion copies names out of the inline dentry area before checking that each recorded name length fits in the available filename slots.

A corrupted image can therefore make the conversion path read past the inline filename storage while building the regular dentry block.

Validate each inline dentry name length against the inline filename area before copying it.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 fs/f2fs/inline.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 15 lines

fs/f2fs/inline.c static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) · line 513

Quoted 12 lines
fs/f2fs/inline.c +4 -0
index 7aabfc9b43cb..4584dfbe3fb8 100644
@@ -507,6 +507,10 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
 			bit_pos++;
 			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 -EFSCORRUPTED;
	err = -EFSCORRUPTED;
	goto punch_dentry_pages;
Quoted 1 line

Applied with it.

Thanks,

Quoted 8 lines
Quoted 8 lines

Thanks,

Quoted 3 lines
fs/f2fs/inline.c +0 -0
 		/*
 		 * We only need the disk_name and hash to move the dentry.