*** BLURB HERE ***
Weili Qian (3): uadk: modify address check uadk: check calloc return value drv/hisi_sec: modify minor errors in hisi_sec.c
Wenkai Lin (3): uadk/v1: fix for sec_dump_bd uadk/v1: fix for wd_recv_sync print uadk/v1: update the symbol table for libraries
drv/hisi_sec.c | 59 ++++++++++++++++++++++++++---------------- include/wd_util.h | 2 +- v1/drv/hisi_sec_udrv.c | 13 ++++------ v1/libwd.map | 1 + v1/wd.c | 11 +++++--- wd_aead.c | 19 +++++++------- wd_cipher.c | 14 +++++----- wd_digest.c | 18 ++++++++----- wd_util.c | 14 ++++++---- 9 files changed, 88 insertions(+), 63 deletions(-)
From: Wenkai Lin linwenkai6@hisilicon.com
Fix for uninit parameters and wrong data type.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/drv/hisi_sec_udrv.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index 36b93e6..ac6df5f 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -1738,7 +1738,7 @@ int qm_fill_digest_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i) info->req_cache[i] = msg;
#ifdef DEBUG_LOG - sec_dump_bd((unsigned int *)sqe, SQE_BYTES_NUMS); + sec_dump_bd((unsigned char *)temp, SQE_BYTES_NUMS); #endif
return WD_SUCCESS; @@ -1961,10 +1961,7 @@ int qm_parse_cipher_bd3_sqe(void *msg, const struct qm_queue_info *info, }
#ifdef DEBUG_LOG - if (sqe3->type == BD_TYPE3) - sec_dump_bd((unsigned char *)sqe3, SQE_BYTES_NUMS); - else - sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS); + sec_dump_bd((unsigned char *)msg, SQE_BYTES_NUMS); #endif
return 1; @@ -2515,7 +2512,7 @@ int qm_fill_aead_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i) info->req_cache[i] = msg;
#ifdef DEBUG_LOG - sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS); + sec_dump_bd((unsigned char *)temp, SQE_BYTES_NUMS); #endif
return ret; @@ -2602,7 +2599,7 @@ int qm_parse_aead_bd3_sqe(void *msg, const struct qm_queue_info *info, }
#ifdef DEBUG_LOG - sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS); + sec_dump_bd((unsigned char *)msg, SQE_BYTES_NUMS); #endif
return 1; @@ -2669,7 +2666,7 @@ int qm_parse_digest_bd3_sqe(void *msg, const struct qm_queue_info *info, }
#ifdef DEBUG_LOG - sec_dump_bd((unsigned int *)sqe, SQE_BYTES_NUMS); + sec_dump_bd((unsigned char *)msg, SQE_BYTES_NUMS); #endif
return 1;
From: Wenkai Lin linwenkai6@hisilicon.com
wd_recv_sync should print more information when return.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/v1/wd.c b/v1/wd.c index 4286bbe..02bc49c 100644 --- a/v1/wd.c +++ b/v1/wd.c @@ -688,8 +688,10 @@ int wd_wait(struct wd_queue *q, __u16 ms) fds[0].events = POLLIN;
ret = poll(fds, 1, ms); - if (unlikely(ret < 0)) + if (unlikely(ret < 0)) { + WD_ERR("failed to poll a queue!\n"); return -WD_ENODEV; + }
/* return 0 for no data, 1 for new message */ return ret; @@ -700,8 +702,11 @@ int wd_recv_sync(struct wd_queue *q, void **resp, __u16 ms) int ret;
ret = wd_wait(q, ms); - if (likely(ret > 0)) - return wd_recv(q, resp); + if (likely(ret > 0)) { + ret = wd_recv(q, resp); + if (unlikely(!ret)) + WD_ERR("failed to recv data after poll!\n"); + }
return ret; }
From: Wenkai Lin linwenkai6@hisilicon.com
hisi_qm_inject_op_register should be visible to the outside APP, fix it now.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/libwd.map | 1 + 1 file changed, 1 insertion(+)
diff --git a/v1/libwd.map b/v1/libwd.map index 4e6b639..d53201b 100644 --- a/v1/libwd.map +++ b/v1/libwd.map @@ -160,6 +160,7 @@ global: wd_get_sgl_datalen; wd_get_sge_datalen; wd_get_sgl_bufsize; + hisi_qm_inject_op_register;
local: *; };
From: Weili Qian qianweili@huawei.com
When the memory is in SGL format, both wd_check_src_dst and wd_check_datalist are called for address check. Actually, only wd_check_datalist needs to be called.
Signed-off-by: Weili Qian qianweili@huawei.com --- include/wd_util.h | 2 +- wd_aead.c | 19 +++++++++---------- wd_cipher.c | 14 +++++++------- wd_digest.c | 18 ++++++++++++------ wd_util.c | 4 ++-- 5 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h index f217f0f..1c4af0b 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -254,7 +254,7 @@ int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes); * * Return 0 if the datalist is not less than expected size. */ -int wd_check_datalist(struct wd_datalist *head, __u32 size); +int wd_check_datalist(struct wd_datalist *head, __u64 size);
/* diff --git a/wd_aead.c b/wd_aead.c index 9c3f1ab..65949f7 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -374,7 +374,7 @@ void wd_aead_free_sess(handle_t h_sess) static int wd_aead_param_check(struct wd_aead_sess *sess, struct wd_aead_req *req) { - __u32 len; + __u64 len; int ret;
if (unlikely(!sess || !req)) { @@ -410,18 +410,11 @@ static int wd_aead_param_check(struct wd_aead_sess *sess, return -WD_EINVAL; }
- ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); - if (unlikely(ret)) { - WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); - return -WD_EINVAL; - } - if (req->data_fmt == WD_SGL_BUF) { - len = req->in_bytes + req->assoc_bytes; + len = (__u64)req->in_bytes + req->assoc_bytes; ret = wd_check_datalist(req->list_src, len); if (unlikely(ret)) { - WD_ERR("failed to check the src datalist, size = %u\n", - len); + WD_ERR("failed to check the src datalist, size = %llu\n", len); return -WD_EINVAL; }
@@ -431,6 +424,12 @@ static int wd_aead_param_check(struct wd_aead_sess *sess, req->out_bytes); return -WD_EINVAL; } + } else { + ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); + if (unlikely(ret)) { + WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); + return -WD_EINVAL; + } }
return 0; diff --git a/wd_cipher.c b/wd_cipher.c index 4799213..646aa89 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -560,7 +560,7 @@ static int cipher_iv_len_check(struct wd_cipher_req *req,
if (!req->iv) { WD_ERR("invalid: cipher input iv is NULL!\n"); - ret = -WD_EINVAL; + return -WD_EINVAL; }
switch (sess->alg) { @@ -636,12 +636,6 @@ static int wd_cipher_check_params(handle_t h_sess, if (unlikely(ret)) return ret;
- ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); - if (unlikely(ret)) { - WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); - return -WD_EINVAL; - } - if (req->data_fmt == WD_SGL_BUF) { ret = wd_check_datalist(req->list_src, req->in_bytes); if (unlikely(ret)) { @@ -657,6 +651,12 @@ static int wd_cipher_check_params(handle_t h_sess, req->in_bytes); return -WD_EINVAL; } + } else { + ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); + if (unlikely(ret)) { + WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); + return -WD_EINVAL; + } }
return cipher_iv_len_check(req, sess); diff --git a/wd_digest.c b/wd_digest.c index f116aec..943fd8c 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -548,12 +548,6 @@ static int wd_digest_param_check(struct wd_digest_sess *sess, return -WD_EINVAL; }
- ret = wd_check_src_dst(req->in, req->in_bytes, req->out, req->out_bytes); - if (unlikely(ret)) { - WD_ERR("invalid: in/out addr is NULL when in/out size is non-zero!\n"); - return -WD_EINVAL; - } - if (req->data_fmt == WD_SGL_BUF) { ret = wd_check_datalist(req->list_in, req->in_bytes); if (unlikely(ret)) { @@ -561,6 +555,18 @@ static int wd_digest_param_check(struct wd_digest_sess *sess, req->in_bytes); return -WD_EINVAL; } + + ret = wd_check_src_dst(NULL, 0, req->out, req->out_bytes); + if (unlikely(ret)) { + WD_ERR("invalid: out addr is NULL when out size is non-zero!\n"); + return -WD_EINVAL; + } + } else { + ret = wd_check_src_dst(req->in, req->in_bytes, req->out, req->out_bytes); + if (unlikely(ret)) { + WD_ERR("invalid: in/out addr is NULL when in/out size is non-zero!\n"); + return -WD_EINVAL; + } }
return wd_aes_hmac_length_check(sess, req); diff --git a/wd_util.c b/wd_util.c index 76548c9..5350f84 100644 --- a/wd_util.c +++ b/wd_util.c @@ -475,10 +475,10 @@ int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes) return 0; }
-int wd_check_datalist(struct wd_datalist *head, __u32 size) +int wd_check_datalist(struct wd_datalist *head, __u64 size) { struct wd_datalist *tmp = head; - __u32 list_size = 0; + __u64 list_size = 0;
while (tmp) { if (tmp->data)
From: Weili Qian qianweili@huawei.com
Added the check of the return value of calloc.
Signed-off-by: Weili Qian qianweili@huawei.com --- wd_util.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/wd_util.c b/wd_util.c index 5350f84..8d362d7 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2632,10 +2632,15 @@ static int wd_alg_ce_ctx_init(struct wd_init_attrs *attrs) ctx_config->ctx_num = 1; ctx_config->ctxs = calloc(ctx_config->ctx_num, sizeof(struct wd_ctx)); if (!ctx_config->ctxs) { - return -WD_ENOMEM; WD_ERR("failed to alloc ctxs!\n"); + return -WD_ENOMEM; } + ctx_config->ctxs[0].ctx = (handle_t)calloc(1, sizeof(struct wd_ce_ctx)); + if (!ctx_config->ctxs[0].ctx) { + free(ctx_config->ctxs); + return -WD_ENOMEM; + }
return WD_SUCCESS; } @@ -2719,7 +2724,7 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) char alg_type[CRYPTO_MAX_ALG_NAME]; int driver_type = UADK_ALG_HW; char *alg = attrs->alg; - int ret = 0; + int ret = -WD_EINVAL;
if (!attrs->ctx_params) return -WD_EINVAL; @@ -2801,7 +2806,6 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) numa_max_node() + 1, alg_poll_func); if (!alg_sched) { WD_ERR("fail to instance scheduler\n"); - ret = -WD_EINVAL; goto out_ctx_config; } attrs->sched = alg_sched;
From: Weili Qian qianweili@huawei.com
1. In AEAD stream mode, iv is update used recv_msg. However, the iv pointer in recv_msg is a random value in the asynchronous mode, which may cause address exceptions. Therefore, temp_msg is used. 2. The AEAD stream mode does not support the SGL format. The SGL memory soft calculation may fail. 3. The data type is converted to __u64 during addition calculation to avoid calculation result overflow.
Signed-off-by: Weili Qian qianweili@huawei.com --- drv/hisi_sec.c | 59 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 23 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index d9bb7e4..0a1bcc1 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -2255,9 +2255,9 @@ static int aead_len_check(struct wd_aead_msg *msg, enum sec_bd_type type) } }
- if (unlikely(msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) { - WD_ERR("aead input data length is too long, size = %u\n", - msg->in_bytes + msg->assoc_bytes); + if (unlikely((__u64)msg->in_bytes + msg->assoc_bytes > MAX_INPUT_DATA_LEN)) { + WD_ERR("aead input data length is too long, size = %llu\n", + (__u64)msg->in_bytes + msg->assoc_bytes); return -WD_EINVAL; }
@@ -2516,6 +2516,11 @@ int aead_msg_state_check(struct wd_aead_msg *msg) } }
+ if (unlikely(msg->msg_state != AEAD_MSG_BLOCK && msg->data_fmt == WD_SGL_BUF)) { + WD_ERR("invalid: sgl mode not supports stream mode!\n"); + return -WD_EINVAL; + } + return 0; }
@@ -2555,10 +2560,12 @@ static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_ fill_aead_bd2_addr(msg, &sqe);
ret = fill_stream_bd2(msg, &sqe); - if (ret == WD_SOFT_COMPUTING) - return 0; - else if (unlikely(ret)) - return ret; + if (ret == WD_SOFT_COMPUTING) { + ret = 0; + goto put_sgl; + } else if (unlikely(ret)) { + goto put_sgl; + }
hisi_set_msg_id(h_qp, &msg->tag); sqe.type2.tag = (__u16)msg->tag; @@ -2568,14 +2575,16 @@ static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_ if (ret != -WD_EBUSY) WD_ERR("aead send sqe is err(%d)!\n", ret);
- if (msg->data_fmt == WD_SGL_BUF) - hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, - msg->out); - - return ret; + goto put_sgl; }
return 0; + +put_sgl: + if (msg->data_fmt == WD_SGL_BUF) + hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out); + + return ret; }
static void update_stream_counter(struct wd_aead_msg *recv_msg) @@ -2629,7 +2638,7 @@ static void parse_aead_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe, temp_msg = recv_msg; }
- update_stream_counter(recv_msg); + update_stream_counter(temp_msg);
if (unlikely(recv_msg->result != WD_SUCCESS)) dump_sec_msg(temp_msg, "aead"); @@ -2946,10 +2955,12 @@ static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *
fill_aead_bd3_addr(msg, &sqe); ret = fill_stream_bd3(h_qp, msg, &sqe); - if (ret == WD_SOFT_COMPUTING) - return 0; - else if (unlikely(ret)) - return ret; + if (ret == WD_SOFT_COMPUTING) { + ret = 0; + goto put_sgl; + } else if (unlikely(ret)) { + goto put_sgl; + }
hisi_set_msg_id(h_qp, &msg->tag); sqe.tag = msg->tag; @@ -2958,14 +2969,16 @@ static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void * if (ret != -WD_EBUSY) WD_ERR("aead send sqe is err(%d)!\n", ret);
- if (msg->data_fmt == WD_SGL_BUF) - hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, - msg->out); - - return ret; + goto put_sgl; }
return 0; + +put_sgl: + if (msg->data_fmt == WD_SGL_BUF) + hisi_sec_put_sgl(h_qp, msg->alg_type, msg->in, msg->out); + + return ret; }
static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, @@ -3005,7 +3018,7 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, temp_msg = recv_msg; }
- update_stream_counter(recv_msg); + update_stream_counter(temp_msg);
if (unlikely(recv_msg->result != WD_SUCCESS)) dump_sec_msg(temp_msg, "aead");