diff options
author | Gustavo A. R. Silva <gustavoars@kernel.org> | 2023-09-15 13:12:38 -0600 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-11-20 11:58:57 +0100 |
commit | 4c7f066b7b7c127626d428ad18289f912ac42f93 (patch) | |
tree | 88308f557dea69b16e6efdb9de193ffc6bb7aa1c /net/tls | |
parent | be25fc451ef4ee2151c9d11fd48785396ba9ec16 (diff) | |
download | linux-stable-4c7f066b7b7c127626d428ad18289f912ac42f93.tar.gz linux-stable-4c7f066b7b7c127626d428ad18289f912ac42f93.tar.bz2 linux-stable-4c7f066b7b7c127626d428ad18289f912ac42f93.zip |
tls: Use size_add() in call to struct_size()
[ Upstream commit a2713257ee2be22827d7bc248302d408c91bfb95 ]
If, for any reason, the open-coded arithmetic causes a wraparound,
the protection that `struct_size()` adds against potential integer
overflows is defeated. Fix this by hardening call to `struct_size()`
with `size_add()`.
Fixes: b89fec54fd61 ("tls: rx: wrap decrypt params in a struct")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net/tls')
-rw-r--r-- | net/tls/tls_sw.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index e9d1e83a859d..9634dfd636fd 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -1491,7 +1491,7 @@ static int tls_decrypt_sg(struct sock *sk, struct iov_iter *out_iov, */ aead_size = sizeof(*aead_req) + crypto_aead_reqsize(ctx->aead_recv); aead_size = ALIGN(aead_size, __alignof__(*dctx)); - mem = kmalloc(aead_size + struct_size(dctx, sg, n_sgin + n_sgout), + mem = kmalloc(aead_size + struct_size(dctx, sg, size_add(n_sgin, n_sgout)), sk->sk_allocation); if (!mem) { err = -ENOMEM; |