Skip to contentSkip to conversation

ima: Fix a use after free in ima_read_modsig()

PATCH In review Dan Carpenter 2 participants 4 messages Aug 8, 2019

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

PATCH 1/1 ima: Fix a use after free in ima_read_modsig()

This code frees "hdr" and then dereferences it on the next line to get the error code.

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..d106885cc495 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)) {
+		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);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 5 lines · Dan Carpenter

This code frees "hdr" and then dereferences it on the next line to get the error code.

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

Thanks, Dan.  Julia already reported this.  Thiago posted a patch last night.  Just getting to it now.  Can I add your Reviewed-by or Tested- by?

Mimi

#2 lore raw
Quoted 10 lines · Mimi Zohar
Quoted 5 lines · Dan Carpenter

This code frees "hdr" and then dereferences it on the next line to get the error code.

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

Thanks, Dan.  Julia already reported this.  Thiago posted a patch last night.  Just getting to it now.  Can I add your Reviewed-by or Tested- by?

I haven't seen the other patch so Reviewed-by seems like the wrong thing. I don't really need any sort of credit. I'm just going through my backlog of warnings from being out of office. Perhaps Reported-by?

regards,
dan carpenter

#3 lore raw
Quoted 8 lines · Dan Carpenter
Quoted 7 lines · Mimi Zohar
Quoted 5 lines · Dan Carpenter

This code frees "hdr" and then dereferences it on the next line to get the error code.

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

Thanks, Dan.  Julia already reported this.  Thiago posted a patch last night.  Just getting to it now.  Can I add your Reviewed-by or Tested- by?

I haven't seen the other patch so Reviewed-by seems like the wrong thing. I don't really need any sort of credit. I'm just going through my backlog of warnings from being out of office. Perhaps Reported-by?

That works. FYI, your solution and Thiago's are exactly the same.[1]

Mimi

[1] https://lore.kernel.org/linux-integrity/[email protected]/T/#u