Skip to contentSkip to conversation

ext4: xattr: fix null pointer deref in ext4_raw_inode()

PATCH Applied Karina Yankevich 4 participants 4 messages Oct 22, 2025 – Nov 17, 2025 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: xattr: fix null pointer deref in ext4_raw_inode()

If ext4_get_inode_loc() fails (e.g. if it returns -EFSCORRUPTED), iloc.bh will remain set to NULL. Since ext4_xattr_inode_dec_ref_all() lacks error checking, this will lead to a null pointer dereference in ext4_raw_inode(), called right after ext4_get_inode_loc().

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes c8e008b60492 ("ext4: ignore xattrs past end")
---
 fs/ext4/xattr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ext4/xattr.c +5 -1
index ce7253b3f549..2e02efbddaac 100644
@@ -1174,7 +1174,11 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
 	if (block_csum)
 		end = (void *)bh->b_data + bh->b_size;
 	else {
-		ext4_get_inode_loc(parent, &iloc);
+		err = ext4_get_inode_loc(parent, &iloc);
+		if (err) {
+			EXT4_ERROR_INODE(parent, "parent inode loc (error %d)", err);
+			return;
+		}
 		end = (void *)ext4_raw_inode(&iloc) + EXT4_SB(parent->i_sb)->s_inode_size;
 	}
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Karina Yankevich
Quoted 10 lines · Karina Yankevich

If ext4_get_inode_loc() fails (e.g. if it returns -EFSCORRUPTED), iloc.bh will remain set to NULL. Since ext4_xattr_inode_dec_ref_all() lacks error checking, this will lead to a null pointer dereference in ext4_raw_inode(), called right after ext4_get_inode_loc().

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes c8e008b60492 ("ext4: ignore xattrs past end")

An error return at this point may lead to an inconsistent ea_inode reference count. However, since the caller ext4_xattr_delete_inode() has already loaded iloc.bh via ext4_get_inode_loc(), this almost never fails.

Quoted 21 lines
---
 fs/ext4/xattr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ext4/xattr.c +5 -1
index ce7253b3f549..2e02efbddaac 100644
@@ -1174,7 +1174,11 @@ ext4_xattr_inode_dec_ref_all(handle_t *handle, struct inode *parent,
 	if (block_csum)
 		end = (void *)bh->b_data + bh->b_size;
 	else {
-		ext4_get_inode_loc(parent, &iloc);
+		err = ext4_get_inode_loc(parent, &iloc);
+		if (err) {
+			EXT4_ERROR_INODE(parent, "parent inode loc (error %d)", err);
+			return;
+		}
 		end = (void *)ext4_raw_inode(&iloc) + EXT4_SB(parent->i_sb)->s_inode_size;
 	}
 
maintainer Applied
#3 lore raw
In reply to Karina Yankevich
Quoted 8 lines · Karina Yankevich

If ext4_get_inode_loc() fails (e.g. if it returns -EFSCORRUPTED), iloc.bh will remain set to NULL. Since ext4_xattr_inode_dec_ref_all() lacks error checking, this will lead to a null pointer dereference in ext4_raw_inode(), called right after ext4_get_inode_loc().

Found by Linux Verification Center (linuxtesting.org) with SVACE.

[...]

Applied, thanks!

[1/1] ext4: xattr: fix null pointer deref in ext4_raw_inode()

      commit: b97cb7d6a051aa6ebd57906df0e26e9e36c26d14

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>