Skip to content

Commit 109ba77

Browse files
jankaratytso
authored andcommitted
ext4: check for directory entries too close to block end
ext4_check_dir_entry() currently does not catch a case when a directory entry ends so close to the block end that the header of the next directory entry would not fit in the remaining space. This can lead to directory iteration code trying to access address beyond end of current buffer head leading to oops. CC: [email protected] Signed-off-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 64d4ce8 commit 109ba77

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

fs/ext4/dir.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
8181
error_msg = "rec_len is too small for name_len";
8282
else if (unlikely(((char *) de - buf) + rlen > size))
8383
error_msg = "directory entry overrun";
84+
else if (unlikely(((char *) de - buf) + rlen >
85+
size - EXT4_DIR_REC_LEN(1) &&
86+
((char *) de - buf) + rlen != size)) {
87+
error_msg = "directory entry too close to block end";
88+
}
8489
else if (unlikely(le32_to_cpu(de->inode) >
8590
le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count)))
8691
error_msg = "inode out of bounds";

0 commit comments

Comments
 (0)