]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
crypto: sm3 - fix undefined shift by >= width of value
authorEric Biggers <ebiggers@google.com>
Wed, 9 Jan 2019 06:12:41 +0000 (22:12 -0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837477
commit d45a90cb5d061fa7d411b974b950fe0b8bc5f265 upstream.

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>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
crypto/sm3_generic.c

index 9e823d99f095f714015f5f6c37253f593170bf0e..68b8f791685c6808bbe53750f97ab05c9a865c68 100644 (file)
@@ -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);