Skip to contentSkip to conversation

X.509: Fix error code in x509_cert_parse()

PATCH Superseded Dan Carpenter 3 participants 5 messages May 23, 2017 – Jun 10, 2017

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

PATCH 1/1 X.509: Fix error code in x509_cert_parse()

We forgot to set the error code on this path so it could result in returning NULL which leads to a NULL dereference.

Fixes db6c43bd2132 ("crypto: KEYS: convert public key and digsig asym to the akcipher api")
crypto/asymmetric_keys/x509_cert_parser.c +3 -1
index c80765b211cf..1f69e948fb34 100644
@@ -103,8 +103,10 @@ struct x509_certificate *x509_cert_parse(const void *data, size_t datalen)
 	}
 
 	cert->pub->key = kmemdup(ctx->key, ctx->key_size, GFP_KERNEL);
-	if (!cert->pub->key)
+	if (!cert->pub->key) {
+		ret = -ENOMEM;
 		goto error_decode;
+	}
 
 	cert->pub->keylen = ctx->key_size;
 
maintainer
#1 lore raw

crypto/asymmetric_keys/x509_cert_parser.c struct x509_certificate *x509_cert_parse(const void *data, size_t datalen) · line 109

Quoted 6 lines · Dan Carpenter
crypto/asymmetric_keys/x509_cert_parser.c +3 -1
 	cert->pub->key = kmemdup(ctx->key, ctx->key_size, GFP_KERNEL);
-	if (!cert->pub->key)
+	if (!cert->pub->key) {
+		ret = -ENOMEM;
 		goto error_decode;
+	}

Put the "ret = -ENOMEM" line before the kmemdup line maybe?

David

#2 lore raw

PATCH v2 1/1 X.509: Fix error code in x509_cert_parse()

We forgot to set the error code on this path so it could result in returning NULL which leads to a NULL dereference.

Fixes db6c43bd2132 ("crypto: KEYS: convert public key and digsig asym to the akcipher api")

---
v2: Style change

Sorry for the delay, I'm been out of office.

crypto/asymmetric_keys/x509_cert_parser.c +1 -0
index c80765b211cf..dd03fead1ca3 100644
@@ -102,6 +102,7 @@ struct x509_certificate *x509_cert_parse(const void *data, size_t datalen)
 		}
 	}
 
+	ret = -ENOMEM;
 	cert->pub->key = kmemdup(ctx->key, ctx->key_size, GFP_KERNEL);
 	if (!cert->pub->key)
 		goto error_decode;
maintainer
#3 lore raw
Quoted 7 lines · Dan Carpenter

We forgot to set the error code on this path so it could result in returning NULL which leads to a NULL dereference.

Fixes db6c43bd2132 ("crypto: KEYS: convert public key and digsig asym to the akcipher api")

---
v2: Style change

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#4 lore raw
Quoted 1 line · Herbert Xu

Patch applied. Thanks.

Note that I've passed this on to James to pass on to Linus along with a bunch of other patches.

David