159 lines
4.5 KiB
Diff
159 lines
4.5 KiB
Diff
From ffdacf318e16c0d666aa171d46c7bd75d128a32a Mon Sep 17 00:00:00 2001
|
|
From: Hao Fang <fanghao11@huawei.com>
|
|
Date: Sat, 25 Nov 2023 16:13:22 +0800
|
|
Subject: [PATCH 71/82] uadk_engine: cipher/digest: fixes for priv address
|
|
check
|
|
|
|
1.Add priv address check return by EVP_CIPHER_CTX_get_cipher_data().
|
|
2.Add priv address check return by EVP_MD_CTX_md_data().
|
|
|
|
Signed-off-by: Hao Fang <fanghao11@huawei.com>
|
|
---
|
|
src/uadk_cipher.c | 18 ++++++++++++++----
|
|
src/uadk_digest.c | 30 ++++++++++++++++++++++++++++++
|
|
2 files changed, 44 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c
|
|
index 12830b7..472c47c 100644
|
|
--- a/src/uadk_cipher.c
|
|
+++ b/src/uadk_cipher.c
|
|
@@ -185,7 +185,7 @@ static int uadk_e_cipher_sw_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
|
|
|
priv = (struct cipher_priv_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
|
if (unlikely(priv == NULL)) {
|
|
- fprintf(stderr, "uadk engine state is NULL.\n");
|
|
+ fprintf(stderr, "priv get from cipher ctx is NULL.\n");
|
|
return 0;
|
|
}
|
|
|
|
@@ -235,7 +235,7 @@ static int uadk_e_cipher_soft_work(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
priv = (struct cipher_priv_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
|
if (unlikely(priv == NULL)) {
|
|
- fprintf(stderr, "uadk engine state is NULL.\n");
|
|
+ fprintf(stderr, "priv get from cipher ctx is NULL.\n");
|
|
return 0;
|
|
}
|
|
|
|
@@ -277,7 +277,7 @@ static void uadk_e_cipher_sw_cleanup(EVP_CIPHER_CTX *ctx)
|
|
struct cipher_priv_ctx *priv =
|
|
(struct cipher_priv_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
|
|
|
- if (priv->sw_ctx_data) {
|
|
+ if (priv && priv->sw_ctx_data) {
|
|
OPENSSL_free(priv->sw_ctx_data);
|
|
priv->sw_ctx_data = NULL;
|
|
}
|
|
@@ -500,6 +500,11 @@ static int uadk_e_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
|
int nid, ret;
|
|
__u32 i;
|
|
|
|
+ if (unlikely(!priv)) {
|
|
+ fprintf(stderr, "priv get from cipher ctx is NULL.\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
if (unlikely(!key)) {
|
|
fprintf(stderr, "ctx init parameter key is NULL.\n");
|
|
return 0;
|
|
@@ -541,7 +546,7 @@ static int uadk_e_cipher_cleanup(EVP_CIPHER_CTX *ctx)
|
|
|
|
uadk_e_cipher_sw_cleanup(ctx);
|
|
|
|
- if (priv->sess) {
|
|
+ if (priv && priv->sess) {
|
|
wd_cipher_free_sess(priv->sess);
|
|
priv->sess = 0;
|
|
}
|
|
@@ -752,6 +757,11 @@ static int uadk_e_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
struct async_op op;
|
|
int ret;
|
|
|
|
+ if (unlikely(!priv)) {
|
|
+ fprintf(stderr, "priv get from cipher ctx is NULL.\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
priv->req.src = (unsigned char *)in;
|
|
priv->req.in_bytes = inlen;
|
|
priv->req.dst = out;
|
|
diff --git a/src/uadk_digest.c b/src/uadk_digest.c
|
|
index 0aa90f3..06851f1 100644
|
|
--- a/src/uadk_digest.c
|
|
+++ b/src/uadk_digest.c
|
|
@@ -535,6 +535,11 @@ static int uadk_e_digest_init(EVP_MD_CTX *ctx)
|
|
__u32 i;
|
|
int ret;
|
|
|
|
+ if (unlikely(!priv)) {
|
|
+ fprintf(stderr, "priv get from digest ctx is NULL.\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
priv->e_nid = EVP_MD_nid(EVP_MD_CTX_md(ctx));
|
|
|
|
digest_priv_ctx_reset(priv);
|
|
@@ -587,6 +592,11 @@ static void digest_update_out_length(EVP_MD_CTX *ctx)
|
|
struct digest_priv_ctx *priv =
|
|
(struct digest_priv_ctx *)EVP_MD_CTX_md_data(ctx);
|
|
|
|
+ if (unlikely(!priv)) {
|
|
+ fprintf(stderr, "priv get from digest ctx is NULL.\n");
|
|
+ return;
|
|
+ }
|
|
+
|
|
/* Sha224 and Sha384 need full length mac buffer as doing long hash */
|
|
if (priv->e_nid == NID_sha224)
|
|
priv->req.out_bytes = WD_DIGEST_SHA224_FULL_LEN;
|
|
@@ -614,6 +624,11 @@ static int digest_update_inner(EVP_MD_CTX *ctx, const void *data, size_t data_le
|
|
int copy_to_bufflen;
|
|
int ret;
|
|
|
|
+ if (unlikely(!priv)) {
|
|
+ fprintf(stderr, "priv get from digest ctx is NULL.\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
digest_update_out_length(ctx);
|
|
digest_set_msg_state(priv, false);
|
|
|
|
@@ -671,6 +686,11 @@ static int uadk_e_digest_update(EVP_MD_CTX *ctx, const void *data, size_t data_l
|
|
struct digest_priv_ctx *priv =
|
|
(struct digest_priv_ctx *)EVP_MD_CTX_md_data(ctx);
|
|
|
|
+ if (unlikely(!priv)) {
|
|
+ fprintf(stderr, "priv get from digest ctx is NULL.\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
if (unlikely(priv->switch_flag == UADK_DO_SOFT))
|
|
goto soft_update;
|
|
|
|
@@ -770,6 +790,11 @@ static int uadk_e_digest_final(EVP_MD_CTX *ctx, unsigned char *digest)
|
|
struct async_op *op;
|
|
int ret = 1;
|
|
|
|
+ if (unlikely(!priv)) {
|
|
+ fprintf(stderr, "priv get from digest ctx is NULL.\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
digest_set_msg_state(priv, true);
|
|
priv->req.in = priv->data;
|
|
priv->req.out = priv->out;
|
|
@@ -863,6 +888,11 @@ static int uadk_e_digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
|
|
if (!t)
|
|
return 1;
|
|
|
|
+ if (!f) {
|
|
+ fprintf(stderr, "priv get from digest ctx is NULL.\n");
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
if (t->sess) {
|
|
params.numa_id = -1;
|
|
t->setup.sched_param = ¶ms;
|
|
--
|
|
2.25.1
|
|
|