mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.ibm.com>
To: florian.bauckholt@cispa.de, Lukas Wunner <lukas@wunner.de>,
	Ignat Korchagin <ignat@linux.win>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org, keyrings@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] crypto: ecdsa - Reject non-DER X9.62 signatures
Date: Wed, 2 Dec 2026 16:13:19 -0500	[thread overview]
Message-ID: <66003f46-9f45-46c2-9f5b-2bdda2ee533b@linux.ibm.com> (raw)
In-Reply-To: <20261201-ecdsa-x962-der-v2-1-00ba1a98a530@cispa.de>



On 12/1/26 6:21 AM, Florian Bauckholt via B4 Relay wrote:
> From: Florian Bauckholt <florian.bauckholt@cispa.de>
> 
> The x962(ecdsa-nist-*) template decodes Ecdsa-Sig-Value with the
> generic BER decoder, and ecdsa_get_signature_rs() only strips one
> leading zero byte without looking at the INTEGER's sign or encoding.
> As a result the following encodings of a valid signature are accepted
> as well:
> 
>   - a SEQUENCE tag without the constructed bit (0x10 instead of 0x30),
>     as the decoder ignores that bit when matching a constructed tag
>   - non-minimal length encodings of the SEQUENCE, r or s (long form
>     where the short form fits, or padded with zero bytes)
>   - indefinite length for the SEQUENCE
>   - data following the SEQUENCE (the decoder does not check that the
>     whole buffer was consumed)
>   - r or s with the most significant bit set but without the leading
>     zero byte, i.e. a negative INTEGER read as positive
>   - r or s with a superfluous leading zero byte
> 
> RFC 3279 section 2.2.3 and SEC 1 section C.5 require Ecdsa-Sig-Value to
> be DER-encoded, so all of these are invalid and should be rejected.
> 
> This is a potential but unlikely behaviour change for users of the x962
> template (X.509 certificates, module and IMA signatures,
> KEYCTL_PKEY_VERIFY): signatures that are valid ECDSA signatures but are
> not DER-encoded used to verify and are now rejected with -EINVAL. The
> p1363 template is not affected.
> 
> Rejecting trailing data relies on KEYCTL_PKEY_VERIFY passing the
> caller's signature length. Between commit cb481e59ea6c ("KEYS: fix
> overflow in keyctl_pkey_params_get_2()") and commit 94cd21592349 ("KEYS:
> Fix asym key overflow in keyctl_pkey_verify()") it passed max_sig_size
> instead, so trees containing the former need the latter before this
> patch, or every signature shorter than the maximum is rejected.
> 
> Add a test vector for each of these encodings, taken or derived from
> Wycheproof's secp256r1/SHA-256 test vectors.
> 
> Found by differential testing against other ECDSA implementations.
> 
> Fixes: 4e6602916bc6 ("crypto: ecdsa - Add support for ECDSA signature verification")
> Signed-off-by: Florian Bauckholt <florian.bauckholt@cispa.de>

Tested-by: Stefan Berger <stefanb@linux.ibm.com>


      reply	other threads:[~2026-12-02 21:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 11:21 Florian Bauckholt via B4 Relay
2026-12-02 21:13 ` Stefan Berger [this message]

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=66003f46-9f45-46c2-9f5b-2bdda2ee533b@linux.ibm.com \
    --to=stefanb@linux.ibm.com \
    --cc=davem@davemloft.net \
    --cc=florian.bauckholt@cispa.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=ignat@linux.win \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    /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

all inboxes | Powered by JetHome®