When check whether a 'struct wd_dtb' type variable is all zero, the length of the data should be the value of 'bsize'. Directly using 'dsize' may truncate the data in some cases and cause erroneous judgement.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- drv/hisi_hpre.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index aec2f57..9da2bd7 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -1056,11 +1056,16 @@ static void ecc_get_io_len(__u32 atype, __u32 hsz, size_t *ilen, } }
-static bool is_all_zero(struct wd_dtb *e, struct wd_ecc_msg *msg) +static bool is_all_zero(struct wd_dtb *e) { int i;
- for (i = 0; i < e->dsize && i < msg->key_bytes; i++) { + if (!e || !e->data) { + WD_ERR("invalid: e or e->data is NULL\n"); + return true; + } + + for (i = 0; i < e->bsize; i++) { if (e->data[i]) return false; } @@ -1096,12 +1101,12 @@ static int ecc_prepare_sign_in(struct wd_ecc_msg *msg, return -WD_EINVAL; } hw_msg->sm2_ksel = 1; - } else if (is_all_zero(k, msg)) { + } else if (is_all_zero(k)) { WD_ERR("invalid: ecc sign in k all zero!\n"); return -WD_EINVAL; }
- if (is_all_zero(e, msg)) { + if (is_all_zero(e)) { WD_ERR("invalid: ecc sign in e all zero!\n"); return -WD_EINVAL; } @@ -1143,7 +1148,7 @@ static int ecc_prepare_verf_in(struct wd_ecc_msg *msg, s = &vin->s; r = &vin->r;
- if (is_all_zero(e, msg)) { + if (is_all_zero(e)) { WD_ERR("invalid: ecc verf in e all zero!\n"); return -WD_EINVAL; } @@ -1284,7 +1289,7 @@ static int u_is_in_p(struct wd_ecc_msg *msg) return -WD_EINVAL; }
- if (is_all_zero(&pbk->x, msg)) { + if (is_all_zero(&pbk->x)) { WD_ERR("invalid: ux is zero!\n"); return -WD_EINVAL; }