Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

X.509: Fix self-signed determination

There's a bug in the code determining whether a certificate is self-signed
or not: if they have neither AKID nor SKID then we just assume that the
cert is self-signed, which may not be true.

Fix this by checking that the raw subject name matches the raw issuer name
and that the public key algorithm for the key and signature are both the
same in addition to requiring that the AKID bits match.

Signed-off-by: David Howells <dhowells@redhat.com>

+9
+9
crypto/asymmetric_keys/x509_public_key.c
··· 230 230 231 231 pr_devel("==>%s()\n", __func__); 232 232 233 + if (cert->raw_subject_size != cert->raw_issuer_size || 234 + memcmp(cert->raw_subject, cert->raw_issuer, 235 + cert->raw_issuer_size) != 0) 236 + goto not_self_signed; 237 + 233 238 if (cert->sig->auth_ids[0] || cert->sig->auth_ids[1]) { 234 239 /* If the AKID is present it may have one or two parts. If 235 240 * both are supplied, both must match. ··· 250 245 cert->sig->auth_ids[0] && cert->sig->auth_ids[1]) 251 246 goto out; 252 247 } 248 + 249 + ret = -EKEYREJECTED; 250 + if (cert->pub->pkey_algo != cert->sig->pkey_algo) 251 + goto out; 253 252 254 253 ret = public_key_verify_signature(cert->pub, cert->sig); 255 254 if (ret < 0) {