android_kernel_samsung_msm8976/arch
Eric Biggers 7be193871e crypto: salsa20 - fix blkcipher_walk API usage
commit ecaaab5649781c5a0effdaf298a925063020500e upstream.

When asked to encrypt or decrypt 0 bytes, both the generic and x86
implementations of Salsa20 crash in blkcipher_walk_done(), either when
doing 'kfree(walk->buffer)' or 'free_page((unsigned long)walk->page)',
because walk->buffer and walk->page have not been initialized.

The bug is that Salsa20 is calling blkcipher_walk_done() even when
nothing is in 'walk.nbytes'.  But blkcipher_walk_done() is only meant to
be called when a nonzero number of bytes have been provided.

The broken code is part of an optimization that tries to make only one
call to salsa20_encrypt_bytes() to process inputs that are not evenly
divisible by 64 bytes.  To fix the bug, just remove this "optimization"
and use the blkcipher_walk API the same way all the other users do.

Reproducer:

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

    int main()
    {
            int algfd, reqfd;
            struct sockaddr_alg addr = {
                    .salg_type = "skcipher",
                    .salg_name = "salsa20",
            };
            char key[16] = { 0 };

            algfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
            bind(algfd, (void *)&addr, sizeof(addr));
            reqfd = accept(algfd, 0, 0);
            setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, sizeof(key));
            read(reqfd, key, sizeof(key));
    }

Reported-by: syzbot <syzkaller@googlegroups.com>
Fixes: eb6f13eb9f ("[CRYPTO] salsa20_generic: Fix multi-page processing")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
2019-07-27 21:45:46 +02:00
..
alpha Safer ABI for O_TMPFILE 2018-12-03 11:52:36 +01:00
arc mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
arm ARM: 8720/1: ensure dump_instr() checks addr_limit 2019-07-27 21:45:44 +02:00
arm64 UPSTREAM: arm64: vdso: Mark vDSO code as read-only 2019-07-27 21:45:21 +02:00
avr32
blackfin
c6x
cris
frv mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
h8300
hexagon
ia64 Import latest Samsung release 2017-04-18 03:43:52 +02:00
m32r This is the 3.10.98 stable release 2017-04-18 17:17:24 +02:00
m68k Merge remote-tracking branch 'f2fs/linux-3.10.y' into HEAD 2017-04-18 17:02:28 +02:00
metag
microblaze
mips mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
mn10300 This is the 3.10.96 stable release 2017-04-18 17:16:02 +02:00
openrisc This is the 3.10.96 stable release 2017-04-18 17:16:02 +02:00
parisc Safer ABI for O_TMPFILE 2018-12-03 11:52:36 +01:00
powerpc mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
s390 This is the 3.10.99 stable release 2017-04-18 17:17:46 +02:00
score
sh mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
sparc Safer ABI for O_TMPFILE 2018-12-03 11:52:36 +01:00
tile mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
um This is the 3.10.99 stable release 2017-04-18 17:17:46 +02:00
unicore32
x86 crypto: salsa20 - fix blkcipher_walk API usage 2019-07-27 21:45:46 +02:00
xtensa mm: larger stack guard gap, between vmas 2017-07-11 00:00:39 +00:00
.gitignore
Kconfig FROMLIST: mm: mmap: Add new /proc tunable for mmap_base ASLR. 2016-05-18 14:36:00 +05:30