Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH 0/4] crypto: miscellaneous small fixes
@ 2026-12-04  8:37 Dan Carpenter
  2026-12-04  8:37 ` [PATCH 1/4] crypto: rsassa-pkcs1 - Fix check for no hash prefix Dan Carpenter
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Dan Carpenter @ 2026-12-04  8:37 UTC (permalink / raw)
  To: Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller,
	Joy Latten, David Howells, Robbie Harwood, Vivek Goyal
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-crypto, keyrings,
	Dan Carpenter

These are some small bugs found by an audit at Pereq.  We found a bunch
of other place which didn't implement the RFC correctly or whatever.
But they didn't have a security impact and the code is old and it's not
clear that any users will ever hit them.

However, these are small obvious one liners.  I have tested these with
live reproducers except the patch 3 where just I changed
"smaller > bigger" to "bigger > smaller" in the warning output.

Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
Dan Carpenter (4):
      crypto: rsassa-pkcs1 - Fix check for no hash prefix
      crypto: ccm - Fix off-by-one in set_msg_len()
      crypto: asymmetric_keys - Fix warning in pefile_strip_sig_wrapper()
      crypto: asymmetric_keys - Print the correct offset in a debug message

 crypto/asymmetric_keys/pkcs7_parser.c  | 2 +-
 crypto/asymmetric_keys/verify_pefile.c | 2 +-
 crypto/ccm.c                           | 2 +-
 crypto/rsassa-pkcs1.c                  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
---
base-commit: a9c48428cbd8d96b26f92631d0db6f8519c5fcc5
change-id: 20261204-crypto_trivial-d2c81ab1f1df

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


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

* [PATCH 1/4] crypto: rsassa-pkcs1 - Fix check for no hash prefix
  2026-12-04  8:37 [PATCH 0/4] crypto: miscellaneous small fixes Dan Carpenter
@ 2026-12-04  8:37 ` Dan Carpenter
  2026-12-04  8:37 ` [PATCH 2/4] crypto: ccm - Fix off-by-one in set_msg_len() Dan Carpenter
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2026-12-04  8:37 UTC (permalink / raw)
  To: Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller,
	Joy Latten, David Howells, Robbie Harwood, Vivek Goyal
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-crypto, keyrings,
	Dan Carpenter

The test:

	if (p->data == hash_prefix_none)
		return false;

is supposed to test if we don't have a hash prefix.  However it
doesn't work since hash_prefix_none[] is a zero length array and the
compiler puts it next to something else.  Where it goes exactly
depends on the compiler and the features.  But, for example, if you
are using GCC with the -fno-toplevel-reorder it will be the same
address as hash_prefix_md5[] and md5 hashes accidentally return early.

Test for if "p->size" instead.

We still verify the whole digest so this doesn't have any real security
impact.

Fixes: a03a728e377a ("crypto: rsassa-pkcs1 - Reinstate support for legacy protocols")
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 crypto/rsassa-pkcs1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/rsassa-pkcs1.c b/crypto/rsassa-pkcs1.c
index 39137476ce81..fc91afbc7fee 100644
--- a/crypto/rsassa-pkcs1.c
+++ b/crypto/rsassa-pkcs1.c
@@ -130,7 +130,7 @@ static bool rsassa_pkcs1_invalid_hash_len(unsigned int len,
 	 * do not prepend a Full Hash Prefix to the hash.  In that case,
 	 * the size of the Full Hash Prefix is zero.
 	 */
-	if (p->data == hash_prefix_none)
+	if (!p->size)
 		return false;
 
 	/*

-- 
2.53.0


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

* [PATCH 2/4] crypto: ccm - Fix off-by-one in set_msg_len()
  2026-12-04  8:37 [PATCH 0/4] crypto: miscellaneous small fixes Dan Carpenter
  2026-12-04  8:37 ` [PATCH 1/4] crypto: rsassa-pkcs1 - Fix check for no hash prefix Dan Carpenter
@ 2026-12-04  8:37 ` Dan Carpenter
  2026-12-04  8:37 ` [PATCH 3/4] crypto: asymmetric_keys - Fix warning in pefile_strip_sig_wrapper() Dan Carpenter
  2026-12-04  8:37 ` [PATCH 4/4] crypto: asymmetric_keys - Print the correct offset in a debug message Dan Carpenter
  3 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2026-12-04  8:37 UTC (permalink / raw)
  To: Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller,
	Joy Latten, David Howells, Robbie Harwood, Vivek Goyal
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-crypto, keyrings,
	Dan Carpenter

RFC 3610 specifies the message length in section 2.1. (Inputs) as:

   3.  The message m, consisting of a string of l(m) octets where 0 <=
       l(m) < 2^(8L).  The length restriction ensures that l(m) can be
       encoded in a field of L octets.

So this limit check should be >= instead of >.

Nothing is really affected by this except everyone will refuse to
decrypt your data.  Also you have to be a privileged user to hit this
bug.

Fixes: 4a49b499dfa0 ("[CRYPTO] ccm: Added CCM mode")
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 crypto/ccm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/ccm.c b/crypto/ccm.c
index 916441e4f2b8..b7ed78b7a168 100644
--- a/crypto/ccm.c
+++ b/crypto/ccm.c
@@ -72,7 +72,7 @@ static int set_msg_len(u8 *block, unsigned int msglen, int csize)
 
 	if (csize >= 4)
 		csize = 4;
-	else if (msglen > (1 << (8 * csize)))
+	else if (msglen >= (1 << (8 * csize)))
 		return -EOVERFLOW;
 
 	data = cpu_to_be32(msglen);

-- 
2.53.0


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

* [PATCH 3/4] crypto: asymmetric_keys - Fix warning in pefile_strip_sig_wrapper()
  2026-12-04  8:37 [PATCH 0/4] crypto: miscellaneous small fixes Dan Carpenter
  2026-12-04  8:37 ` [PATCH 1/4] crypto: rsassa-pkcs1 - Fix check for no hash prefix Dan Carpenter
  2026-12-04  8:37 ` [PATCH 2/4] crypto: ccm - Fix off-by-one in set_msg_len() Dan Carpenter
@ 2026-12-04  8:37 ` Dan Carpenter
  2026-12-04  8:37 ` [PATCH 4/4] crypto: asymmetric_keys - Print the correct offset in a debug message Dan Carpenter
  3 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2026-12-04  8:37 UTC (permalink / raw)
  To: Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller,
	Joy Latten, David Howells, Robbie Harwood, Vivek Goyal
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-crypto, keyrings,
	Dan Carpenter

The order is reversed so the error message says the smaller number
is larger than the bigger number.  Flip it.

Fixes: 4fc5c74dde69 ("verify_pefile: relax wrapper length check")
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 crypto/asymmetric_keys/verify_pefile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/asymmetric_keys/verify_pefile.c b/crypto/asymmetric_keys/verify_pefile.c
index 23918e3dfd47..18f5183872a1 100644
--- a/crypto/asymmetric_keys/verify_pefile.c
+++ b/crypto/asymmetric_keys/verify_pefile.c
@@ -148,7 +148,7 @@ static int pefile_strip_sig_wrapper(const void *pebuf,
 	 */
 	if (wrapper.length > ctx->sig_len) {
 		pr_warn("Signature wrapper bigger than sig len (%x > %x)\n",
-			ctx->sig_len, wrapper.length);
+			wrapper.length, ctx->sig_len);
 		return -ELIBBAD;
 	}
 	if (wrapper.length < sizeof(wrapper)) {

-- 
2.53.0


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

* [PATCH 4/4] crypto: asymmetric_keys - Print the correct offset in a debug message
  2026-12-04  8:37 [PATCH 0/4] crypto: miscellaneous small fixes Dan Carpenter
                   ` (2 preceding siblings ...)
  2026-12-04  8:37 ` [PATCH 3/4] crypto: asymmetric_keys - Fix warning in pefile_strip_sig_wrapper() Dan Carpenter
@ 2026-12-04  8:37 ` Dan Carpenter
  2026-12-04  8:52   ` sashiko-bot
  3 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2026-12-04  8:37 UTC (permalink / raw)
  To: Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller,
	Joy Latten, David Howells, Robbie Harwood, Vivek Goyal
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-crypto, keyrings,
	Dan Carpenter

This debug message prints the wrong offset:

Old: PKCS7: Cert began with tag 04 at 259674912
New: PKCS7: Cert began with tag 04 at 52

Fixes: 2e3fadbf730f ("PKCS#7: Implement a parser [RFC 2315]")
Signed-off-by: Dan Carpenter <dan@pereq.eu>
---
 crypto/asymmetric_keys/pkcs7_parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c
index 7f00e45a33cf..c5dd638a50fe 100644
--- a/crypto/asymmetric_keys/pkcs7_parser.c
+++ b/crypto/asymmetric_keys/pkcs7_parser.c
@@ -445,7 +445,7 @@ int pkcs7_extract_cert(void *context, size_t hdrlen,
 
 	if (tag != ((ASN1_UNIV << 6) | ASN1_CONS_BIT | ASN1_SEQ)) {
 		pr_debug("Cert began with tag %02x at %lu\n",
-			 tag, (unsigned long)ctx - ctx->data);
+			 tag, (unsigned long)value - ctx->data);
 		return -EBADMSG;
 	}
 

-- 
2.53.0


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

* Re: [PATCH 4/4] crypto: asymmetric_keys - Print the correct offset in a debug message
  2026-12-04  8:37 ` [PATCH 4/4] crypto: asymmetric_keys - Print the correct offset in a debug message Dan Carpenter
@ 2026-12-04  8:52   ` sashiko-bot
  2026-12-04 11:36     ` Dan Carpenter
  0 siblings, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-12-04  8:52 UTC (permalink / raw)
  To: Dan Carpenter, Lukas Wunner, Ignat Korchagin, Herbert Xu,
	David S. Miller, Joy Latten, David Howells, Robbie Harwood,
	Vivek Goyal
  Cc: Karthik Bhargavan, Clément Blaudeau, linux-crypto, keyrings

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] crypto: off-by-hdrlen debug offset in pkcs7_extract_cert()
--

commit f0faf0419a12880593a89a85374f99bb1edc3463
Author: Dan Carpenter <dan@pereq.eu>

crypto: asymmetric_keys - Print the correct offset in a debug message

This commit updates a pr_debug() call in pkcs7_extract_cert() to compute
the logged offset from value instead of ctx.

> diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c
> index 7f00e45a33cf6..c5dd638a50fe4 100644
> --- a/crypto/asymmetric_keys/pkcs7_parser.c
> +++ b/crypto/asymmetric_keys/pkcs7_parser.c
> @@ -445,7 +445,7 @@ int pkcs7_extract_cert(void *context, size_t hdrlen,
>  
>  	if (tag != ((ASN1_UNIV << 6) | ASN1_CONS_BIT | ASN1_SEQ)) {
>  		pr_debug("Cert began with tag %02x at %lu\n",
> -			 tag, (unsigned long)ctx - ctx->data);
> +			 tag, (unsigned long)value - ctx->data);
>  		return -EBADMSG;
>  	}

[Severity: Low]
Should this subtract hdrlen from value when computing the offset?

asn1_ber_decoder() advances past the tag and length header before invoking
the action, so value points to the payload rather than the tag byte, as
shown right below where value is adjusted by hdrlen for x509_cert_parse().
The debug message therefore logs an offset hdrlen bytes past the tag.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-crypto_trivial-v1-0-9e0865f6d9ff@pereq.eu?part=4

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

* Re: [PATCH 4/4] crypto: asymmetric_keys - Print the correct offset in a debug message
  2026-12-04  8:52   ` sashiko-bot
@ 2026-12-04 11:36     ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2026-12-04 11:36 UTC (permalink / raw)
  To: sashiko-reviews
  Cc: Lukas Wunner, Ignat Korchagin, Herbert Xu, David S. Miller,
	Joy Latten, David Howells, Robbie Harwood, Vivek Goyal,
	Karthik Bhargavan, Clément Blaudeau, linux-crypto, keyrings

On Fri, Dec 04, 2026 at 08:52:20AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Low] crypto: off-by-hdrlen debug offset in pkcs7_extract_cert()
> --
> 
> commit f0faf0419a12880593a89a85374f99bb1edc3463
> Author: Dan Carpenter <dan@pereq.eu>
> 
> crypto: asymmetric_keys - Print the correct offset in a debug message
> 
> This commit updates a pr_debug() call in pkcs7_extract_cert() to compute
> the logged offset from value instead of ctx.
> 
> > diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c
> > index 7f00e45a33cf6..c5dd638a50fe4 100644
> > --- a/crypto/asymmetric_keys/pkcs7_parser.c
> > +++ b/crypto/asymmetric_keys/pkcs7_parser.c
> > @@ -445,7 +445,7 @@ int pkcs7_extract_cert(void *context, size_t hdrlen,
> >  
> >  	if (tag != ((ASN1_UNIV << 6) | ASN1_CONS_BIT | ASN1_SEQ)) {
> >  		pr_debug("Cert began with tag %02x at %lu\n",
> > -			 tag, (unsigned long)ctx - ctx->data);
> > +			 tag, (unsigned long)value - ctx->data);
> >  		return -EBADMSG;
> >  	}
> 
> [Severity: Low]
> Should this subtract hdrlen from value when computing the offset?
> 
> asn1_ber_decoder() advances past the tag and length header before invoking
> the action, so value points to the payload rather than the tag byte, as
> shown right below where value is adjusted by hdrlen for x509_cert_parse().
> The debug message therefore logs an offset hdrlen bytes past the tag.
> 

Sashiko is correct.  It should be
"(unsigned long)value - hdrlen - ctx->data".  I copy and pasted bad code.
I'll fix the other code too:

Old: PKCS7: Unknown OID: [39] 1.2.3.4
     PKCS7: Cert began with tag 04 at 311626400

New: PKCS7: Unknown OID: [37] 1.2.3.4
     PKCS7: Cert began with tag 04 at 57

regards,
dan carpenter

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

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  8:37 [PATCH 0/4] crypto: miscellaneous small fixes Dan Carpenter
2026-12-04  8:37 ` [PATCH 1/4] crypto: rsassa-pkcs1 - Fix check for no hash prefix Dan Carpenter
2026-12-04  8:37 ` [PATCH 2/4] crypto: ccm - Fix off-by-one in set_msg_len() Dan Carpenter
2026-12-04  8:37 ` [PATCH 3/4] crypto: asymmetric_keys - Fix warning in pefile_strip_sig_wrapper() Dan Carpenter
2026-12-04  8:37 ` [PATCH 4/4] crypto: asymmetric_keys - Print the correct offset in a debug message Dan Carpenter
2026-12-04  8:52   ` sashiko-bot
2026-12-04 11:36     ` Dan Carpenter

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