Skip to content

Commit 24fbf7b

Browse files
yeyunfeng-devherbertx
authored andcommitted
crypto: hisilicon - Fix double free in sec_free_hw_sgl()
There are two problems in sec_free_hw_sgl(): First, when sgl_current->next is valid, @hw_sgl will be freed in the first loop, but it free again after the loop. Second, sgl_current and sgl_current->next_sgl is not match when dma_pool_free() is invoked, the third parameter should be the dma address of sgl_current, but sgl_current->next_sgl is the dma address of next chain, so use sgl_current->next_sgl is wrong. Fix this by deleting the last dma_pool_free() in sec_free_hw_sgl(), modifying the condition for while loop, and matching the address for dma_pool_free(). Fixes: 915e4e8 ("crypto: hisilicon - SEC security accelerator driver") Signed-off-by: Yunfeng Ye <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 212ef6f commit 24fbf7b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/crypto/hisilicon/sec/sec_algs.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,18 @@ static void sec_free_hw_sgl(struct sec_hw_sgl *hw_sgl,
215215
dma_addr_t psec_sgl, struct sec_dev_info *info)
216216
{
217217
struct sec_hw_sgl *sgl_current, *sgl_next;
218+
dma_addr_t sgl_next_dma;
218219

219-
if (!hw_sgl)
220-
return;
221220
sgl_current = hw_sgl;
222-
while (sgl_current->next) {
221+
while (sgl_current) {
223222
sgl_next = sgl_current->next;
224-
dma_pool_free(info->hw_sgl_pool, sgl_current,
225-
sgl_current->next_sgl);
223+
sgl_next_dma = sgl_current->next_sgl;
224+
225+
dma_pool_free(info->hw_sgl_pool, sgl_current, psec_sgl);
226+
226227
sgl_current = sgl_next;
228+
psec_sgl = sgl_next_dma;
227229
}
228-
dma_pool_free(info->hw_sgl_pool, hw_sgl, psec_sgl);
229230
}
230231

231232
static int sec_alg_skcipher_setkey(struct crypto_skcipher *tfm,

0 commit comments

Comments
 (0)