linux-brain/include/crypto
Eric Biggers 81ad8a8e86 crypto: vmac - separate tfm and request context
commit bb29648102 upstream.

syzbot reported a crash in vmac_final() when multiple threads
concurrently use the same "vmac(aes)" transform through AF_ALG.  The bug
is pretty fundamental: the VMAC template doesn't separate per-request
state from per-tfm (per-key) state like the other hash algorithms do,
but rather stores it all in the tfm context.  That's wrong.

Also, vmac_final() incorrectly zeroes most of the state including the
derived keys and cached pseudorandom pad.  Therefore, only the first
VMAC invocation with a given key calculates the correct digest.

Fix these bugs by splitting the per-tfm state from the per-request state
and using the proper init/update/final sequencing for requests.

Reproducer for the crash:

    #include <linux/if_alg.h>
    #include <sys/socket.h>
    #include <unistd.h>

    int main()
    {
            int fd;
            struct sockaddr_alg addr = {
                    .salg_type = "hash",
                    .salg_name = "vmac(aes)",
            };
            char buf[256] = { 0 };

            fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
            bind(fd, (void *)&addr, sizeof(addr));
            setsockopt(fd, SOL_ALG, ALG_SET_KEY, buf, 16);
            fork();
            fd = accept(fd, NULL, NULL);
            for (;;)
                    write(fd, buf, 256);
    }

The immediate cause of the crash is that vmac_ctx_t.partial_size exceeds
VMAC_NHBYTES, causing vmac_final() to memset() a negative length.

Reported-by: syzbot+264bca3a6e8d645550d3@syzkaller.appspotmail.com
Fixes: f1939f7c56 ("crypto: vmac - New hash algorithm for intel_txt support")
Cc: <stable@vger.kernel.org> # v2.6.32+
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>
2018-08-17 20:59:29 +02:00
..
internal crypto: hash - introduce crypto_hash_alg_has_setkey() 2018-02-17 13:21:15 +01:00
ablk_helper.h crypto: create generic version of ablk_helper 2013-09-24 06:02:24 +10:00
aead.h crypto: aead - Add chunk size 2016-07-18 17:35:38 +08:00
aes.h crypto: aes - Move key_length in struct crypto_aes_ctx to be the last field 2009-02-18 16:48:04 +08:00
akcipher.h crypto: doc - add akcipher API 2016-02-17 04:07:53 +08:00
algapi.h crypto: engine - move crypto engine to its own header 2016-09-07 21:08:26 +08:00
authenc.h crypto: authenc - Export key parsing helper function 2013-10-16 20:56:25 +08:00
b128ops.h [CRYPTO] lib: some common 128-bit block operations, nicely centralized 2006-12-06 18:38:55 -08:00
blowfish.h crypto: blowfish - split generic and common c code 2011-09-22 21:25:25 +10:00
cast_common.h crypto: cast5/cast6 - move lookup tables to shared module 2012-12-06 17:16:26 +08:00
cast5.h crypto: cast5/cast6 - move lookup tables to shared module 2012-12-06 17:16:26 +08:00
cast6.h crypto: cast5/cast6 - move lookup tables to shared module 2012-12-06 17:16:26 +08:00
chacha20.h random: replace non-blocking pool with a Chacha20-based CRNG 2016-07-03 00:57:23 -04:00
cryptd.h crypto: cryptd - Add helpers to check whether a tfm is queued 2016-06-23 18:29:52 +08:00
crypto_wq.h crypto: api - Use dedicated workqueue for crypto subsystem 2009-02-19 14:33:40 +08:00
ctr.h [CRYPTO] ctr: Refactor into ctr and rfc3686 2008-01-11 08:16:41 +11:00
des.h crypto: des_3des - add x86-64 assembly implementation 2014-06-20 21:27:58 +08:00
dh.h crypto: dh - Add DH software implementation 2016-06-23 18:29:56 +08:00
drbg.h crypto: drbg - prevent invalid SG mappings 2016-11-30 19:46:44 +08:00
ecdh.h crypto: ecdh - Add ECDH software support 2016-06-23 18:29:57 +08:00
engine.h crypto: engine - permit to enqueue ashash_request 2016-09-07 21:08:27 +08:00
gf128mul.h Update broken web addresses in the kernel. 2010-10-18 11:03:14 +02:00
ghash.h crypto: ghash-generic - move common definitions to a new header file 2016-10-02 22:26:40 +08:00
hash_info.h keys, trusted: select hash algorithm for TPM2 chips 2015-12-20 15:27:12 +02:00
hash.h crypto: hash - prevent using keyed hashes without setting key 2018-02-25 11:05:44 +01:00
if_alg.h crypto: af_alg - Allow af_af_alg_release_parent to be called on nokey path 2016-01-18 18:16:32 +08:00
kpp.h crypto: ecdh - Add ECDH software support 2016-06-23 18:29:57 +08:00
lrw.h crypto: lrw - add interface for parallelized cipher implementions 2011-11-09 11:50:31 +08:00
mcryptd.h crypto: mcryptd - protect the per-CPU queue with a lock 2017-12-29 17:42:58 +01:00
md5.h crypto: hash - add zero length message hash for shax and md5 2015-12-22 20:43:35 +08:00
null.h crypto: null - Remove default null blkcipher 2016-07-18 17:35:44 +08:00
padlock.h crypto: padlock - Move padlock.h into include/crypto 2011-01-07 14:52:00 +11:00
pcrypt.h crypto: pcrypt - Add pcrypt crypto parallelization wrapper 2010-01-07 15:57:19 +11:00
pkcs7.h PKCS#7: Make trust determination dependent on contents of trust keyring 2016-04-06 16:14:24 +01:00
poly1305.h crypto: poly1305 - remove ->setkey() method 2018-02-17 13:21:15 +01:00
public_key.h KEYS: Move the point of trust determination to __key_link() 2016-04-11 22:43:43 +01:00
rng.h crypto: doc - Fix typo in crypto-API.xml 2015-06-04 15:05:08 +08:00
scatterwalk.h crypto: scatterwalk - Inline start/map/done 2016-07-18 17:35:50 +08:00
serpent.h crypto: serpent-sse2 - add lrw support 2011-11-21 16:13:24 +08:00
sha.h crypto: hash - add zero length message hash for shax and md5 2015-12-22 20:43:35 +08:00
sha1_base.h crypto: sha1 - implement base layer for SHA-1 2015-04-10 21:39:39 +08:00
sha3.h crypto: sha3 - Add SHA-3 hash algorithm 2016-06-20 19:25:01 +08:00
sha256_base.h crypto: sha256 - implement base layer for SHA-256 2015-04-10 21:39:39 +08:00
sha512_base.h crypto: sha512 - implement base layer for SHA-512 2015-04-10 21:39:39 +08:00
skcipher.h crypto: skcipher - Add comment for skcipher_alg->base 2016-07-19 15:42:42 +08:00
twofish.h crypto: twofish-x86_64-3way - add lrw support 2011-11-09 11:53:32 +08:00
xts.h crypto: xts - consolidate sanity check for keys 2016-02-17 04:07:51 +08:00