Skip to content

Commit 65f8ea4

Browse files
Lukas Czernertytso
authored andcommitted
ext4: check if directory block is within i_size
Currently ext4 directory handling code implicitly assumes that the directory blocks are always within the i_size. In fact ext4_append() will attempt to allocate next directory block based solely on i_size and the i_size is then appropriately increased after a successful allocation. However, for this to work it requires i_size to be correct. If, for any reason, the directory inode i_size is corrupted in a way that the directory tree refers to a valid directory block past i_size, we could end up corrupting parts of the directory tree structure by overwriting already used directory blocks when modifying the directory. Fix it by catching the corruption early in __ext4_read_dirblock(). Addresses Red-Hat-Bugzilla: #2070205 CVE: CVE-2022-1184 Signed-off-by: Lukas Czerner <lczerner@redhat.com> Cc: stable@vger.kernel.org Reviewed-by: Andreas Dilger <adilger@dilger.ca> Link: https://lore.kernel.org/r/20220704142721.157985-1-lczerner@redhat.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 3fa5d23 commit 65f8ea4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/ext4/namei.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
110110
struct ext4_dir_entry *dirent;
111111
int is_dx_block = 0;
112112

113+
if (block >= inode->i_size) {
114+
ext4_error_inode(inode, func, line, block,
115+
"Attempting to read directory block (%u) that is past i_size (%llu)",
116+
block, inode->i_size);
117+
return ERR_PTR(-EFSCORRUPTED);
118+
}
119+
113120
if (ext4_simulate_fail(inode->i_sb, EXT4_SIM_DIRBLOCK_EIO))
114121
bh = ERR_PTR(-EIO);
115122
else

0 commit comments

Comments
 (0)