Skip to content

Commit

Permalink
cryptodev: fix freeing after device release
Browse files Browse the repository at this point in the history
[ upstream commit eeaeca8 ]

The PMD destroy function was calling the release function, which frees
cryptodev->data, and then tries to free cryptodev->data->dev_private,
which causes the heap use after free issue.

A temporary pointer is set before the free of cryptodev->data,
which can then be used afterwards to free dev_private.
The free cannot be moved to before the release function is called,
as dev_private is used in the PMD close function while being released.

Fixes: 9e6edea ("cryptodev: add APIs to assist PMD initialisation")

Reported-by: Zhihong Peng <zhihongx.peng@intel.com>
Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Akhil Goyal <gakhil@marvell.com>
  • Loading branch information
ciarapow authored and bluca committed Aug 3, 2021
1 parent 946df43 commit 1515698
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/librte_cryptodev/rte_cryptodev_pmd.c
Expand Up @@ -140,6 +140,7 @@ int
rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev)
{
int retval;
void *dev_priv = cryptodev->data->dev_private;

CDEV_LOG_INFO("Closing crypto device %s", cryptodev->device->name);

Expand All @@ -149,7 +150,7 @@ rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev)
return retval;

if (rte_eal_process_type() == RTE_PROC_PRIMARY)
rte_free(cryptodev->data->dev_private);
rte_free(dev_priv);


cryptodev->device = NULL;
Expand Down

0 comments on commit 1515698

Please sign in to comment.