linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Vitaly Chikunov <vt@altlinux.org>
Cc: keyrings@vger.kernel.org, Jarkko Sakkinen <jarkko@kernel.org>,
	David Howells <dhowells@redhat.com>,
	linux-crypto@vger.kernel.org, linux-integrity@vger.kernel.org,
	Stefan Berger <stefanb@linux.ibm.com>,
	Gilad Ben-Yossef <gilad@benyossef.com>,
	Tianjia Zhang <tianjia.zhang@linux.alibaba.com>,
	Mimi Zohar <zohar@linux.ibm.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/2] KEYS: asymmetric: enforce that sig algo matches key algo
Date: Tue, 1 Feb 2022 19:10:33 -0800	[thread overview]
Message-ID: <Yfn2KZgjuFRSJzSj@sol.localdomain> (raw)
In-Reply-To: <20220202025230.hrfochvm3uyuh2wm@altlinux.org>

On Wed, Feb 02, 2022 at 05:52:30AM +0300, Vitaly Chikunov wrote:
> Eric,
> 
> On Mon, Jan 31, 2022 at 04:34:13PM -0800, Eric Biggers wrote:
> > From: Eric Biggers <ebiggers@google.com>
> > 
> > Most callers of public_key_verify_signature(), including most indirect
> > callers via verify_signature() as well as pkcs7_verify_sig_chain(),
> > don't check that public_key_signature::pkey_algo matches
> > public_key::pkey_algo.  These should always match.
> 
> Why should they match?

For the reasons I explain in the rest of the commit message.  To summarize: to
have a valid signature verification scheme the algorithm must be fixed by the
key, and not attacker-controlled.

> 
> public_key_signature is the data prepared to verify the cert's
> signature. The cert's signature algorithm could be different from the
> public key algorithm defined in the cert itself. They should match only
> for self-signed certs. For example, you should be able to sign RSA
> public key with ECDSA signature and vice versa. Or 256-bit EC-RDSA with
> 512-bit EC-RDSA. This check will prevent this.

That has nothing to do with this patch, as this patch is only dealing with the
signature.  A cert's public key algorithm can be different, and that is fine.

> > diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
> > index 4fefb219bfdc8..aba7113d86c76 100644
> > --- a/crypto/asymmetric_keys/public_key.c
> > +++ b/crypto/asymmetric_keys/public_key.c
> > @@ -325,6 +325,21 @@ int public_key_verify_signature(const struct public_key *pkey,
> >  	BUG_ON(!sig);
> >  	BUG_ON(!sig->s);
> >  
> > +	/*
> > +	 * The signature's claimed public key algorithm *must* match the key's
> > +	 * actual public key algorithm.
> > +	 *
> > +	 * Small exception: ECDSA signatures don't specify the curve, but ECDSA
> > +	 * keys do.  So the strings can mismatch slightly in that case:
> > +	 * "ecdsa-nist-*" for the key, but "ecdsa" for the signature.
> > +	 */
> > +	if (!sig->pkey_algo)
> > +		return -EINVAL;
> 
> This seem incorrect too, as sig->pkey_algo could be NULL for direct
> signature verification calls. For example, for keyctl pkey_verify.

We can make it optional if some callers aren't providing it.  Of course, such
callers wouldn't be able to verify ECDSA signatures.

- Eric

  reply	other threads:[~2022-02-02  3:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01  0:34 [PATCH 0/2] Fix bugs in public_key_verify_signature() Eric Biggers
2022-02-01  0:34 ` [PATCH 1/2] KEYS: asymmetric: enforce that sig algo matches key algo Eric Biggers
2022-02-02  2:52   ` Vitaly Chikunov
2022-02-02  3:10     ` Eric Biggers [this message]
2022-02-02  3:22       ` Eric Biggers
2022-02-02  5:20       ` Vitaly Chikunov
2022-02-21  1:43   ` Jarkko Sakkinen
2022-03-04 19:26     ` Eric Biggers
2022-03-05  5:51       ` Jarkko Sakkinen
2022-02-01  0:34 ` [PATCH 2/2] KEYS: asymmetric: properly validate hash_algo and encoding Eric Biggers
2022-02-21  1:46   ` Jarkko Sakkinen
2022-02-21  2:21     ` Eric Biggers
2022-02-21 20:16       ` Jarkko Sakkinen
2022-02-01  2:38 ` [PATCH 0/2] Fix bugs in public_key_verify_signature() Stefan Berger
2022-02-07  7:45 ` Tianjia Zhang
2022-02-07 11:43 ` [PATCH] KEYS: asymmetric: enforce SM2 signature use pkey algo Tianjia Zhang
2022-02-08  5:35   ` Eric Biggers
2022-02-08  9:45     ` Tianjia Zhang
2022-02-21  1:49   ` Jarkko Sakkinen
2022-02-21  2:43     ` Tianjia Zhang
2022-02-21 20:17       ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yfn2KZgjuFRSJzSj@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=gilad@benyossef.com \
    --cc=jarkko@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stefanb@linux.ibm.com \
    --cc=tianjia.zhang@linux.alibaba.com \
    --cc=vt@altlinux.org \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).