Skip to contentSkip to conversation

ext4: validate xattrs to avoid OOB in ext4_find_inline_entry

PATCH Superseded Raphael Pinsonneault-Thibeault 3 participants 4 messages Nov 8, 2025 – Nov 12, 2025 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: validate xattrs to avoid OOB in ext4_find_inline_entry

When looking for an entry in an inlined directory, if e_value_offs is changed underneath the filesystem by some change in the block device, it will lead to an out-of-bounds access that KASAN detects as a use-after-free.

This is a similar problem as fixed by
commit c6b72f5d82b1 ("ext4: avoid OOB when system.data xattr changes underneath the filesystem") whose fix was to call ext4_xattr_ibody_find() right after reading the
inode with ext4_get_inode_loc() to check the validity of the xattrs.

However, ext4_xattr_ibody_find() only checks xattr names, via xattr_find_entry(), not e_value_offs.

Fix by calling xattr_check_inode() which performs a full check on the xattrs in inode.

Reported-by [email protected]
Fixes c6b72f5d82b10 ("ext4: avoid OOB when system.data xattr changes underneath the filesystem")
---
 fs/ext4/inline.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ext4/inline.c +7 -0
index 1b094a4f3866..7d46e1e16b52 100644
@@ -1593,6 +1593,13 @@ struct buffer_head *ext4_find_inline_entry(struct inode *dir,
 
 	down_read(&EXT4_I(dir)->xattr_sem);
 
+	if (EXT4_INODE_HAS_XATTR_SPACE(dir)) {
+		ret = xattr_check_inode(dir, IHDR(dir, ext4_raw_inode(&is.iloc)),
+					ITAIL(dir, ext4_raw_inode(&is.iloc)));
+		if (ret)
+			goto out;
+	}
+
 	ret = ext4_xattr_ibody_find(dir, &i, &is);
 	if (ret)
 		goto out;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 30 lines · Raphael Pinsonneault-Thibeault

When looking for an entry in an inlined directory, if e_value_offs is changed underneath the filesystem by some change in the block device, it will lead to an out-of-bounds access that KASAN detects as a use-after-free.

This is a similar problem as fixed by
commit c6b72f5d82b1 ("ext4: avoid OOB when system.data xattr changes underneath the filesystem") whose fix was to call ext4_xattr_ibody_find() right after reading the
inode with ext4_get_inode_loc() to check the validity of the xattrs.

However, ext4_xattr_ibody_find() only checks xattr names, via xattr_find_entry(), not e_value_offs.

Fix by calling xattr_check_inode() which performs a full check on the xattrs in inode.

Reported-by [email protected]
Fixes c6b72f5d82b10 ("ext4: avoid OOB when system.data xattr changes underneath the filesystem")
---
 fs/ext4/inline.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ext4/inline.c +0 -0
index 1b094a4f3866..7d46e1e16b52 100644

fs/ext4/inline.c struct buffer_head *ext4_find_inline_entry(struct inode *dir, · line 1602

Quoted 10 lines
fs/ext4/inline.c +7 -0
@@ -1593,6 +1593,13 @@ struct buffer_head *ext4_find_inline_entry(struct inode *dir,
 
 	down_read(&EXT4_I(dir)->xattr_sem);
 
+	if (EXT4_INODE_HAS_XATTR_SPACE(dir)) {
+		ret = xattr_check_inode(dir, IHDR(dir, ext4_raw_inode(&is.iloc)),
+					ITAIL(dir, ext4_raw_inode(&is.iloc)));
+		if (ret)
+			goto out;
+	}
+

ext4_xattr_ibody_find used to call xattr_check_inode until commit 5701875f9609 ("ext4: fix out-of-bound read in ext4_xattr_inode_dec_ref_all()").

So every other place where ext4_xattr_ibody_find was protecting against such block device changes is not working since.

At least, the Fixes: line should change to point out to that commit, but I wonder if the inode checking should be put back there. I haven't investigated if that would regress the bug it fixes, though.

Cascardo.

Quoted 6 lines
fs/ext4/inline.c +0 -0
 	ret = ext4_xattr_ibody_find(dir, &i, &is);
 	if (ret)
 		goto out;
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 1/1 ext4: validate xattrs to avoid OOB in ext4_find_inline_entry

When looking for an entry in an inlined directory, if e_value_offs is changed underneath the filesystem by some change in the block device, it will lead to an out-of-bounds access that KASAN detects as a use-after-free.

This is a similar problem as fixed by
commit c6b72f5d82b1 ("ext4: avoid OOB when system.data xattr changes underneath the filesystem") whose fix was to call ext4_xattr_ibody_find() right after reading the
inode with ext4_get_inode_loc() to check the validity of the xattrs.

However, ext4_xattr_ibody_find() only checks xattr names, via xattr_find_entry(), not e_value_offs.

Fix by calling xattr_check_inode() which performs a full check on the xattrs in inode.

Reported-by [email protected]
Fixes 5701875f9609 ("ext4: fix out-of-bound read in ext4_xattr_inode_dec_ref_all()")

---
changelog
v1 -> v2: change Fixes tag to reflect that ext4_xattr_ibody_find() used to call xattr_check_inode() until 5701875f9609.

 fs/ext4/inline.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ext4/inline.c +7 -0
index 1b094a4f3866..7d46e1e16b52 100644
@@ -1593,6 +1593,13 @@ struct buffer_head *ext4_find_inline_entry(struct inode *dir,
 
 	down_read(&EXT4_I(dir)->xattr_sem);
 
+	if (EXT4_INODE_HAS_XATTR_SPACE(dir)) {
+		ret = xattr_check_inode(dir, IHDR(dir, ext4_raw_inode(&is.iloc)),
+					ITAIL(dir, ext4_raw_inode(&is.iloc)));
+		if (ret)
+			goto out;
+	}
+
 	ret = ext4_xattr_ibody_find(dir, &i, &is);
 	if (ret)
 		goto out;
Signature · 1 line
2.43.0
reviewer
#3 lore raw
Quoted 13 lines · Raphael Pinsonneault-Thibeault

When looking for an entry in an inlined directory, if e_value_offs is changed underneath the filesystem by some change in the block device, it will lead to an out-of-bounds access that KASAN detects as a use-after-free.

This is a similar problem as fixed by
commit c6b72f5d82b1 ("ext4: avoid OOB when system.data xattr changes underneath the filesystem") whose fix was to call ext4_xattr_ibody_find() right after reading the
inode with ext4_get_inode_loc() to check the validity of the xattrs.

However, ext4_xattr_ibody_find() only checks xattr names, via xattr_find_entry(), not e_value_offs.

Quoted 8 lines

Fix by calling xattr_check_inode() which performs a full check on the xattrs in inode.

Reported-by [email protected]
Fixes 5701875f9609 ("ext4: fix out-of-bound read in ext4_xattr_inode_dec_ref_all()")

When the filesystem is mounted on top of a block device, syzbot cannot write to it (it disables CONFIG_BLKDEV_WRITE_MOUNTED option). Also there's no sane way how the filesystem driver could avoid oopses when the block device's buffer cache is modified while the filesystem is mounted without unacceptable slowdown so this patch is pointless in my opinion.

The syzbot reproducer you're referencing actually seems to use LOOP_SET_STATUS ioctl to mess with the loop device while the filesystem is mounted. Understanding what exactly happens there and modifying the loopback device driver to forbid that is in my opinion a more sustainable way to fix problems like this.

Honza

Quoted 29 lines

---
changelog
v1 -> v2: change Fixes tag to reflect that ext4_xattr_ibody_find() used to call xattr_check_inode() until 5701875f9609.

 fs/ext4/inline.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ext4/inline.c +7 -0
index 1b094a4f3866..7d46e1e16b52 100644
@@ -1593,6 +1593,13 @@ struct buffer_head *ext4_find_inline_entry(struct inode *dir,
 
 	down_read(&EXT4_I(dir)->xattr_sem);
 
+	if (EXT4_INODE_HAS_XATTR_SPACE(dir)) {
+		ret = xattr_check_inode(dir, IHDR(dir, ext4_raw_inode(&is.iloc)),
+					ITAIL(dir, ext4_raw_inode(&is.iloc)));
+		if (ret)
+			goto out;
+	}
+
 	ret = ext4_xattr_ibody_find(dir, &i, &is);
 	if (ret)
 		goto out;
Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR