Linux kernel -stable discussions
 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
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ 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] 6+ 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
  2026-12-01  8:22 ` [PATCH 3/5] pkcs7: Clear the ->verified flag before checking trust Dan Carpenter
  2 siblings, 1 reply; 6+ 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] 6+ 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  8:22 ` [PATCH 3/5] pkcs7: Clear the ->verified flag before checking trust Dan Carpenter
  2 siblings, 0 replies; 6+ 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] 6+ 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
  2 siblings, 0 replies; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ messages in thread

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

Thread overview: 6+ 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  8:22 ` [PATCH 3/5] pkcs7: Clear the ->verified flag before checking trust Dan Carpenter

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