crypto: qat - avoid double free of authentication descriptor
Subsystems (2)
PATCH 1/1 crypto: qat - avoid double free of authentication descriptor
From: Svyatoslav Pankratov <[email protected]>
qat_uclo_wr_suof_img() reuses a single struct icp_qat_fw_auth_desc pointer across all signed images. At the end of every loop iteration qat_uclo_ummap_auth_fw() releases the DMA buffer backing the descriptor, but leaves the caller's pointer untouched.
If qat_uclo_map_auth_fw() then fails for a subsequent image before it assigns a new descriptor, for example when qat_uclo_simg_alloc() cannot allocate the DMA region, the error path jumps to wr_err and calls qat_uclo_ummap_auth_fw() again on the stale pointer. This reads chunk_bus_addr and chunk_size from already freed coherent memory and passes them to dma_free_coherent(), resulting in a use-after-free and a double free.
Clear the descriptor pointer in qat_uclo_ummap_auth_fw() after the buffer is released so that it is unmapped at most once.
--- drivers/crypto/intel/qat/qat_common/qat_uclo.c | 1 + 1 file changed, 1 insertion(+)
drivers/crypto/intel/qat/qat_common/qat_uclo.c +1 -0
@@ -1398,6 +1398,7 @@ static void qat_uclo_ummap_auth_fw(struct icp_qat_fw_loader_handle *handle, dram_desc.dram_size = ((struct icp_qat_auth_chunk *) (*desc))->chunk_size;qat_uclo_simg_free (handle, &dram_desc); + *desc =NULL ; } }
Signature · 1 line
2.50.1
Herbert Xu
maintainerQuoted 18 lines · Ahsan Atta
From: Svyatoslav Pankratov <[email protected]>
qat_uclo_wr_suof_img()reuses a single structicp_qat_fw_auth_descpointer across all signed images. At the end of every loop iterationqat_uclo_ummap_auth_fw()releases the DMA buffer backing the descriptor, but leaves the caller's pointer untouched.If
qat_uclo_map_auth_fw()then fails for a subsequent image before it assigns a new descriptor, for example whenqat_uclo_simg_alloc()cannot allocate the DMA region, the error path jumps towr_errand callsqat_uclo_ummap_auth_fw()again on the stale pointer. This readschunk_bus_addrandchunk_sizefrom already freed coherent memory and passes them todma_free_coherent(), resulting in a use-after-free and a double free.Clear the descriptor pointer in
qat_uclo_ummap_auth_fw()after the buffer is released so that it is unmapped at most once.
Quoted 7 lines
Fixes b0272276d903 ("crypto: qat - add support for new devices to FW loader")Signed-off-by Svyatoslav Pankratov <[email protected]>Signed-off-by Ahsan Atta <[email protected]>Reviewed-by Giovanni Cabiddu <[email protected]>--- drivers/crypto/intel/qat/qat_common/qat_uclo.c | 1 + 1 file changed, 1 insertion(+)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt