All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: sm3 - fix undefined shift by >= width of value
@ 2019-01-09  6:12 Eric Biggers
  2019-01-10 14:06 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2019-01-09  6:12 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu; +Cc: Gilad Ben-Yossef

From: Eric Biggers <ebiggers@google.com>

sm3_compress() calls rol32() with shift >= 32, which causes undefined
behavior.  This is easily detected by enabling CONFIG_UBSAN.

Explicitly AND with 31 to make the behavior well defined.

Fixes: 4f0fc1600edb ("crypto: sm3 - add OSCCA SM3 secure hash")
Cc: <stable@vger.kernel.org> # v4.15+
Cc: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/sm3_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/sm3_generic.c b/crypto/sm3_generic.c
index 9a5c60f08aad8..c0cf87ae7ef6d 100644
--- a/crypto/sm3_generic.c
+++ b/crypto/sm3_generic.c
@@ -100,7 +100,7 @@ static void sm3_compress(u32 *w, u32 *wt, u32 *m)
 
 	for (i = 0; i <= 63; i++) {
 
-		ss1 = rol32((rol32(a, 12) + e + rol32(t(i), i)), 7);
+		ss1 = rol32((rol32(a, 12) + e + rol32(t(i), i & 31)), 7);
 
 		ss2 = ss1 ^ rol32(a, 12);
 
-- 
2.20.1

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

* Re: [PATCH] crypto: sm3 - fix undefined shift by >= width of value
  2019-01-09  6:12 [PATCH] crypto: sm3 - fix undefined shift by >= width of value Eric Biggers
@ 2019-01-10 14:06 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2019-01-10 14:06 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-crypto, Gilad Ben-Yossef

On Tue, Jan 08, 2019 at 10:12:41PM -0800, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> sm3_compress() calls rol32() with shift >= 32, which causes undefined
> behavior.  This is easily detected by enabling CONFIG_UBSAN.
> 
> Explicitly AND with 31 to make the behavior well defined.
> 
> Fixes: 4f0fc1600edb ("crypto: sm3 - add OSCCA SM3 secure hash")
> Cc: <stable@vger.kernel.org> # v4.15+
> Cc: Gilad Ben-Yossef <gilad@benyossef.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>  crypto/sm3_generic.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2019-01-10 14:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-09  6:12 [PATCH] crypto: sm3 - fix undefined shift by >= width of value Eric Biggers
2019-01-10 14:06 ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.