Skip to content

Commit 437499e

Browse files
ebiggersdhowells
authored andcommitted
X.509: fix BUG_ON() when hash algorithm is unsupported
The X.509 parser mishandles the case where the certificate's signature's hash algorithm is not available in the crypto API. In this case, x509_get_sig_params() doesn't allocate the cert->sig->digest buffer; this part seems to be intentional. However, public_key_verify_signature() is still called via x509_check_for_self_signed(), which triggers the 'BUG_ON(!sig->digest)'. Fix this by making public_key_verify_signature() return -ENOPKG if the hash buffer has not been allocated. Reproducer when all the CONFIG_CRYPTO_SHA512* options are disabled: openssl req -new -sha512 -x509 -batch -nodes -outform der \ | keyctl padd asymmetric desc @s Fixes: 6c2dc5a ("X.509: Extract signature digest and make self-signed cert checks earlier") Reported-by: Paolo Valente <paolo.valente@linaro.org> Cc: Paolo Valente <paolo.valente@linaro.org> Cc: <stable@vger.kernel.org> # v4.7+ Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 6459ae3 commit 437499e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crypto/asymmetric_keys/public_key.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ int public_key_verify_signature(const struct public_key *pkey,
7979

8080
BUG_ON(!pkey);
8181
BUG_ON(!sig);
82-
BUG_ON(!sig->digest);
8382
BUG_ON(!sig->s);
8483

84+
if (!sig->digest)
85+
return -ENOPKG;
86+
8587
alg_name = sig->pkey_algo;
8688
if (strcmp(sig->pkey_algo, "rsa") == 0) {
8789
/* The data wangled by the RSA algorithm is typically padded

0 commit comments

Comments
 (0)