Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Dan Carpenter <dan@pereq.eu>
Cc: "David Howells" <dhowells@redhat.com>,
	"Lukas Wunner" <lukas@wunner.de>,
	"Ignat Korchagin" <ignat@linux.win>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"David Woodhouse" <dwmw2@infradead.org>,
	"Eric Snowberg" <eric.snowberg@oracle.com>,
	"Karthik Bhargavan" <karthik@pereq.eu>,
	"Clément Blaudeau" <clement@cryspen.com>,
	keyrings@vger.kernel.org, linux-crypto@vger.kernel.org
Subject: Re: [PATCH 4/5] pkcs7: Reset the signer identifier fields and check them
Date: Tue, 1 Dec 2026 18:25:58 +0200	[thread overview]
Message-ID: <aw71FjQrrlN-NhrD@kernel.org> (raw)
In-Reply-To: <20261201-pkcs7-v1-4-ace9edcd1a53@pereq.eu>

On Tue, Dec 01, 2026 at 11:22:30AM +0300, Dan Carpenter wrote:
> This bug isn't very serious.

Why I need to think about this?

> 
> The SignerInfo can be either version 1 or version 3.  For version 1
> we use ->raw_serial and ->raw_issuer.  For version 3 we use
> ->raw_skid.  The problem is that these fields are not cleared at the
> start so we could accidentally use whatever was put there by the
> previous caller.
> 
> Clear the fields in pkcs7_note_signerinfo_version(), which is called
> at the start of each SignerInfo.  Add a check in pkcs7_note_signed_info()
> to ensure that the fields are set correctly.
> 
> The malformed packets would eventually fail anyway so the impact of
> this bug is minimal.  The difference is that now we return -EBADMSG
> instead of -EINVAL or -EKEYREJECTED.
> 
> Fixes: 60d65cacd7c2 ("PKCS#7: Support CMS messages also [RFC5652]")
> Signed-off-by: Dan Carpenter <dan@pereq.eu>
> ---
>  crypto/asymmetric_keys/pkcs7_parser.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c
> index 7f00e45a33cf..b95205ede202 100644
> --- a/crypto/asymmetric_keys/pkcs7_parser.c
> +++ b/crypto/asymmetric_keys/pkcs7_parser.c
> @@ -400,6 +400,13 @@ int pkcs7_note_signerinfo_version(void *context, size_t hdrlen,
>  	struct pkcs7_parse_context *ctx = context;
>  	unsigned version;
>  
> +	ctx->raw_serial = NULL;
> +	ctx->raw_serial_size = 0;
> +	ctx->raw_issuer = NULL;
> +	ctx->raw_issuer_size = 0;
> +	ctx->raw_skid = NULL;
> +	ctx->raw_skid_size = 0;
> +
>  	if (vlen != 1)
>  		goto unsupported;
>  
> @@ -714,6 +721,13 @@ int pkcs7_note_signed_info(void *context, size_t hdrlen,
>  		return -EBADMSG;
>  	}
>  
> +	/* The sid must be of the form that the version calls for */
> +	if (ctx->expect_skid ? !ctx->raw_skid_size :
> +			       !ctx->raw_serial || !ctx->raw_issuer) {
> +		pr_warn("SignerInfo sid does not match its version\n");
> +		return -EBADMSG;
> +	}
> +
>  	/* Generate cert issuer + serial number key ID */
>  	if (!ctx->expect_skid) {
>  		kid = asymmetric_key_generate_id(ctx->raw_serial,
> 
> -- 
> 2.53.0
> 

Br, Jarkko

  reply	other threads:[~2026-12-01 16:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:22 [PATCH 0/5] pkcs7: Fix some certificate handling bugs Dan Carpenter
2026-12-01  8:22 ` [PATCH 1/5] pkcs7: Don't trust a blacklisted certificate Dan Carpenter
2026-12-01 15:42   ` Jarkko Sakkinen
2026-12-01 15:46     ` Jarkko Sakkinen
2026-12-01  8:22 ` [PATCH 2/5] certs: Fix error checking in is_key_on_revocation_list() Dan Carpenter
2026-12-01 16:22   ` Jarkko Sakkinen
2026-12-01  8:22 ` [PATCH 3/5] pkcs7: Clear the ->verified flag before checking trust Dan Carpenter
2026-12-01 16:25   ` Jarkko Sakkinen
2026-12-01  8:22 ` [PATCH 4/5] pkcs7: Reset the signer identifier fields and check them Dan Carpenter
2026-12-01 16:25   ` Jarkko Sakkinen [this message]
2026-12-01 16:36     ` Dan Carpenter
2026-12-01  8:22 ` [PATCH 5/5] pkcs7: Fix support for subjectKeyIdentifier signers Dan Carpenter

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=aw71FjQrrlN-NhrD@kernel.org \
    --to=jarkko@kernel.org \
    --cc=clement@cryspen.com \
    --cc=dan@pereq.eu \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=eric.snowberg@oracle.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=ignat@linux.win \
    --cc=karthik@pereq.eu \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@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