Skip to content

Commit 65121ef

Browse files
jankaratytso
authored andcommitted
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: e50e512 ("ext4: xattr-in-inode support") Reported-by: [email protected] Reported-by: Hugh Dickins <[email protected]> Signed-off-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 7882b01 commit 65121ef

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/ext4/xattr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,12 @@ static int ext4_xattr_inode_write(handle_t *handle, struct inode *ea_inode,
14331433
goto out;
14341434

14351435
memcpy(bh->b_data, buf, csize);
1436+
/*
1437+
* Zero out block tail to avoid writing uninitialized memory
1438+
* to disk.
1439+
*/
1440+
if (csize < blocksize)
1441+
memset(bh->b_data + csize, 0, blocksize - csize);
14361442
set_buffer_uptodate(bh);
14371443
ext4_handle_dirty_metadata(handle, ea_inode, bh);
14381444

0 commit comments

Comments
 (0)