CVE-2019-13104: ext4: check for underflow in ext4fs_read_file

In ext4fs_read_file, it is possible for a broken/malicious file
system to cause a memcpy of a negative number of bytes, which
overflows all memory. This patch fixes the issue by checking for
a negative length.

Change-Id: Ia9abdb744dfff20aa1a538d38f335284e30a307b
Signed-off-by: Paul Emge <paulemge@forallsecure.com>
Signed-off-by: Karthick Shanmugham <kartshan@codeaurora.org>
This commit is contained in:
Paul Emge 2020-01-14 20:15:32 +05:30 committed by Karthick Shanmugham
parent 043f757bb9
commit e621657025

View file

@ -68,6 +68,9 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
if (len > filesize)
len = filesize;
if (blocksize <= 0 || len <= 0)
return -1;
blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
for (i = lldiv(pos, blocksize); i < blockcnt; i++) {