Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH 0/5] pkcs7: Fix some certificate handling bugs
@ 2026-12-01  8:22 Dan Carpenter
  2026-12-01  8:22 ` [PATCH 1/5] pkcs7: Don't trust a blacklisted certificate Dan Carpenter
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Dan Carpenter @ 2026-12-01  8:22 UTC (permalink / raw)
  To: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Jarkko Sakkinen, Eric Snowberg
  Cc: Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	Dan Carpenter, stable

These bugs were found through our formal analysis work at Pereq.
I tested these my loading signed modules.

Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
Dan Carpenter (5):
      pkcs7: Don't trust a blacklisted certificate
      certs: Fix error checking in is_key_on_revocation_list()
      pkcs7: Clear the ->verified flag before checking trust
      pkcs7: Reset the signer identifier fields and check them
      pkcs7: Fix support for subjectKeyIdentifier signers

 certs/blacklist.c                     |  2 ++
 crypto/asymmetric_keys/pkcs7_parser.c | 14 ++++++++++++++
 crypto/asymmetric_keys/pkcs7_trust.c  |  9 ++++++++-
 crypto/asymmetric_keys/pkcs7_verify.c |  3 ++-
 4 files changed, 26 insertions(+), 2 deletions(-)
---
base-commit: a9c48428cbd8d96b26f92631d0db6f8519c5fcc5
change-id: 20261201-pkcs7-22b85760f720

Best regards,
--  
Dan Carpenter <dan@pereq.eu>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/5] pkcs7: Don't trust a blacklisted certificate
  2026-12-01  8:22 [PATCH 0/5] pkcs7: Fix some certificate handling bugs Dan Carpenter
@ 2026-12-01  8:22 ` Dan Carpenter
  2026-12-01 15:42   ` Jarkko Sakkinen
  2026-12-01  8:22 ` [PATCH 2/5] certs: Fix error checking in is_key_on_revocation_list() Dan Carpenter
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Dan Carpenter @ 2026-12-01  8:22 UTC (permalink / raw)
  To: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Jarkko Sakkinen, Eric Snowberg
  Cc: Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	Dan Carpenter, stable

If you have a signed module but the signature is blacklisted then it
shouldn't load unless you have a second valid signature.  The bug
here is that an attacker can load the module by adding a SignerInfo
that names a certificate which isn't in the message, with random bytes
as the signature.

The problem is that pkcs7_verify() checks for the blacklist but it
relies on pkcs7_validate_trust() to check if the nonsense signature
is valid.  But pkcs7_validate_trust() says that the blacklisted signature
is in the accepted list and accepts it.

Make pkcs7_validate_trust_one() reject a blacklisted SignerInfo.

Fixes: 03bb79315ddc ("PKCS#7: Handle blacklisted certificates")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 crypto/asymmetric_keys/pkcs7_trust.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/crypto/asymmetric_keys/pkcs7_trust.c b/crypto/asymmetric_keys/pkcs7_trust.c
index 9a87c34ed173..7f8b80c8488a 100644
--- a/crypto/asymmetric_keys/pkcs7_trust.c
+++ b/crypto/asymmetric_keys/pkcs7_trust.c
@@ -30,6 +30,11 @@ static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,
 
 	kenter(",%u,", sinfo->index);
 
+	if (sinfo->blacklisted) {
+		kleave(" = -ENOKEY [blacklisted]");
+		return -ENOKEY;
+	}
+
 	if (sinfo->unsupported_crypto) {
 		kleave(" = -ENOPKG [cached]");
 		return -ENOPKG;

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/5] certs: Fix error checking in is_key_on_revocation_list()
  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  8:22 ` 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
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Dan Carpenter @ 2026-12-01  8:22 UTC (permalink / raw)
  To: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Jarkko Sakkinen, Eric Snowberg
  Cc: Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	Dan Carpenter, stable

The is_key_on_revocation_list() function is a bit unusual because it
always returns errors.  An -EKEYREJECTED error is bad, while -ENOKEY
means the key was not on the revocation list and that's the success
path.

It works by re-using the pkcs7_validate_trust() function to find the key
in the revoked list.  If the key is found that's bad.  If it's not that's
good.  The problem is that pkcs7_validate_trust() gives up early with
-EKEYREJECTED when it encounters an invalid signature.

We could write a different function that doesn't give up instead of
re-using pkcs7_validate_trust(), but in practice a key with a bad
signature should never succeed so just treat that as revoked and return
-EKEYREJECTED.  Or if we hit an -ENOMEM in a non-malicious situation
then we are already scuppered so rejecting the key is fine.

Fixes: 56c5812623f9 ("certs: Add EFI_CERT_X509_GUID support for dbx entries")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 certs/blacklist.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/certs/blacklist.c b/certs/blacklist.c
index fa561c12eabf..abadeeb5baa7 100644
--- a/certs/blacklist.c
+++ b/certs/blacklist.c
@@ -294,6 +294,8 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
 
 	if (ret == 0)
 		return -EKEYREJECTED;
+	if (ret != -ENOKEY && ret != -ENOPKG)
+		return ret;
 
 	return -ENOKEY;
 }

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/5] pkcs7: Clear the ->verified flag before checking trust
  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  8:22 ` [PATCH 2/5] certs: Fix error checking in is_key_on_revocation_list() Dan Carpenter
@ 2026-12-01  8:22 ` 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  8:22 ` [PATCH 5/5] pkcs7: Fix support for subjectKeyIdentifier signers Dan Carpenter
  4 siblings, 1 reply; 12+ messages in thread
From: Dan Carpenter @ 2026-12-01  8:22 UTC (permalink / raw)
  To: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Jarkko Sakkinen, Eric Snowberg
  Cc: Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	Dan Carpenter, stable

The pkcs7_validate_trust() function can be called multiple times.  In
particular we call it with the .blacklist keyring and then again with
the trusted keyring.  The ->verified flag should always be reset to false
at the start so we don't re-use the value from the previous call.

This doesn't affect anything after my previous fixes are applied but it's
obviously the correct thing to do.

Fixes: 56c5812623f9 ("certs: Add EFI_CERT_X509_GUID support for dbx entries")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 crypto/asymmetric_keys/pkcs7_trust.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/crypto/asymmetric_keys/pkcs7_trust.c b/crypto/asymmetric_keys/pkcs7_trust.c
index 7f8b80c8488a..82ff3d2bb4ac 100644
--- a/crypto/asymmetric_keys/pkcs7_trust.c
+++ b/crypto/asymmetric_keys/pkcs7_trust.c
@@ -168,8 +168,10 @@ int pkcs7_validate_trust(struct pkcs7_message *pkcs7,
 	int cached_ret = -ENOKEY;
 	int ret;
 
-	for (p = pkcs7->certs; p; p = p->next)
+	for (p = pkcs7->certs; p; p = p->next) {
 		p->seen = false;
+		p->verified = false;
+	}
 
 	for (sinfo = pkcs7->signed_infos; sinfo; sinfo = sinfo->next) {
 		ret = pkcs7_validate_trust_one(pkcs7, sinfo, trust_keyring);

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/5] pkcs7: Reset the signer identifier fields and check them
  2026-12-01  8:22 [PATCH 0/5] pkcs7: Fix some certificate handling bugs Dan Carpenter
                   ` (2 preceding siblings ...)
  2026-12-01  8:22 ` [PATCH 3/5] pkcs7: Clear the ->verified flag before checking trust Dan Carpenter
@ 2026-12-01  8:22 ` Dan Carpenter
  2026-12-01 16:25   ` Jarkko Sakkinen
  2026-12-01  8:22 ` [PATCH 5/5] pkcs7: Fix support for subjectKeyIdentifier signers Dan Carpenter
  4 siblings, 1 reply; 12+ messages in thread
From: Dan Carpenter @ 2026-12-01  8:22 UTC (permalink / raw)
  To: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Jarkko Sakkinen, Eric Snowberg
  Cc: Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	Dan Carpenter

This bug isn't very serious.

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


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/5] pkcs7: Fix support for subjectKeyIdentifier signers
  2026-12-01  8:22 [PATCH 0/5] pkcs7: Fix some certificate handling bugs Dan Carpenter
                   ` (3 preceding siblings ...)
  2026-12-01  8:22 ` [PATCH 4/5] pkcs7: Reset the signer identifier fields and check them Dan Carpenter
@ 2026-12-01  8:22 ` Dan Carpenter
  4 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2026-12-01  8:22 UTC (permalink / raw)
  To: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Jarkko Sakkinen, Eric Snowberg
  Cc: Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	Dan Carpenter

A version 3 SignerInfo names its signer's certificate by
subjectKeyIdentifier (the ->skid) instead of by issuer and serial number,
but pkcs7_find_key() only checks the ->id.

If the key is in the trusted key ring then the /* As a last resort, see
if we have a trusted public key that matches the signed info directly. */
fallback code in pkcs7_validate_trust_one() will find the correct key.
But intermediate keys are rejected.

Compare the identifier with x509->skid as well.

Fixes: 60d65cacd7c2 ("PKCS#7: Support CMS messages also [RFC5652]")
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 crypto/asymmetric_keys/pkcs7_verify.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/crypto/asymmetric_keys/pkcs7_verify.c b/crypto/asymmetric_keys/pkcs7_verify.c
index 474e2c1ae21b..dc9b69478a52 100644
--- a/crypto/asymmetric_keys/pkcs7_verify.c
+++ b/crypto/asymmetric_keys/pkcs7_verify.c
@@ -187,7 +187,8 @@ static int pkcs7_find_key(struct pkcs7_message *pkcs7,
 		 * PKCS#7 message - but I can't be 100% sure of that.  It's
 		 * possible this will need element-by-element comparison.
 		 */
-		if (!asymmetric_key_id_same(x509->id, sinfo->sig->auth_ids[0]))
+		if (!asymmetric_key_id_same(x509->id, sinfo->sig->auth_ids[0]) &&
+		    !asymmetric_key_id_same(x509->skid, sinfo->sig->auth_ids[0]))
 			continue;
 		pr_devel("Sig %u: Found cert serial match X.509[%u]\n",
 			 sinfo->index, certix);

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/5] pkcs7: Don't trust a blacklisted certificate
  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
  0 siblings, 1 reply; 12+ messages in thread
From: Jarkko Sakkinen @ 2026-12-01 15:42 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Eric Snowberg,
	Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	stable

On Tue, Dec 01, 2026 at 11:22:27AM +0300, Dan Carpenter wrote:
> If you have a signed module but the signature is blacklisted then it
> shouldn't load unless you have a second valid signature.  The bug
> here is that an attacker can load the module by adding a SignerInfo
> that names a certificate which isn't in the message, with random bytes
> as the signature.
> 
> The problem is that pkcs7_verify() checks for the blacklist but it
> relies on pkcs7_validate_trust() to check if the nonsense signature
> is valid.  But pkcs7_validate_trust() says that the blacklisted signature
> is in the accepted list and accepts it.
> 
> Make pkcs7_validate_trust_one() reject a blacklisted SignerInfo.
> 
> Fixes: 03bb79315ddc ("PKCS#7: Handle blacklisted certificates")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan@pereq.eu>
> ---
>  crypto/asymmetric_keys/pkcs7_trust.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/crypto/asymmetric_keys/pkcs7_trust.c b/crypto/asymmetric_keys/pkcs7_trust.c
> index 9a87c34ed173..7f8b80c8488a 100644
> --- a/crypto/asymmetric_keys/pkcs7_trust.c
> +++ b/crypto/asymmetric_keys/pkcs7_trust.c
> @@ -30,6 +30,11 @@ static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,
>  
>  	kenter(",%u,", sinfo->index);
>  
> +	if (sinfo->blacklisted) {
> +		kleave(" = -ENOKEY [blacklisted]");
> +		return -ENOKEY;
> +	}
> +
>  	if (sinfo->unsupported_crypto) {
>  		kleave(" = -ENOPKG [cached]");
>  		return -ENOPKG;
> 
> -- 
> 2.53.0
> 

Clear enough despite drifts a bit from my expertise scope:

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

Br, Jarkko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/5] pkcs7: Don't trust a blacklisted certificate
  2026-12-01 15:42   ` Jarkko Sakkinen
@ 2026-12-01 15:46     ` Jarkko Sakkinen
  0 siblings, 0 replies; 12+ messages in thread
From: Jarkko Sakkinen @ 2026-12-01 15:46 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Eric Snowberg,
	Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	stable

On Tue, Dec 01, 2026 at 05:42:31PM +0200, Jarkko Sakkinen wrote:
> On Tue, Dec 01, 2026 at 11:22:27AM +0300, Dan Carpenter wrote:
> > If you have a signed module but the signature is blacklisted then it
> > shouldn't load unless you have a second valid signature.  The bug
> > here is that an attacker can load the module by adding a SignerInfo
> > that names a certificate which isn't in the message, with random bytes
> > as the signature.

Although I hate this CVE report style in commit messages. Just
stripped down what's the problem without spy story. Reading
about The Attacker is a total waste of cognitive compute.

R-by still applies ;-)

Br, Jarkko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/5] certs: Fix error checking in is_key_on_revocation_list()
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Jarkko Sakkinen @ 2026-12-01 16:22 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Eric Snowberg,
	Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	stable

On Tue, Dec 01, 2026 at 11:22:28AM +0300, Dan Carpenter wrote:
> The is_key_on_revocation_list() function is a bit unusual because it
> always returns errors.  An -EKEYREJECTED error is bad, while -ENOKEY
> means the key was not on the revocation list and that's the success
> path.
> 
> It works by re-using the pkcs7_validate_trust() function to find the key
> in the revoked list.  If the key is found that's bad.  If it's not that's
> good.  The problem is that pkcs7_validate_trust() gives up early with
> -EKEYREJECTED when it encounters an invalid signature.
> 
> We could write a different function that doesn't give up instead of
> re-using pkcs7_validate_trust(), but in practice a key with a bad
> signature should never succeed so just treat that as revoked and return
> -EKEYREJECTED.  Or if we hit an -ENOMEM in a non-malicious situation
> then we are already scuppered so rejecting the key is fine.
> 
> Fixes: 56c5812623f9 ("certs: Add EFI_CERT_X509_GUID support for dbx entries")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan@pereq.eu>
> ---
>  certs/blacklist.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/certs/blacklist.c b/certs/blacklist.c
> index fa561c12eabf..abadeeb5baa7 100644
> --- a/certs/blacklist.c
> +++ b/certs/blacklist.c
> @@ -294,6 +294,8 @@ int is_key_on_revocation_list(struct pkcs7_message *pkcs7)
>  
>  	if (ret == 0)
>  		return -EKEYREJECTED;
> +	if (ret != -ENOKEY && ret != -ENOPKG)
> +		return ret;
>  
>  	return -ENOKEY;
>  }
> 
> -- 
> 2.53.0
> 


Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

Br, Jarkko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/5] pkcs7: Clear the ->verified flag before checking trust
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Jarkko Sakkinen @ 2026-12-01 16:25 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Eric Snowberg,
	Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto,
	stable

On Tue, Dec 01, 2026 at 11:22:29AM +0300, Dan Carpenter wrote:
> The pkcs7_validate_trust() function can be called multiple times.  In
> particular we call it with the .blacklist keyring and then again with
> the trusted keyring.  The ->verified flag should always be reset to false
> at the start so we don't re-use the value from the previous call.
> 
> This doesn't affect anything after my previous fixes are applied but it's
> obviously the correct thing to do.
> 
> Fixes: 56c5812623f9 ("certs: Add EFI_CERT_X509_GUID support for dbx entries")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan@pereq.eu>
> ---
>  crypto/asymmetric_keys/pkcs7_trust.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/crypto/asymmetric_keys/pkcs7_trust.c b/crypto/asymmetric_keys/pkcs7_trust.c
> index 7f8b80c8488a..82ff3d2bb4ac 100644
> --- a/crypto/asymmetric_keys/pkcs7_trust.c
> +++ b/crypto/asymmetric_keys/pkcs7_trust.c
> @@ -168,8 +168,10 @@ int pkcs7_validate_trust(struct pkcs7_message *pkcs7,
>  	int cached_ret = -ENOKEY;
>  	int ret;
>  
> -	for (p = pkcs7->certs; p; p = p->next)
> +	for (p = pkcs7->certs; p; p = p->next) {
>  		p->seen = false;
> +		p->verified = false;
> +	}
>  
>  	for (sinfo = pkcs7->signed_infos; sinfo; sinfo = sinfo->next) {
>  		ret = pkcs7_validate_trust_one(pkcs7, sinfo, trust_keyring);
> 
> -- 
> 2.53.0
> 


Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

I have a fresh recollection of this code as I recently updated my old
patch set [1] and went through asymmetric keys while at it. Thus,
this sudden activity.

[1] https://lore.kernel.org/keyrings/awzN3mJnVJWckleF@kernel.org/T/#rc8d0baf69de43237c2f29a2edfa1c36e11e3035b

Br, Jarkko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/5] pkcs7: Reset the signer identifier fields and check them
  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
  2026-12-01 16:36     ` Dan Carpenter
  0 siblings, 1 reply; 12+ messages in thread
From: Jarkko Sakkinen @ 2026-12-01 16:25 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Eric Snowberg,
	Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/5] pkcs7: Reset the signer identifier fields and check them
  2026-12-01 16:25   ` Jarkko Sakkinen
@ 2026-12-01 16:36     ` Dan Carpenter
  0 siblings, 0 replies; 12+ messages in thread
From: Dan Carpenter @ 2026-12-01 16:36 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, David Woodhouse, Eric Snowberg,
	Karthik Bhargavan, Clément Blaudeau, keyrings, linux-crypto

On Tue, Dec 01, 2026 at 06:25:58PM +0200, Jarkko Sakkinen wrote:
> 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?
> 

It's the same as patch 3.  You shouldn't re-use garbage data left
from the previous call even though the result ends up being the same
either way.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-12-01 16:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-12-01 16:36     ` Dan Carpenter
2026-12-01  8:22 ` [PATCH 5/5] pkcs7: Fix support for subjectKeyIdentifier signers Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox