Skip to content

Commit 8700ce0

Browse files
ISCAS-Vulabherbertx
authored andcommitted
crypto: ccree - Correctly handle return of sg_nents_for_len
Fix error handling in cc_map_hash_request_update where sg_nents_for_len return value was assigned to u32, converting negative errors to large positive values before passing to sg_copy_to_buffer. Check sg_nents_for_len return value and propagate errors before assigning to areq_ctx->in_nents. Fixes: b7ec853 ("crypto: ccree - use std api when possible") Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent e9eb520 commit 8700ce0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

drivers/crypto/ccree/cc_buffer_mgr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ int cc_map_hash_request_update(struct cc_drvdata *drvdata, void *ctx,
12351235
int rc = 0;
12361236
u32 dummy = 0;
12371237
u32 mapped_nents = 0;
1238+
int sg_nents;
12381239

12391240
dev_dbg(dev, " update params : curr_buff=%p curr_buff_cnt=0x%X nbytes=0x%X src=%p curr_index=%u\n",
12401241
curr_buff, *curr_buff_cnt, nbytes, src, areq_ctx->buff_index);
@@ -1248,7 +1249,10 @@ int cc_map_hash_request_update(struct cc_drvdata *drvdata, void *ctx,
12481249
if (total_in_len < block_size) {
12491250
dev_dbg(dev, " less than one block: curr_buff=%p *curr_buff_cnt=0x%X copy_to=%p\n",
12501251
curr_buff, *curr_buff_cnt, &curr_buff[*curr_buff_cnt]);
1251-
areq_ctx->in_nents = sg_nents_for_len(src, nbytes);
1252+
sg_nents = sg_nents_for_len(src, nbytes);
1253+
if (sg_nents < 0)
1254+
return sg_nents;
1255+
areq_ctx->in_nents = sg_nents;
12521256
sg_copy_to_buffer(src, areq_ctx->in_nents,
12531257
&curr_buff[*curr_buff_cnt], nbytes);
12541258
*curr_buff_cnt += nbytes;

0 commit comments

Comments
 (0)