From: Thiago Jung Bauermann Date: Thu, 8 Aug 2019 00:43:18 +0000 (-0300) Subject: ima: Fix use after free in ima_read_modsig() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=556d971bdae643de4cd7e2976e14f70ca2a3061d;p=linux.git ima: Fix use after free in ima_read_modsig() If we can't parse the PKCS7 in the appended modsig, we will free the modsig structure and then access one of its members to determine the error value. Fixes: 39b07096364a ("ima: Implement support for module-style appended signatures") Reported-by: kbuild test robot Reported-by: Julia Lawall Reported-by: Dan Carpenter Signed-off-by: Thiago Jung Bauermann Reviewed-by: Gustavo A. R. Silva Signed-off-by: Mimi Zohar --- diff --git a/security/integrity/ima/ima_modsig.c b/security/integrity/ima/ima_modsig.c index c412e31d17141..d106885cc4955 100644 --- a/security/integrity/ima/ima_modsig.c +++ b/security/integrity/ima/ima_modsig.c @@ -91,8 +91,9 @@ int ima_read_modsig(enum ima_hooks func, const void *buf, loff_t buf_len, hdr->pkcs7_msg = pkcs7_parse_message(buf + buf_len, sig_len); if (IS_ERR(hdr->pkcs7_msg)) { + rc = PTR_ERR(hdr->pkcs7_msg); kfree(hdr); - return PTR_ERR(hdr->pkcs7_msg); + return rc; } memcpy(hdr->raw_pkcs7, buf + buf_len, sig_len);