1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 Date: Thu, 6 Feb 2020 12:42:01 +0100
4 Subject: [PATCH] crypto: chacha20poly1305 - prevent integer overflow on large
7 commit c9cc0517bba9f0213f1e55172feceb99e5512daf upstream.
9 This code assigns src_len (size_t) to sl (int), which causes problems
10 when src_len is very large. Probably nobody in the kernel should be
11 passing this much data to chacha20poly1305 all in one go anyway, so I
12 don't think we need to change the algorithm or introduce larger types
13 or anything. But we should at least error out early in this case and
14 print a warning so that we get reports if this does happen and can look
15 into why anybody is possibly passing it that much data or if they're
16 accidently passing -1 or similar.
18 Fixes: d95312a3ccc0 ("crypto: lib/chacha20poly1305 - reimplement crypt_from_sg() routine")
19 Cc: Ard Biesheuvel <ardb@kernel.org>
20 Cc: stable@vger.kernel.org # 5.5+
21 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
22 Acked-by: Ard Biesheuvel <ardb@kernel.org>
23 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
24 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
26 lib/crypto/chacha20poly1305.c | 3 +++
27 1 file changed, 3 insertions(+)
29 --- a/lib/crypto/chacha20poly1305.c
30 +++ b/lib/crypto/chacha20poly1305.c
31 @@ -235,6 +235,9 @@ bool chacha20poly1305_crypt_sg_inplace(s
35 + if (WARN_ON(src_len > INT_MAX))
38 chacha_load_key(b.k, key);