crypto: fix heap use after free bug
PATCH 1/1 crypto: fix heap use after free bug
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 QAT close function while being released.
---
The same issue is found in crypto/octeontx,
which may need to be addressed by maintainers.
Cc: Anoob Joseph <[email protected]>
--- lib/cryptodev/rte_cryptodev_pmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/cryptodev/rte_cryptodev_pmd.c +2 -1
@@ -140,6 +140,7 @@ int rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev) {int retval; +void *tmp_dev_private = cryptodev->data->dev_private;CDEV_LOG_INFO ("Closing crypto device %s" , cryptodev->device->name);
@@ -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 (tmp_dev_private); cryptodev->device =NULL ;
Signature · 1 line
2.25.1
Quoted 30 lines
The PMD destroy function was calling the release function, which frees
cryptodev->data, and then tries to freecryptodev->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 freedev_private.
The free cannot be moved to before the release function is called, asdev_privateis used in the QAT close function while being released.Fixes 9e6edea41805 ("cryptodev: add APIs to assist PMD initialisation")Reported-by ZhihongX Peng <[email protected]>Signed-off-by Ciara Power <[email protected]>---
The same issue is found incrypto/octeontx,
which may need to be addressed by maintainers.
Cc: Anoob Joseph <[email protected]>--- lib/cryptodev/rte_cryptodev_pmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/cryptodev/rte_cryptodev_pmd.c +0
-0
lib/cryptodev/rte_cryptodev_pmd.c int · line 143
Quoted 4 lines
lib/cryptodev/rte_cryptodev_pmd.c +1
-0@@ -140,6 +140,7 @@ int rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev) {int retval; +void *tmp_dev_private = cryptodev->data->dev_private;
Can we rename this pointer as dev_private?
Quoted 16 lines
lib/cryptodev/rte_cryptodev_pmd.c +1
-1CDEV_LOG_INFO ("Closing crypto device %s" , cryptodev->device- >name);@@ -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 (tmp_dev_private);
cryptodev->device= NULL;
--
2.25.1
Fixed title
Cryptodev: fix heap use after free
Quoted 8 lines
Quoted 8 lines
The PMD destroy function was calling the release function, which frees
cryptodev->data, and then tries to freecryptodev->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 freedev_private.
The free cannot be moved to before the release function is called, asdev_privateis used in the QAT close function while being released.
I believe all PMDs use dev_private for close.
Hence replaces QAT with PMD
Quoted 16 lines
Quoted 16 lines
Fixes 9e6edea41805 ("cryptodev: add APIs to assist PMD initialisation")Reported-by ZhihongX Peng <[email protected]>Signed-off-by Ciara Power <[email protected]>---
The same issue is found incrypto/octeontx,
which may need to be addressed by maintainers.
Cc: Anoob Joseph <[email protected]>--- lib/cryptodev/rte_cryptodev_pmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 12 lines
lib/cryptodev/rte_cryptodev_pmd.c int · line 143
Quoted 10 lines
lib/cryptodev/rte_cryptodev_pmd.c +1
-0@@ -140,6 +140,7 @@ int rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev) {int retval; +void *tmp_dev_private = cryptodev->data->dev_private;Can we rename this pointer as
dev_private?
Renamed this while merging, as we have RC3 deadline today.
Quoted 17 lines
Quoted 17 lines
lib/cryptodev/rte_cryptodev_pmd.c +1
-1CDEV_LOG_INFO ("Closing crypto device %s" , cryptodev->device- >name);@@ -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 (tmp_dev_private);
cryptodev->device= NULL;
--
2.25.1
Quoted 51 lines
Fixed title
Cryptodev: fix heap use after freeQuoted 8 lines
Quoted 8 lines
The PMD destroy function was calling the release function, which frees
cryptodev->data, and then tries to freecryptodev->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 freedev_private.
The free cannot be moved to before the release function is called, asdev_privateis used in the QAT close function while being released.I believe all PMDs use
dev_privatefor close.
Hence replaces QAT with PMDQuoted 16 lines
Quoted 16 lines
Fixes 9e6edea41805 ("cryptodev: add APIs to assist PMD initialisation")Reported-by ZhihongX Peng <[email protected]>Signed-off-by Ciara Power <[email protected]>---
The same issue is found incrypto/octeontx,
which may need to be addressed by maintainers.
Cc: Anoob Joseph <[email protected]>--- lib/cryptodev/rte_cryptodev_pmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 12 lines
lib/cryptodev/rte_cryptodev_pmd.c int · line 143
Quoted 10 lines
lib/cryptodev/rte_cryptodev_pmd.c +1
-0@@ -140,6 +140,7 @@ int rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev) {int retval; +void *tmp_dev_private = cryptodev->data->dev_private;Can we rename this pointer as
dev_private?Renamed this while merging, as we have RC3 deadline today.
Quoted 9 lines
Quoted 9 lines
lib/cryptodev/rte_cryptodev_pmd.c +0
-0CDEV_LOG_INFO ("Closing crypto device %s" , cryptodev->device- >name);@@ -149,7 +150,7 @@ rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev)return retval;
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
lib/cryptodev/rte_cryptodev_pmd.c +1
-1if (rte_eal_process_type () ==RTE_PROC_PRIMARY ) -rte_free (cryptodev->data->dev_private); +rte_free (tmp_dev_private);
cryptodev->device= NULL;
Applied to dpdk-next-crypto