Skip to contentSkip to conversation

ima: fix reference leak in asymmetric_verify()

PATCH In review Eric Biggers 4 participants 6 messages Jan 13, 2022 – Jan 19, 2022

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

PATCH 1/1 ima: fix reference leak in asymmetric_verify()

From: Eric Biggers <[email protected]>

Don't leak a reference to the key if its algorithm is unknown.

Fixes 947d70597236 ("ima: Support EC keys for signature verification")
Cc <[email protected]> # v5.13+
---
 security/integrity/digsig_asymmetric.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
security/integrity/digsig_asymmetric.c +9 -6
index 23240d793b07..895f4b9ce8c6 100644
@@ -109,22 +109,25 @@ int asymmetric_verify(struct key *keyring, const char *sig,
 
 	pk = asymmetric_key_public_key(key);
 	pks.pkey_algo = pk->pkey_algo;
-	if (!strcmp(pk->pkey_algo, "rsa"))
+	if (!strcmp(pk->pkey_algo, "rsa")) {
 		pks.encoding = "pkcs1";
-	else if (!strncmp(pk->pkey_algo, "ecdsa-", 6))
+	} else if (!strncmp(pk->pkey_algo, "ecdsa-", 6)) {
 		/* edcsa-nist-p192 etc. */
 		pks.encoding = "x962";
-	else if (!strcmp(pk->pkey_algo, "ecrdsa") ||
-		   !strcmp(pk->pkey_algo, "sm2"))
+	} else if (!strcmp(pk->pkey_algo, "ecrdsa") ||
+		   !strcmp(pk->pkey_algo, "sm2")) {
 		pks.encoding = "raw";
-	else
-		return -ENOPKG;
+	} else {
+		ret = -ENOPKG;
+		goto out;
+	}
 
 	pks.digest = (u8 *)data;
 	pks.digest_size = datalen;
 	pks.s = hdr->sig;
 	pks.s_size = siglen;
 	ret = verify_signature(key, &pks);
+out:
 	key_put(key);
 	pr_debug("%s() = %d\n", __func__, ret);
 	return ret;

base-commit: feb7a43de5ef625ad74097d8fd3481d5dbc06a59

Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 48 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Don't leak a reference to the key if its algorithm is unknown.

Fixes 947d70597236 ("ima: Support EC keys for signature verification")
Cc <[email protected]> # v5.13+
---
  security/integrity/digsig_asymmetric.c | 15 +++++++++------
  1 file changed, 9 insertions(+), 6 deletions(-)
security/integrity/digsig_asymmetric.c +9 -6
index 23240d793b07..895f4b9ce8c6 100644
@@ -109,22 +109,25 @@ int asymmetric_verify(struct key *keyring, const char *sig,
 
  	pk = asymmetric_key_public_key(key);
  	pks.pkey_algo = pk->pkey_algo;
-	if (!strcmp(pk->pkey_algo, "rsa"))
+	if (!strcmp(pk->pkey_algo, "rsa")) {
  		pks.encoding = "pkcs1";
-	else if (!strncmp(pk->pkey_algo, "ecdsa-", 6))
+	} else if (!strncmp(pk->pkey_algo, "ecdsa-", 6)) {
  		/* edcsa-nist-p192 etc. */
  		pks.encoding = "x962";
-	else if (!strcmp(pk->pkey_algo, "ecrdsa") ||
-		   !strcmp(pk->pkey_algo, "sm2"))
+	} else if (!strcmp(pk->pkey_algo, "ecrdsa") ||
+		   !strcmp(pk->pkey_algo, "sm2")) {
  		pks.encoding = "raw";
-	else
-		return -ENOPKG;
+	} else {
+		ret = -ENOPKG;
+		goto out;
+	}
 
  	pks.digest = (u8 *)data;
  	pks.digest_size = datalen;
  	pks.s = hdr->sig;
  	pks.s_size = siglen;
  	ret = verify_signature(key, &pks);
+out:
  	key_put(key);
  	pr_debug("%s() = %d\n", __func__, ret);
  	return ret;
Quoted 1 line

base-commit: feb7a43de5ef625ad74097d8fd3481d5dbc06a59

#3 lore raw
Quoted 5 lines · Mimi Zohar

Hi Eric,

Quoted 2 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Quoted 8 lines
Quoted 5 lines

Don't leak a reference to the key if its algorithm is unknown.

Fixes 947d70597236 ("ima: Support EC keys for signature verification")
Cc <[email protected]> # v5.13+

Thanks. You're intending to apply this patch, right? Or are you expecting someone else to? get_maintainer.pl didn't associate this file with IMA, but I see you sent out a patch to fix that
(https://lore.kernel.org/linux-integrity/[email protected]/T/#u).

- Eric

maintainer
#4 lore raw
Quoted 12 lines · Eric Biggers
Quoted 11 lines · Mimi Zohar

Hi Eric,

Quoted 7 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Don't leak a reference to the key if its algorithm is unknown.

Fixes 947d70597236 ("ima: Support EC keys for signature verification")
Cc <[email protected]> # v5.13+
Quoted 7 lines
Quoted 2 lines

Thanks. You're intending to apply this patch, right? Or are you expecting someone else to? get_maintainer.pl didn't associate this file with IMA, but I see you sent out a patch to fix that
(https://lore.kernel.org/linux-integrity/[email protected]/T/#u).

Once the open window closes, I'll apply it.

Mimi