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)