[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250421083116.1161805-2-suhui@nfschina.com>
Date: Mon, 21 Apr 2025 16:31:16 +0800
From: Su Hui <suhui@...china.com>
To: herbert@...dor.apana.org.au,
davem@...emloft.net,
christophe.jaillet@...adoo.fr
Cc: Su Hui <suhui@...china.com>,
linux-crypto@...r.kernel.org,
linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: [PATCH v2 1/2] crypto: using size_add() for kmalloc()
It's safer to use size_add() to replace open-coded aithmetic in allocator
arguments, because size_add() can prevent possible overflow problem.
Signed-off-by: Su Hui <suhui@...china.com>
---
include/crypto/aead.h | 2 +-
include/crypto/akcipher.h | 3 ++-
include/crypto/kpp.h | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/crypto/aead.h b/include/crypto/aead.h
index 0e8a41638678..8df3d112bf6a 100644
--- a/include/crypto/aead.h
+++ b/include/crypto/aead.h
@@ -433,7 +433,7 @@ static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm,
{
struct aead_request *req;
- req = kmalloc(sizeof(*req) + crypto_aead_reqsize(tfm), gfp);
+ req = kmalloc(size_add(sizeof(*req), crypto_aead_reqsize(tfm)), gfp);
if (likely(req))
aead_request_set_tfm(req, tfm);
diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h
index cdf7da74bf2f..6927664bc3d7 100644
--- a/include/crypto/akcipher.h
+++ b/include/crypto/akcipher.h
@@ -184,7 +184,8 @@ static inline struct akcipher_request *akcipher_request_alloc(
{
struct akcipher_request *req;
- req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp);
+ req = kmalloc(size_add(sizeof(*req),
+ crypto_akcipher_reqsize(tfm)), gfp);
if (likely(req))
akcipher_request_set_tfm(req, tfm);
diff --git a/include/crypto/kpp.h b/include/crypto/kpp.h
index 2d9c4de57b69..ad120bbc8b7c 100644
--- a/include/crypto/kpp.h
+++ b/include/crypto/kpp.h
@@ -182,7 +182,7 @@ static inline struct kpp_request *kpp_request_alloc(struct crypto_kpp *tfm,
{
struct kpp_request *req;
- req = kmalloc(sizeof(*req) + crypto_kpp_reqsize(tfm), gfp);
+ req = kmalloc(size_add(sizeof(*req), crypto_kpp_reqsize(tfm)), gfp);
if (likely(req))
kpp_request_set_tfm(req, tfm);
--
2.30.2
Powered by blists - more mailing lists