asymmetric_keys: log on fatal failures in PE/pkcs7

These particular errors can be encountered while trying to kexec when
secureboot lockdown is in place.  Without this change, even with a
signed debug build, one still needs to reboot the machine to add the
appropriate dyndbg parameters (since lockdown blocks debugfs).

Accordingly, upgrade all pr_debug() before fatal error into pr_warn().

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Jarkko Sakkinen <jarkko@kernel.org>
cc: Eric Biederman <ebiederm@xmission.com>
cc: Herbert Xu <herbert@gondor.apana.org.au>
cc: keyrings@vger.kernel.org
cc: linux-crypto@vger.kernel.org
cc: kexec@lists.infradead.org
Link: https://lore.kernel.org/r/20230220171254.592347-3-rharwood@redhat.com/ # v2
This commit is contained in:
Robbie Harwood 2023-02-20 12:12:54 -05:00 committed by David Howells
parent 4fc5c74dde
commit 3584c1dbff
2 changed files with 17 additions and 17 deletions

View File

@ -79,16 +79,16 @@ static int pkcs7_digest(struct pkcs7_message *pkcs7,
} }
if (sinfo->msgdigest_len != sig->digest_size) { if (sinfo->msgdigest_len != sig->digest_size) {
pr_debug("Sig %u: Invalid digest size (%u)\n", pr_warn("Sig %u: Invalid digest size (%u)\n",
sinfo->index, sinfo->msgdigest_len); sinfo->index, sinfo->msgdigest_len);
ret = -EBADMSG; ret = -EBADMSG;
goto error; goto error;
} }
if (memcmp(sig->digest, sinfo->msgdigest, if (memcmp(sig->digest, sinfo->msgdigest,
sinfo->msgdigest_len) != 0) { sinfo->msgdigest_len) != 0) {
pr_debug("Sig %u: Message digest doesn't match\n", pr_warn("Sig %u: Message digest doesn't match\n",
sinfo->index); sinfo->index);
ret = -EKEYREJECTED; ret = -EKEYREJECTED;
goto error; goto error;
} }
@ -478,7 +478,7 @@ int pkcs7_supply_detached_data(struct pkcs7_message *pkcs7,
const void *data, size_t datalen) const void *data, size_t datalen)
{ {
if (pkcs7->data) { if (pkcs7->data) {
pr_debug("Data already supplied\n"); pr_warn("Data already supplied\n");
return -EINVAL; return -EINVAL;
} }
pkcs7->data = data; pkcs7->data = data;

View File

@ -74,7 +74,7 @@ static int pefile_parse_binary(const void *pebuf, unsigned int pelen,
break; break;
default: default:
pr_debug("Unknown PEOPT magic = %04hx\n", pe32->magic); pr_warn("Unknown PEOPT magic = %04hx\n", pe32->magic);
return -ELIBBAD; return -ELIBBAD;
} }
@ -95,7 +95,7 @@ static int pefile_parse_binary(const void *pebuf, unsigned int pelen,
ctx->certs_size = ddir->certs.size; ctx->certs_size = ddir->certs.size;
if (!ddir->certs.virtual_address || !ddir->certs.size) { if (!ddir->certs.virtual_address || !ddir->certs.size) {
pr_debug("Unsigned PE binary\n"); pr_warn("Unsigned PE binary\n");
return -ENODATA; return -ENODATA;
} }
@ -127,7 +127,7 @@ static int pefile_strip_sig_wrapper(const void *pebuf,
unsigned len; unsigned len;
if (ctx->sig_len < sizeof(wrapper)) { if (ctx->sig_len < sizeof(wrapper)) {
pr_debug("Signature wrapper too short\n"); pr_warn("Signature wrapper too short\n");
return -ELIBBAD; return -ELIBBAD;
} }
@ -142,16 +142,16 @@ static int pefile_strip_sig_wrapper(const void *pebuf,
* rounded up since 0.110. * rounded up since 0.110.
*/ */
if (wrapper.length > ctx->sig_len) { if (wrapper.length > ctx->sig_len) {
pr_debug("Signature wrapper bigger than sig len (%x > %x)\n", pr_warn("Signature wrapper bigger than sig len (%x > %x)\n",
ctx->sig_len, wrapper.length); ctx->sig_len, wrapper.length);
return -ELIBBAD; return -ELIBBAD;
} }
if (wrapper.revision != WIN_CERT_REVISION_2_0) { if (wrapper.revision != WIN_CERT_REVISION_2_0) {
pr_debug("Signature is not revision 2.0\n"); pr_warn("Signature is not revision 2.0\n");
return -ENOTSUPP; return -ENOTSUPP;
} }
if (wrapper.cert_type != WIN_CERT_TYPE_PKCS_SIGNED_DATA) { if (wrapper.cert_type != WIN_CERT_TYPE_PKCS_SIGNED_DATA) {
pr_debug("Signature certificate type is not PKCS\n"); pr_warn("Signature certificate type is not PKCS\n");
return -ENOTSUPP; return -ENOTSUPP;
} }
@ -164,7 +164,7 @@ static int pefile_strip_sig_wrapper(const void *pebuf,
ctx->sig_offset += sizeof(wrapper); ctx->sig_offset += sizeof(wrapper);
ctx->sig_len -= sizeof(wrapper); ctx->sig_len -= sizeof(wrapper);
if (ctx->sig_len < 4) { if (ctx->sig_len < 4) {
pr_debug("Signature data missing\n"); pr_warn("Signature data missing\n");
return -EKEYREJECTED; return -EKEYREJECTED;
} }
@ -198,7 +198,7 @@ check_len:
return 0; return 0;
} }
not_pkcs7: not_pkcs7:
pr_debug("Signature data not PKCS#7\n"); pr_warn("Signature data not PKCS#7\n");
return -ELIBBAD; return -ELIBBAD;
} }
@ -341,8 +341,8 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
digest_size = crypto_shash_digestsize(tfm); digest_size = crypto_shash_digestsize(tfm);
if (digest_size != ctx->digest_len) { if (digest_size != ctx->digest_len) {
pr_debug("Digest size mismatch (%zx != %x)\n", pr_warn("Digest size mismatch (%zx != %x)\n",
digest_size, ctx->digest_len); digest_size, ctx->digest_len);
ret = -EBADMSG; ret = -EBADMSG;
goto error_no_desc; goto error_no_desc;
} }
@ -373,7 +373,7 @@ static int pefile_digest_pe(const void *pebuf, unsigned int pelen,
* PKCS#7 certificate. * PKCS#7 certificate.
*/ */
if (memcmp(digest, ctx->digest, ctx->digest_len) != 0) { if (memcmp(digest, ctx->digest, ctx->digest_len) != 0) {
pr_debug("Digest mismatch\n"); pr_warn("Digest mismatch\n");
ret = -EKEYREJECTED; ret = -EKEYREJECTED;
} else { } else {
pr_debug("The digests match!\n"); pr_debug("The digests match!\n");