Skip to contentSkip to conversation

crypto/nitrox: fix coverity defects

PATCH In review Nagadheeraj Rottela 3 participants 10 messages Feb 20, 2020 – Apr 5, 2020 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto/nitrox: fix coverity defects

Address the defects reported by coverity: Unintended sign extension and Out-of-bounds access.

Coverity issue: 349899, 349905, 349911, 349921, 349923, 349926

Fixes 32e4930d5a3b ("crypto/nitrox: add hardware queue management")
Fixes 9fdef0cc2385 ("crypto/nitrox: create symmetric cryptodev")
---
 drivers/crypto/nitrox/nitrox_csr.h | 18 +++++++++---------
 drivers/crypto/nitrox/nitrox_sym.c |  3 ++-
 2 files changed, 11 insertions(+), 10 deletions(-)
drivers/crypto/nitrox/nitrox_csr.h +9 -9
index 8cd92e38b..b4c969b26 100644
@@ -12,15 +12,15 @@
 #define NITROX_CSR_ADDR(bar_addr, offset) (bar_addr + (offset))
 
 /* NPS packet registers */
-#define NPS_PKT_IN_INSTR_CTLX(_i)	(0x10060 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_BADDRX(_i)	(0x10068 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_RSIZEX(_i)	(0x10070 + ((_i) * 0x40000))
-#define NPS_PKT_IN_DONE_CNTSX(_i)	(0x10080 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_BAOFF_DBELLX(_i)	(0x10078 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INT_LEVELSX(_i)		(0x10088 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_CTLX(_i)		(0x10000 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_CNTSX(_i)		(0x10008 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_INT_LEVELSX(_i)	(0x10010 + ((_i) * 0x40000))
+#define NPS_PKT_IN_INSTR_CTLX(_i)	(0x10060UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_BADDRX(_i)	(0x10068UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_RSIZEX(_i)	(0x10070UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_DONE_CNTSX(_i)	(0x10080UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_BAOFF_DBELLX(_i)	(0x10078UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INT_LEVELSX(_i)		(0x10088UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_CTLX(_i)		(0x10000UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_CNTSX(_i)		(0x10008UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_INT_LEVELSX(_i)	(0x10010UL + ((_i) * 0x40000UL))
 
 /* AQM Virtual Function Registers */
 #define AQMQ_QSZX(_i)			(0x20008 + ((_i)*0x40000))
drivers/crypto/nitrox/nitrox_sym.c +2 -1
index 56410c44d..d1b32fec9 100644
@@ -683,7 +683,8 @@ nitrox_sym_pmd_create(struct nitrox_device *ndev)
 	struct rte_cryptodev *cdev;
 
 	rte_pci_device_name(&ndev->pdev->addr, name, sizeof(name));
-	snprintf(name + strlen(name), RTE_CRYPTODEV_NAME_MAX_LEN, "_n5sym");
+	snprintf(name + strlen(name), RTE_CRYPTODEV_NAME_MAX_LEN - strlen(name),
+		 "_n5sym");
 	ndev->rte_sym_dev.driver = &nitrox_rte_sym_drv;
 	ndev->rte_sym_dev.numa_node = ndev->pdev->device.numa_node;
 	ndev->rte_sym_dev.devargs = NULL;
Signature · 1 line
2.13.6
#1 lore raw
Quoted 11 lines

Address the defects reported by coverity: Unintended sign extension and Out-of-bounds access.

Coverity issue: 349899, 349905, 349911, 349921, 349923, 349926

Fixes 32e4930d5a3b ("crypto/nitrox: add hardware queue management")
Fixes 9fdef0cc2385 ("crypto/nitrox: create symmetric cryptodev")

---

Thomas,

Can you take this directly on master.

Thanks,
Akhil

#2 lore raw

20/02/2020 12:07, Akhil Goyal:

Quoted 6 lines
Quoted 6 lines

Address the defects reported by coverity: Unintended sign extension and Out-of-bounds access.

Coverity issue: 349899, 349905, 349911, 349921, 349923, 349926

Quoted 8 lines
Quoted 5 lines
Fixes 32e4930d5a3b ("crypto/nitrox: add hardware queue management")
Fixes 9fdef0cc2385 ("crypto/nitrox: create symmetric cryptodev")

---

Thomas,

Can you take this directly on master.

No sorry, I can't because there is no review and test.

And I think we should not have general patches for Coverity defects. Instead we must do one patch per issue. Here two:
- sign of constants
- out-of-bound access
In each patch, we must have a description of the consequence of the issue.

Thanks

#3 lore raw

PATCH v2 1/2 crypto/nitrox: fix invalid CSR register address generation

In reply to Nagadheeraj Rottela

If the NPS_PKT ring/port is greater than 8191 the NPS_PKT*() macros will evaluate to incorrect values due to unintended sign extension from int to unsigned long. To fix this, add UL suffix to the constants in these macros.

Coverity issue: 349899, 349905, 349911, 349921, 349923

Fixes 32e4930d5a3b ("crypto/nitrox: add hardware queue management")
---
 drivers/crypto/nitrox/nitrox_csr.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/crypto/nitrox/nitrox_csr.h +9 -9
index 8cd92e38b..b4c969b26 100644
@@ -12,15 +12,15 @@
 #define NITROX_CSR_ADDR(bar_addr, offset) (bar_addr + (offset))
 
 /* NPS packet registers */
-#define NPS_PKT_IN_INSTR_CTLX(_i)	(0x10060 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_BADDRX(_i)	(0x10068 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_RSIZEX(_i)	(0x10070 + ((_i) * 0x40000))
-#define NPS_PKT_IN_DONE_CNTSX(_i)	(0x10080 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_BAOFF_DBELLX(_i)	(0x10078 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INT_LEVELSX(_i)		(0x10088 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_CTLX(_i)		(0x10000 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_CNTSX(_i)		(0x10008 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_INT_LEVELSX(_i)	(0x10010 + ((_i) * 0x40000))
+#define NPS_PKT_IN_INSTR_CTLX(_i)	(0x10060UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_BADDRX(_i)	(0x10068UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_RSIZEX(_i)	(0x10070UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_DONE_CNTSX(_i)	(0x10080UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_BAOFF_DBELLX(_i)	(0x10078UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INT_LEVELSX(_i)		(0x10088UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_CTLX(_i)		(0x10000UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_CNTSX(_i)		(0x10008UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_INT_LEVELSX(_i)	(0x10010UL + ((_i) * 0x40000UL))
 
 /* AQM Virtual Function Registers */
 #define AQMQ_QSZX(_i)			(0x20008 + ((_i)*0x40000))
Signature · 1 line
2.13.6
#4 lore raw

PATCH v2 2/2 crypto/nitrox: fix array out of bounds access

In nitrox_sym_pmd_create() the name array will overflow if the pci device name is greater than 57 bytes. To fix this issue subtract pci device name length from array length while appending substring to the name.

Coverity issue: 349926

Fixes 9fdef0cc2385 ("crypto/nitrox: create symmetric cryptodev")
---
 drivers/crypto/nitrox/nitrox_sym.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/nitrox/nitrox_sym.c +2 -1
index 56410c44d..d1b32fec9 100644
@@ -683,7 +683,8 @@ nitrox_sym_pmd_create(struct nitrox_device *ndev)
 	struct rte_cryptodev *cdev;
 
 	rte_pci_device_name(&ndev->pdev->addr, name, sizeof(name));
-	snprintf(name + strlen(name), RTE_CRYPTODEV_NAME_MAX_LEN, "_n5sym");
+	snprintf(name + strlen(name), RTE_CRYPTODEV_NAME_MAX_LEN - strlen(name),
+		 "_n5sym");
 	ndev->rte_sym_dev.driver = &nitrox_rte_sym_drv;
 	ndev->rte_sym_dev.numa_node = ndev->pdev->device.numa_node;
 	ndev->rte_sym_dev.devargs = NULL;
Signature · 1 line
2.13.6
#5 lore raw

Re: [dpdk-dev] [PATCH v2 1/2] crypto/nitrox: fix invalid CSR register address generation

In reply to Nagadheeraj Rottela
Quoted 49 lines

If the NPS_PKT ring/port is greater than 8191 the NPS_PKT*() macros will evaluate to incorrect values due to unintended sign extension from int to unsigned long. To fix this, add UL suffix to the constants in these macros.

Coverity issue: 349899, 349905, 349911, 349921, 349923

Fixes 32e4930d5a3b ("crypto/nitrox: add hardware queue management")
---
 drivers/crypto/nitrox/nitrox_csr.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/crypto/nitrox/nitrox_csr.h +8 -9
index 8cd92e38b..b4c969b26 100644
@@ -12,15 +12,15 @@
 #define NITROX_CSR_ADDR(bar_addr, offset) (bar_addr + (offset))
 
 /* NPS packet registers */
-#define NPS_PKT_IN_INSTR_CTLX(_i)	(0x10060 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_BADDRX(_i)	(0x10068 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_RSIZEX(_i)	(0x10070 + ((_i) * 0x40000))
-#define NPS_PKT_IN_DONE_CNTSX(_i)	(0x10080 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_BAOFF_DBELLX(_i)	(0x10078 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INT_LEVELSX(_i)		(0x10088 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_CTLX(_i)		(0x10000 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_CNTSX(_i)		(0x10008 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_INT_LEVELSX(_i)	(0x10010 + ((_i) * 0x40000))
+#define NPS_PKT_IN_INSTR_CTLX(_i)	(0x10060UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_BADDRX(_i)	(0x10068UL + ((_i) *
 0x40000UL))
+#define NPS_PKT_IN_INSTR_RSIZEX(_i)	(0x10070UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_DONE_CNTSX(_i)	(0x10080UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_BAOFF_DBELLX(_i)	(0x10078UL + ((_i) *
 0x40000UL))
+#define NPS_PKT_IN_INT_LEVELSX(_i)		(0x10088UL + ((_i) *
 0x40000UL))
+#define NPS_PKT_SLC_CTLX(_i)		(0x10000UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_CNTSX(_i)		(0x10008UL + ((_i) *

0x40000UL))
+#define NPS_PKT_SLC_INT_LEVELSX(_i) (0x10010UL + ((_i) * 0x40000UL))

Quoted 2 lines

/* AQM Virtual Function Registers */
#define AQMQ_QSZX(_i) (0x20008 + ((_i)*0x40000))

AQMQ_QSZX may also need to be updated.

#6 lore raw

PATCH v3 1/2 crypto/nitrox: fix invalid CSR register address generation

If the NPS_PKT ring/port is greater than 8191 the NPS_PKT*() macros will evaluate to incorrect values due to unintended sign extension from int to unsigned long. To fix this, add UL suffix to the constants in these macros. The same problem is with AQMQ_QSZX() macro also.

Coverity issue: 349899, 349905, 349911, 349921, 349923

Fixes 32e4930d5a3b ("crypto/nitrox: add hardware queue management")
Fixes 0a8fc2423bff ("crypto/nitrox: introduce Nitrox driver")
---
 drivers/crypto/nitrox/nitrox_csr.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/crypto/nitrox/nitrox_csr.h +10 -10
index 8cd92e38b..de7a3c671 100644
@@ -12,18 +12,18 @@
 #define NITROX_CSR_ADDR(bar_addr, offset) (bar_addr + (offset))
 
 /* NPS packet registers */
-#define NPS_PKT_IN_INSTR_CTLX(_i)	(0x10060 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_BADDRX(_i)	(0x10068 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_RSIZEX(_i)	(0x10070 + ((_i) * 0x40000))
-#define NPS_PKT_IN_DONE_CNTSX(_i)	(0x10080 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INSTR_BAOFF_DBELLX(_i)	(0x10078 + ((_i) * 0x40000))
-#define NPS_PKT_IN_INT_LEVELSX(_i)		(0x10088 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_CTLX(_i)		(0x10000 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_CNTSX(_i)		(0x10008 + ((_i) * 0x40000))
-#define NPS_PKT_SLC_INT_LEVELSX(_i)	(0x10010 + ((_i) * 0x40000))
+#define NPS_PKT_IN_INSTR_CTLX(_i)	(0x10060UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_BADDRX(_i)	(0x10068UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_RSIZEX(_i)	(0x10070UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_DONE_CNTSX(_i)	(0x10080UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INSTR_BAOFF_DBELLX(_i)	(0x10078UL + ((_i) * 0x40000UL))
+#define NPS_PKT_IN_INT_LEVELSX(_i)		(0x10088UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_CTLX(_i)		(0x10000UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_CNTSX(_i)		(0x10008UL + ((_i) * 0x40000UL))
+#define NPS_PKT_SLC_INT_LEVELSX(_i)	(0x10010UL + ((_i) * 0x40000UL))
 
 /* AQM Virtual Function Registers */
-#define AQMQ_QSZX(_i)			(0x20008 + ((_i)*0x40000))
+#define AQMQ_QSZX(_i)			(0x20008UL + ((_i) * 0x40000UL))
 
 static inline uint64_t
 nitrox_read_csr(uint8_t *bar_addr, uint64_t offset)
Signature · 1 line
2.13.6
#7 lore raw

PATCH v3 2/2 crypto/nitrox: fix array out of bounds access

In nitrox_sym_pmd_create() the name array will overflow if the pci device name is greater than 57 bytes. To fix this issue subtract pci device name length from array length while appending substring to the name.

Coverity issue: 349926

Fixes 9fdef0cc2385 ("crypto/nitrox: create symmetric cryptodev")
---
 drivers/crypto/nitrox/nitrox_sym.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/crypto/nitrox/nitrox_sym.c +2 -1
index 56410c44d..d1b32fec9 100644
@@ -683,7 +683,8 @@ nitrox_sym_pmd_create(struct nitrox_device *ndev)
 	struct rte_cryptodev *cdev;
 
 	rte_pci_device_name(&ndev->pdev->addr, name, sizeof(name));
-	snprintf(name + strlen(name), RTE_CRYPTODEV_NAME_MAX_LEN, "_n5sym");
+	snprintf(name + strlen(name), RTE_CRYPTODEV_NAME_MAX_LEN - strlen(name),
+		 "_n5sym");
 	ndev->rte_sym_dev.driver = &nitrox_rte_sym_drv;
 	ndev->rte_sym_dev.numa_node = ndev->pdev->device.numa_node;
 	ndev->rte_sym_dev.devargs = NULL;
Signature · 1 line
2.13.6
Applied
#8 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] crypto/nitrox: fix array out of bounds access

Quoted 15 lines

-----Original Message-----
From: Nagadheeraj Rottela <[email protected]>
Sent: Friday, March 27, 2020 7:13 PM
To: Akhil Goyal <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Nagadheeraj Rottela <[email protected]>
Subject: [PATCH v3 2/2] crypto/nitrox: fix array out of bounds access

In nitrox_sym_pmd_create() the name array will overflow if the pci device name is greater than 57 bytes. To fix this issue subtract pci device name length from array length while appending substring to the name.

Quoted 6 lines

Coverity issue: 349926

Fixes 9fdef0cc2385 ("crypto/nitrox: create symmetric cryptodev")

---

Applied to dpdk-next-crypto

Thanks.

Applied
#9 lore raw

Re: [dpdk-dev] [PATCH v3 1/2] crypto/nitrox: fix invalid CSR register address generation

In reply to Nagadheeraj Rottela
Quoted 7 lines

If the NPS_PKT ring/port is greater than 8191 the NPS_PKT*() macros will evaluate to incorrect values due to unintended sign extension from int to unsigned long. To fix this, add UL suffix to the constants in these macros. The same problem is with AQMQ_QSZX() macro also.

Quoted 7 lines

Coverity issue: 349899, 349905, 349911, 349921, 349923

Fixes 32e4930d5a3b ("crypto/nitrox: add hardware queue management")
Fixes 0a8fc2423bff ("crypto/nitrox: introduce Nitrox driver")

---

Applied to dpdk-next-crypto

Thanks.