Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] crypto: tcrypt: avoid 32-bit overflow in throughput calculation
@ 2026-11-26  5:56 Artem Novak
  2026-11-26  5:59 ` sashiko-bot
  2026-11-26  6:05 ` [PATCH v2] " Artem Novak
  0 siblings, 2 replies; 4+ messages in thread
From: Artem Novak @ 2026-11-26  5:56 UTC (permalink / raw)
  To: herbert, davem
  Cc: anirudh.venkataramanan, mark.d.rustad, linux-crypto, linux-kernel,
	Artem Novak

Cast bcount to u64 before multiplying by blen to prevent 32-bit
overflow when calculating throughput on 32-bit architectures.

Fixes: fdaeb224e2bf ("crypto: tcrypt - Use pr_cont to print test results")
Fixes: 3e3dc25fe7d5 ("crypto: Resolve shadow warnings")

Signed-off-by: Artem Novak <artem122novak@gmail.com>
---
 crypto/tcrypt.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index e6834bdde9b9..1e6132045c24 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -28,6 +28,7 @@
 #include <linux/interrupt.h>
 #include <linux/jiffies.h>
 #include <linux/kernel.h>
+#include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/scatterlist.h>
@@ -734,6 +735,7 @@ static int test_ahash_jiffies_digest(struct tcrypt_ahash_request *treq,
 {
 	struct ahash_request *req = treq->req;
 	unsigned long start, end;
+	u64 bytes;
 	int bcount;
 	int ret;
 
@@ -744,8 +746,9 @@ static int test_ahash_jiffies_digest(struct tcrypt_ahash_request *treq,
 			return ret;
 	}
 
-	pr_cont("%6u opers/sec, %9lu bytes/sec\n",
-		bcount / secs, ((long)bcount * blen) / secs);
+	bytes = div_u64((u64)bcount * blen, secs);
+	pr_cont("%6u opers/sec, %9llu bytes/sec\n",
+		bcount / secs, (unsigned long long)bytes);
 
 	return 0;
 }
@@ -755,6 +758,7 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
 {
 	struct ahash_request *req = treq->req;
 	unsigned long start, end;
+	u64 bytes;
 	int bcount, pcount;
 	int ret;
 
@@ -777,8 +781,9 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
 			return ret;
 	}
 
-	pr_cont("%6u opers/sec, %9lu bytes/sec\n",
-		bcount / secs, ((long)bcount * blen) / secs);
+	bytes = div_u64((u64)bcount * blen, secs);
+	pr_cont("%6u opers/sec, %9llu bytes/sec\n",
+		bcount / secs, (unsigned long long)bytes);
 
 	return 0;
 }
-- 
2.56.1


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

* Re: [PATCH] crypto: tcrypt: avoid 32-bit overflow in throughput calculation
  2026-11-26  5:56 [PATCH] crypto: tcrypt: avoid 32-bit overflow in throughput calculation Artem Novak
@ 2026-11-26  5:59 ` sashiko-bot
  2026-11-26  6:05 ` [PATCH v2] " Artem Novak
  1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-26  5:59 UTC (permalink / raw)
  To: Artem Novak, herbert, davem
  Cc: anirudh.venkataramanan, mark.d.rustad, linux-crypto

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] crypto: tcrypt: inaccurate Fixes trailers for 32-bit throughput
  overflow
--

commit 511920037074a37ed1b8de2506cd7025bc33e2ab
Author: Artem Novak <artem122novak@gmail.com>

> crypto: tcrypt: avoid 32-bit overflow in throughput calculation
>
> Cast bcount to u64 before multiplying by blen to prevent 32-bit
> overflow when calculating throughput on 32-bit architectures.
>
> Fixes: fdaeb224e2bf ("crypto: tcrypt - Use pr_cont to print test results")
> Fixes: 3e3dc25fe7d5 ("crypto: Resolve shadow warnings")
>
> Signed-off-by: Artem Novak <artem122novak@gmail.com>

[Severity: Low]
Are these Fixes: tags pointing to the right commit?  fdaeb224e2bf ("crypto:
tcrypt - Use pr_cont to print test results") only converted printk() to
pr_cont(), and 3e3dc25fe7d5 ("crypto: Resolve shadow warnings") only
renamed sec to secs.  Both test_ahash_jiffies_digest() and
test_ahash_jiffies() along with their ((long)bcount * blen) / sec
throughput calculations were introduced by:

  Fixes: beb63da739f7 ("crypto: tcrypt - Add speed tests for async hashing")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126055600.23172-1-artem122novak@gmail.com?part=1

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

* [PATCH v2] crypto: tcrypt: avoid 32-bit overflow in throughput calculation
  2026-11-26  5:56 [PATCH] crypto: tcrypt: avoid 32-bit overflow in throughput calculation Artem Novak
  2026-11-26  5:59 ` sashiko-bot
@ 2026-11-26  6:05 ` Artem Novak
  2026-11-26  6:14   ` Artem Novak
  1 sibling, 1 reply; 4+ messages in thread
From: Artem Novak @ 2026-11-26  6:05 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-crypto, linux-kernel, Artem Novak

Cast bcount to u64 before multiplying by blen to prevent 32-bit
overflow when calculating throughput on 32-bit architectures.

Fixes: beb63da739f7 ("crypto: tcrypt - Add speed tests for async hashing")

Signed-off-by: Artem Novak <artem122novak@gmail.com>
---
 crypto/tcrypt.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index e6834bdde9b9..1e6132045c24 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -28,6 +28,7 @@
 #include <linux/interrupt.h>
 #include <linux/jiffies.h>
 #include <linux/kernel.h>
+#include <linux/math64.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/scatterlist.h>
@@ -734,6 +735,7 @@ static int test_ahash_jiffies_digest(struct tcrypt_ahash_request *treq,
 {
 	struct ahash_request *req = treq->req;
 	unsigned long start, end;
+	u64 bytes;
 	int bcount;
 	int ret;
 
@@ -744,8 +746,9 @@ static int test_ahash_jiffies_digest(struct tcrypt_ahash_request *treq,
 			return ret;
 	}
 
-	pr_cont("%6u opers/sec, %9lu bytes/sec\n",
-		bcount / secs, ((long)bcount * blen) / secs);
+	bytes = div_u64((u64)bcount * blen, secs);
+	pr_cont("%6u opers/sec, %9llu bytes/sec\n",
+		bcount / secs, (unsigned long long)bytes);
 
 	return 0;
 }
@@ -755,6 +758,7 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
 {
 	struct ahash_request *req = treq->req;
 	unsigned long start, end;
+	u64 bytes;
 	int bcount, pcount;
 	int ret;
 
@@ -777,8 +781,9 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
 			return ret;
 	}
 
-	pr_cont("%6u opers/sec, %9lu bytes/sec\n",
-		bcount / secs, ((long)bcount * blen) / secs);
+	bytes = div_u64((u64)bcount * blen, secs);
+	pr_cont("%6u opers/sec, %9llu bytes/sec\n",
+		bcount / secs, (unsigned long long)bytes);
 
 	return 0;
 }
-- 
2.56.1


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

* Re: [PATCH v2] crypto: tcrypt: avoid 32-bit overflow in throughput calculation
  2026-11-26  6:05 ` [PATCH v2] " Artem Novak
@ 2026-11-26  6:14   ` Artem Novak
  0 siblings, 0 replies; 4+ messages in thread
From: Artem Novak @ 2026-11-26  6:14 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-crypto, linux-kernel

Sorry for the confusion in v1.

I accidentally included the two Fixes: tags below.
On Wed, Nov 25, 2026 at 11:56 PM Artem Novak <artem122novak@gmail.com> wrote:
>> Fixes: fdaeb224e2bf ("crypto: tcrypt - Use pr_cont to print test results")
>> Fixes: 3e3dc25fe7d5 ("crypto: Resolve shadow warnings")
(they belong to other work),
which refer to unrelated changes rather than the commit that introduced the bug;
I've corrected this in v2.

Best regards,
Artem

On Thu, Nov 26, 2026 at 12:05 AM Artem Novak <artem122novak@gmail.com> wrote:
>
> Cast bcount to u64 before multiplying by blen to prevent 32-bit
> overflow when calculating throughput on 32-bit architectures.
>
> Fixes: beb63da739f7 ("crypto: tcrypt - Add speed tests for async hashing")
>
> Signed-off-by: Artem Novak <artem122novak@gmail.com>
> ---
>  crypto/tcrypt.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
> index e6834bdde9b9..1e6132045c24 100644
> --- a/crypto/tcrypt.c
> +++ b/crypto/tcrypt.c
> @@ -28,6 +28,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/jiffies.h>
>  #include <linux/kernel.h>
> +#include <linux/math64.h>
>  #include <linux/module.h>
>  #include <linux/moduleparam.h>
>  #include <linux/scatterlist.h>
> @@ -734,6 +735,7 @@ static int test_ahash_jiffies_digest(struct tcrypt_ahash_request *treq,
>  {
>         struct ahash_request *req = treq->req;
>         unsigned long start, end;
> +       u64 bytes;
>         int bcount;
>         int ret;
>
> @@ -744,8 +746,9 @@ static int test_ahash_jiffies_digest(struct tcrypt_ahash_request *treq,
>                         return ret;
>         }
>
> -       pr_cont("%6u opers/sec, %9lu bytes/sec\n",
> -               bcount / secs, ((long)bcount * blen) / secs);
> +       bytes = div_u64((u64)bcount * blen, secs);
> +       pr_cont("%6u opers/sec, %9llu bytes/sec\n",
> +               bcount / secs, (unsigned long long)bytes);
>
>         return 0;
>  }
> @@ -755,6 +758,7 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
>  {
>         struct ahash_request *req = treq->req;
>         unsigned long start, end;
> +       u64 bytes;
>         int bcount, pcount;
>         int ret;
>
> @@ -777,8 +781,9 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
>                         return ret;
>         }
>
> -       pr_cont("%6u opers/sec, %9lu bytes/sec\n",
> -               bcount / secs, ((long)bcount * blen) / secs);
> +       bytes = div_u64((u64)bcount * blen, secs);
> +       pr_cont("%6u opers/sec, %9llu bytes/sec\n",
> +               bcount / secs, (unsigned long long)bytes);
>
>         return 0;
>  }
> --
> 2.56.1
>

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

end of thread, other threads:[~2026-11-26  6:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  5:56 [PATCH] crypto: tcrypt: avoid 32-bit overflow in throughput calculation Artem Novak
2026-11-26  5:59 ` sashiko-bot
2026-11-26  6:05 ` [PATCH v2] " Artem Novak
2026-11-26  6:14   ` Artem Novak

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