b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 |
| 5 | input |
| 6 | |
| 7 | commit c9cc0517bba9f0213f1e55172feceb99e5512daf upstream. |
| 8 | |
| 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. |
| 17 | |
| 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> |
| 25 | --- |
| 26 | lib/crypto/chacha20poly1305.c | 3 +++ |
| 27 | 1 file changed, 3 insertions(+) |
| 28 | |
| 29 | --- a/lib/crypto/chacha20poly1305.c |
| 30 | +++ b/lib/crypto/chacha20poly1305.c |
| 31 | @@ -235,6 +235,9 @@ bool chacha20poly1305_crypt_sg_inplace(s |
| 32 | __le64 lens[2]; |
| 33 | } b __aligned(16); |
| 34 | |
| 35 | + if (WARN_ON(src_len > INT_MAX)) |
| 36 | + return false; |
| 37 | + |
| 38 | chacha_load_key(b.k, key); |
| 39 | |
| 40 | b.iv[0] = 0; |