Skip to contentSkip to conversation

ext4: Avoid writing unitialized memory to disk in EA inodes

PATCH Applied Jan Kara 2 participants 2 messages Jun 13, 2024 – Jul 11, 2024 ext4 file system

lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 ext4: Avoid writing unitialized memory to disk in EA inodes

If the extended attribute size is not a multiple of block size, the last block in the EA inode will have uninitialized tail which will get written to disk. We will never expose the data to userspace but still this is not a good practice so just zero out the tail of the block as it isn't going to cause a noticeable performance overhead.

Fixes e50e5129f384 ("ext4: xattr-in-inode support")
Reported-by [email protected]
---
 fs/ext4/xattr.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/ext4/xattr.c +6 -0
index 6460879b9fcb..46ce2f21fef9 100644
@@ -1433,6 +1433,12 @@ static int ext4_xattr_inode_write(handle_t *handle, struct inode *ea_inode,
 			goto out;
 
 		memcpy(bh->b_data, buf, csize);
+		/*
+		 * Zero out block tail to avoid writing uninitialized memory
+		 * to disk.
+		 */
+		if (csize < blocksize)
+			memset(bh->b_data + csize, 0, blocksize - csize);
 		set_buffer_uptodate(bh);
 		ext4_handle_dirty_metadata(handle, ea_inode, bh);
 
Signature · 1 line
2.35.3
maintainer Applied
#1 lore raw
Quoted 8 lines · Jan Kara

If the extended attribute size is not a multiple of block size, the last block in the EA inode will have uninitialized tail which will get written to disk. We will never expose the data to userspace but still this is not a good practice so just zero out the tail of the block as it isn't going to cause a noticeable performance overhead.

[...]

Applied, thanks!

[1/1] ext4: Avoid writing unitialized memory to disk in EA inodes

      commit: 65121eff3e4c8c90f8126debf3c369228691c591

Best regards,

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