Skip to contentSkip to conversation

crypto: sm3 - fix undefined shift by >= width of value

PATCH In review Eric Biggers 2 participants 2 messages Jan 9, 2019 – Jan 10, 2019 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: sm3 - fix undefined shift by >= width of value

From: Eric Biggers <[email protected]>

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 <[email protected]> # v4.15+
Cc Gilad Ben-Yossef <[email protected]>
---
 crypto/sm3_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/sm3_generic.c +1 -1
index 9a5c60f08aad8..c0cf87ae7ef6d 100644
@@ -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);
 
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 7 lines · Eric Biggers

From: Eric Biggers <[email protected]>

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.

Quoted 7 lines
Fixes 4f0fc1600edb ("crypto: sm3 - add OSCCA SM3 secure hash")
Cc <[email protected]> # v4.15+
Cc Gilad Ben-Yossef <[email protected]>
---
 crypto/sm3_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt