summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2019-12-02 18:02:13 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-12-31 16:36:27 +0100
commit14ccb2b84f5bfe3a9dad63e911bd9d3ab78fe26f (patch)
tree32221d6693417ca69792a96898493c64b257124f /fs
parent1e62ac6b1307129c0f9ca68e9db4227239b4ab19 (diff)
downloadlinux-stable-14ccb2b84f5bfe3a9dad63e911bd9d3ab78fe26f.tar.gz
linux-stable-14ccb2b84f5bfe3a9dad63e911bd9d3ab78fe26f.tar.bz2
linux-stable-14ccb2b84f5bfe3a9dad63e911bd9d3ab78fe26f.zip
ext4: check for directory entries too close to block end
commit 109ba779d6cca2d519c5dd624a3276d03e21948e upstream. 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: stable@vger.kernel.org Signed-off-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20191202170213.4761-3-jack@suse.cz Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/dir.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 46d5c40f2835..d947c5e439cf 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -77,6 +77,11 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
error_msg = "rec_len is too small for name_len";
else if (unlikely(((char *) de - buf) + rlen > size))
error_msg = "directory entry overrun";
+ else if (unlikely(((char *) de - buf) + rlen >
+ size - EXT4_DIR_REC_LEN(1) &&
+ ((char *) de - buf) + rlen != size)) {
+ error_msg = "directory entry too close to block end";
+ }
else if (unlikely(le32_to_cpu(de->inode) >
le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count)))
error_msg = "inode out of bounds";