integer operation may be truncated before being combined with a larger pointer type.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- lib/crypto/aes.c | 8 ++++++-- v1/wd_bmm.c | 2 +- v1/wd_rsa.c | 6 +++--- v1/wd_sgl.c | 21 +++++++++++---------- wd_mempool.c | 8 +++++--- wd_rsa.c | 6 +++--- 6 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/lib/crypto/aes.c b/lib/crypto/aes.c index 2145d24..b1425bc 100644 --- a/lib/crypto/aes.c +++ b/lib/crypto/aes.c @@ -2,6 +2,7 @@ /* Copyright 2023 Huawei Technologies Co.,Ltd. All rights reserved. */
#include <string.h> +#include <stdint.h> #include "crypto/aes.h"
#define WORD(n) (0x##n##n##n##n) @@ -284,6 +285,7 @@ static void cipher(const unsigned char *in, unsigned char *out, { #define STATE_BYTE 16 __u64 state[STATE_CNT]; + __u64 *s; __u8 i;
memcpy(state, in, STATE_BYTE); @@ -295,13 +297,15 @@ static void cipher(const unsigned char *in, unsigned char *out, sublong(&state[1]); shift_rows(state); mix_columns(state); - add_round_key(state, w + i * STATE_CNT); + s = (void *)((uintptr_t)w + i * STATE_CNT * sizeof(__u64)); + add_round_key(state, s); }
sublong(&state[0]); sublong(&state[1]); shift_rows(state); - add_round_key(state, w + nr * STATE_CNT); + s = (void *)((uintptr_t)w + nr * STATE_CNT * sizeof(__u64)); + add_round_key(state, s);
memcpy(out, state, STATE_BYTE); } diff --git a/v1/wd_bmm.c b/v1/wd_bmm.c index 8f41997..5fd15e5 100644 --- a/v1/wd_bmm.c +++ b/v1/wd_bmm.c @@ -193,7 +193,7 @@ static int usr_pool_init(struct wd_blkpool *p) p->act_start = (void *)ALIGN((uintptr_t)p->usr_mem_start, sp->align_size); for (i = 0; i < sp->block_num; i++) { - hd = p->act_start + (p->act_hd_sz + p->act_blk_sz) * i; + hd = (void *)((uintptr_t)p->act_start + (p->act_hd_sz + p->act_blk_sz) * i); hd->blk = (void *)((uintptr_t)hd + p->act_hd_sz); hd->blk_dma = sp->br.iova_map(sp->br.usr, hd->blk, blk_size); if (!hd->blk_dma) { diff --git a/v1/wd_rsa.c b/v1/wd_rsa.c index 250f479..c5c109d 100644 --- a/v1/wd_rsa.c +++ b/v1/wd_rsa.c @@ -215,7 +215,7 @@ struct wcrypto_rsa_kg_in *wcrypto_new_kg_in(void *ctx, struct wd_dtb *e, kg_in->qbytes = q->dsize; kg_in->e = (void *)kg_in->data; kg_in->p = (void *)kg_in->e + c->key_size; - kg_in->q = (void *)kg_in->p + CRT_PARAM_SZ(c->key_size); + kg_in->q = (void *)((uintptr_t)kg_in->p + CRT_PARAM_SZ(c->key_size));
memcpy(kg_in->e, e->data, e->dsize); memcpy(kg_in->p, p->data, p->dsize); @@ -310,8 +310,8 @@ struct wcrypto_rsa_kg_out *wcrypto_new_kg_out(void *ctx) kg_out->size = (__u32)kg_out_size; if (c->setup.is_crt) { kg_out->qinv = (void *)kg_out->n + kz; - kg_out->dq = kg_out->qinv + CRT_PARAM_SZ(kz); - kg_out->dp = kg_out->dq + CRT_PARAM_SZ(kz); + kg_out->dq = (void *)((uintptr_t)kg_out->qinv + CRT_PARAM_SZ(kz)); + kg_out->dp = (void *)((uintptr_t)kg_out->dq + CRT_PARAM_SZ(kz)); }
return kg_out; diff --git a/v1/wd_sgl.c b/v1/wd_sgl.c index dffbf12..ceb7f4c 100644 --- a/v1/wd_sgl.c +++ b/v1/wd_sgl.c @@ -601,22 +601,22 @@ static void sgl_cp_to_pbuf(struct wd_sgl *src_sgl, int start_sg, int strtad, return;
size -= sz - strtad; - pbuf += sz - strtad; + pbuf = (void *)((uintptr_t)pbuf + sz - strtad); for (i = strtsg + 1; i <= sgl->buf_num - 1 && size > sz; i++) { - memcpy(pbuf + (i - strtsg - 1) * sz, sgl->sge[i].buf, sz); + memcpy((void *)((uintptr_t)pbuf + (i - strtsg - 1) * sz), sgl->sge[i].buf, sz); size -= sz; }
if (i <= sgl->buf_num - 1) { - memcpy(pbuf + (i - strtsg - 1) * sz, sgl->sge[i].buf, size); + memcpy((void *)((uintptr_t)pbuf + (i - strtsg - 1) * sz), sgl->sge[i].buf, size); } else { sgl = next; for (i = 0; i < sgl->buf_num - 1 && size > sz; i++) { - memcpy(pbuf + (i + sgl->buf_num - strtsg - 1) * sz, + memcpy((void *)((uintptr_t)pbuf + (i + sgl->buf_num - strtsg - 1) * sz), sgl->sge[i].buf, sz); size -= sz; } - memcpy(pbuf + (i + sgl->buf_num - strtsg - 1) * sz, + memcpy((void *)((uintptr_t)pbuf + (i + sgl->buf_num - strtsg - 1) * sz), sgl->sge[i].buf, size); } } @@ -687,25 +687,26 @@ static void sgl_cp_from_pbuf(struct wd_sgl *dst_sgl, int start_sg, int strtad, return;
size -= sz - strtad; - pbuf += sz - strtad; + pbuf = (void *)((uintptr_t)pbuf + sz - strtad); for (i = strtsg + 1; i <= sgl->buf_num - 1 && size > sz; i++) { - memcpy(sgl->sge[i].buf, pbuf + (i - strtsg - 1) * sz, sz); + memcpy(sgl->sge[i].buf, (void *)((uintptr_t)pbuf + (i - strtsg - 1) * sz), sz); sgl->sge[i].data_len = sz; size -= sz; }
if (i <= sgl->buf_num - 1) { - memcpy(sgl->sge[i].buf, pbuf + (i - strtsg - 1) * sz, size); + memcpy(sgl->sge[i].buf, (void *)((uintptr_t)pbuf + (i - strtsg - 1) * sz), size); } else { sgl = next; for (i = 0; i < sgl->buf_num - 1 && size > sz; i++) { memcpy(sgl->sge[i].buf, - pbuf + (i + sgl->buf_num - strtsg - 1) * sz, sz); + (void *)((uintptr_t)pbuf + (i + sgl->buf_num - strtsg - 1) * sz), + sz); sgl->sge[i].data_len = sz; size -= sz; } memcpy(sgl->sge[i].buf, - pbuf + (i + sgl->buf_num - strtsg - 1) * sz, size); + (void *)((uintptr_t)pbuf + (i + sgl->buf_num - strtsg - 1) * sz), size); } sgl->sge[i].data_len = size; } diff --git a/wd_mempool.c b/wd_mempool.c index b27d28c..db88fb0 100644 --- a/wd_mempool.c +++ b/wd_mempool.c @@ -273,8 +273,9 @@ static void set_bit(struct bitmap *bm, unsigned int pos) { unsigned long *map = bm->map; unsigned long mask = BIT_MASK(pos); - unsigned long *p = map + BIT_WORD(pos); + unsigned long *p;
+ p = (void *)((uintptr_t)map + BIT_WORD(pos) * sizeof(unsigned long)); *p |= mask; }
@@ -282,14 +283,15 @@ static void clear_bit(struct bitmap *bm, unsigned int pos) { unsigned long *map = bm->map; unsigned long mask = BIT_MASK(pos); - unsigned long *p = map + BIT_WORD(pos); + unsigned long *p;
+ p = (void *)((uintptr_t)map + BIT_WORD(pos) * sizeof(unsigned long)); *p &= ~mask; }
static int test_bit(struct bitmap *bm, unsigned int nr) { - unsigned long *p = bm->map + BIT_WORD(nr); + unsigned long *p = (void *)((uintptr_t)bm->map + BIT_WORD(nr) * sizeof(unsigned long)); unsigned long mask = BIT_MASK(nr);
return !(*p & mask); diff --git a/wd_rsa.c b/wd_rsa.c index 00ac772..ac2106e 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -620,7 +620,7 @@ struct wd_rsa_kg_in *wd_rsa_new_kg_in(handle_t sess, struct wd_dtb *e, kg_in->qbytes = q->dsize; kg_in->e = (void *)kg_in->data; kg_in->p = (void *)kg_in->e + c->key_size; - kg_in->q = (void *)kg_in->p + CRT_PARAM_SZ(c->key_size); + kg_in->q = (void *)((uintptr_t)kg_in->p + CRT_PARAM_SZ(c->key_size));
memcpy(kg_in->e, e->data, e->dsize); memcpy(kg_in->p, p->data, p->dsize); @@ -699,8 +699,8 @@ struct wd_rsa_kg_out *wd_rsa_new_kg_out(handle_t sess) kg_out->size = kg_out_size; if (c->setup.is_crt) { kg_out->qinv = (void *)kg_out->n + kz; - kg_out->dq = kg_out->qinv + CRT_PARAM_SZ(kz); - kg_out->dp = kg_out->dq + CRT_PARAM_SZ(kz); + kg_out->dq = (void *)((uintptr_t)kg_out->qinv + CRT_PARAM_SZ(kz)); + kg_out->dp = (void *)((uintptr_t)kg_out->dq + CRT_PARAM_SZ(kz)); }
return kg_out;