[v2] crypto/octeontx: fix coverity issues

Message ID 1542046420-31462-1-git-send-email-anoob.joseph@caviumnetworks.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series [v2] crypto/octeontx: fix coverity issues |

Checks

Context Check Description
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Anoob Joseph Nov. 12, 2018, 6:14 p.m. UTC
  Coverity Issue: 323492

If the length of string pointed by 'name' is equal to or greater than
the sizeof cptvf->dev_name string, the resultant string will not be
null terminated. Using strlcpy would make sure the string would always
be null terminated.

Fixes: 0dc1cffa4d33 ("crypto/octeontx: add hardware init routine")

Coverity Issue: 323489

Fix null pointer dereferencing

Fixes: bfe2ae495ee2 ("crypto/octeontx: add PMD skeleton")

Coverity Issue: 323486

The function otx_cpt_get_resource() would be setting the pointer
'instance'. In case of error, 'instance' would be set to NULL, and
returns rte_errno. If rte_errno when 'instance' is set to NULL, it can
lead to NULL pointer dereferencing.

Fixes: 0961348fdf52 ("crypto/octeontx: add queue pair functions")

Signed-off-by: Ankur Dwivedi <ankur.dwivedi@caviumnetworks.com>
Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
---
v2:
* Squashed three commits to one

 drivers/crypto/octeontx/otx_cryptodev.c           | 2 +-
 drivers/crypto/octeontx/otx_cryptodev_hw_access.c | 5 ++++-
 drivers/crypto/octeontx/otx_cryptodev_ops.c       | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)
  

Comments

Akhil Goyal Nov. 13, 2018, 10:12 a.m. UTC | #1
On 11/12/2018 11:44 PM, Anoob Joseph wrote:
> Coverity Issue: 323492
>
> If the length of string pointed by 'name' is equal to or greater than
> the sizeof cptvf->dev_name string, the resultant string will not be
> null terminated. Using strlcpy would make sure the string would always
> be null terminated.
>
> Fixes: 0dc1cffa4d33 ("crypto/octeontx: add hardware init routine")
>
> Coverity Issue: 323489
>
> Fix null pointer dereferencing
>
> Fixes: bfe2ae495ee2 ("crypto/octeontx: add PMD skeleton")
>
> Coverity Issue: 323486
>
> The function otx_cpt_get_resource() would be setting the pointer
> 'instance'. In case of error, 'instance' would be set to NULL, and
> returns rte_errno. If rte_errno when 'instance' is set to NULL, it can
> lead to NULL pointer dereferencing.
>
> Fixes: 0961348fdf52 ("crypto/octeontx: add queue pair functions")
>
> Signed-off-by: Ankur Dwivedi <ankur.dwivedi@caviumnetworks.com>
> Signed-off-by: Anoob Joseph <anoob.joseph@caviumnetworks.com>
> ---
> v2:
> * Squashed three commits to one
>
Applied to dpdk-next-crypto

Thanks
  

Patch

diff --git a/drivers/crypto/octeontx/otx_cryptodev.c b/drivers/crypto/octeontx/otx_cryptodev.c
index 269f045..b201e0a 100644
--- a/drivers/crypto/octeontx/otx_cryptodev.c
+++ b/drivers/crypto/octeontx/otx_cryptodev.c
@@ -100,8 +100,8 @@  otx_cpt_pci_remove(struct rte_pci_device *pci_dev)
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		rte_free(cryptodev->data->dev_private);
 
-	cryptodev->device = NULL;
 	cryptodev->device->driver = NULL;
+	cryptodev->device = NULL;
 	cryptodev->data = NULL;
 
 	/* free metapool memory */
diff --git a/drivers/crypto/octeontx/otx_cryptodev_hw_access.c b/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
index 5e705a8..18f2e6b 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_hw_access.c
@@ -9,6 +9,7 @@ 
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_memzone.h>
+#include <rte_string_fns.h>
 
 #include "otx_cryptodev_hw_access.h"
 #include "otx_cryptodev_mbox.h"
@@ -366,7 +367,9 @@  otx_cpt_hw_init(struct cpt_vf *cptvf, void *pdev, void *reg_base, char *name)
 
 	/* Bar0 base address */
 	cptvf->reg_base = reg_base;
-	strncpy(cptvf->dev_name, name, 32);
+
+	/* Save device name */
+	strlcpy(cptvf->dev_name, name, (sizeof(cptvf->dev_name)));
 
 	cptvf->pdev = pdev;
 
diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/octeontx/otx_cryptodev_ops.c
index 23f9659..90d0c14 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_ops.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c
@@ -216,7 +216,7 @@  otx_cpt_que_pair_setup(struct rte_cryptodev *dev,
 	}
 
 	ret = otx_cpt_get_resource(cptvf, 0, &instance);
-	if (ret != 0) {
+	if (ret != 0 || instance == NULL) {
 		CPT_LOG_ERR("Error getting instance handle from device %s : "
 			    "ret = %d", dev->data->name, ret);
 		return ret;