]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit
X.509: fix BUG_ON() when hash algorithm is unsupported
authorEric Biggers <ebiggers@google.com>
Thu, 22 Feb 2018 14:38:33 +0000 (14:38 +0000)
committerSeth Forshee <seth.forshee@canonical.com>
Wed, 28 Feb 2018 14:47:10 +0000 (08:47 -0600)
commit2579659ade918cd5c46ff6f8977e669efd3ace4e
tree56008c5040e770e6918991e6639f2794ad9be4a5
parenta18f85315be0baf7fc8832a9fe35e48f4b7a65b3
X.509: fix BUG_ON() when hash algorithm is unsupported

BugLink: https://bugs.launchpad.net/bugs/1752317
commit 437499eea4291ae9621e8763a41df027c110a1ef upstream.

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: 6c2dc5ae4ab7 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
crypto/asymmetric_keys/public_key.c