]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ext4: check for directory entries too close to block end
authorJan Kara <jack@suse.cz>
Mon, 2 Dec 2019 17:02:13 +0000 (18:02 +0100)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 14 Dec 2019 22:22:45 +0000 (17:22 -0500)
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>
fs/ext4/dir.c

index 9fdd2b269d6172a6856ef0fb98419bf7ed599671..6305d5ec25af9a4f1725385308580dc5a4abe600 100644 (file)
@@ -81,6 +81,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";