Skip to contentSkip to conversation

ima: ima_modsig: Fix use-after-free bug in ima_read_modsig

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Aug 11, 2019 – Aug 28, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ima: ima_modsig: Fix use-after-free bug in ima_read_modsig

hdr is being freed and then dereferenced by accessing hdr->pkcs7_msg

Fix this by copying the value returned by PTR_ERR(hdr->pkcs7_msg) into automatic variable err for its safe use after freeing hdr.

Addresses-Coverity-ID: 1485813 ("Read from pointer after free")

Fixes 39b07096364a ("ima: Implement support for module-style appended signatures")
---
 security/integrity/ima/ima_modsig.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/integrity/ima/ima_modsig.c +2 -1
index c412e31d1714..e681d4326145 100644
@@ -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)) {
+		int err = PTR_ERR(hdr->pkcs7_msg);
 		kfree(hdr);
-		return PTR_ERR(hdr->pkcs7_msg);
+		return err;
 	}
 
 	memcpy(hdr->raw_pkcs7, buf + buf_len, sig_len);
Signature · 1 line
2.22.0
maintainer
#1 lore raw

Hi Gustavo,

Quoted 8 lines · Gustavo A. R. Silva

hdr is being freed and then dereferenced by accessing hdr->pkcs7_msg

Fix this by copying the value returned by PTR_ERR(hdr->pkcs7_msg) into automatic variable err for its safe use after freeing hdr.

Addresses-Coverity-ID: 1485813 ("Read from pointer after free")

Fixes 39b07096364a ("ima: Implement support for module-style appended signatures")

This bug was reported Julia and addressed by Thiago on 8/7. If you would like to add your Review/Tested-by, the patch can be found in the linux-integrity next-queued-testing branch.

thanks,

Mimi

author Reviewed-by
#2 lore raw
Quoted 8 lines · Mimi Zohar

Hi Gustavo,

Quoted 5 lines · Gustavo A. R. Silva

hdr is being freed and then dereferenced by accessing hdr->pkcs7_msg

Fix this by copying the value returned by PTR_ERR(hdr->pkcs7_msg) into automatic variable err for its safe use after freeing hdr.

Quoted 8 lines
Quoted 3 lines

Addresses-Coverity-ID: 1485813 ("Read from pointer after free")

Fixes 39b07096364a ("ima: Implement support for module-style appended signatures")

This bug was reported Julia and addressed by Thiago on 8/7. If you would like to add your Review/Tested-by, the patch can be found in the linux-integrity next-queued-testing branch.

I'm glad this is fixed now. :)

Yeah, you can add my:

Thanks
--
Gustavo