Skip to contentSkip to conversation

Coverity related fixes

PATCH In review Stephen Hemminger 4 participants 13 messages Mar 1, 2024 – Mar 6, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

cover Coverity related fixes

Some small stuff that can be picked up after 24.03

Stephen Hemminger (6):
test/bpf: make sure mbuf is initialized
net/tap: log if netlink ext ack not possible
examples/l2fwd-keepalive: use rte_drand_max
net/qede: replace use of rand()
pipeline: replace use of rand()
baseband/fpga_5gnr: don't use rand()

 app/test/test_bpf.c                                | 1 +
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 3 ++-
 drivers/net/qede/qede_ethdev.c                     | 4 ++--
 drivers/net/tap/tap_netlink.c                      | 3 ++-
 examples/l2fwd-keepalive/main.c                    | 3 ++-
 lib/pipeline/rte_swx_ipsec.c                       | 3 ++-
 6 files changed, 11 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/6 test/bpf: make sure mbuf is initialized

The BPF filter test was not initializing off load flags.

Coverity issue: 375844

Fixes 2eccf6afbea9 ("bpf: add function to convert classic BPF to DPDK BPF")
---
 app/test/test_bpf.c | 1 +
 1 file changed, 1 insertion(+)
app/test/test_bpf.c +1 -0
index f83e72a9adfd..53e3a3112371 100644
@@ -3341,6 +3341,7 @@ test_bpf_filter_sanity(pcap_t *pcap)
 		struct rte_ipv4_hdr ip_hdr;
 	} *hdr;
 
+	memset(&mb, 0, sizeof(mb));
 	dummy_mbuf_prep(&mb, tbuf, sizeof(tbuf), plen);
 	m = &mb;
 
Signature · 1 line
2.43.0
#3 lore raw

PATCH 2/6 net/tap: log if netlink ext ack not possible

In reply to Stephen Hemminger

If kernel doesn't support external ack, log that to aide in any problem diagnosis.

Coverity issue: 362848

Fixes 647909bcf34b ("net/tap: use netlink extended ack support")
---
 drivers/net/tap/tap_netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tap/tap_netlink.c +2 -1
index 75af3404b035..d9c260127d52 100644
@@ -72,7 +72,8 @@ tap_nl_init(uint32_t nl_groups)
 
 #ifdef NETLINK_EXT_ACK
 	/* Ask for extended ACK response. on older kernel will ignore request. */
-	setsockopt(fd, SOL_NETLINK, NETLINK_EXT_ACK, &one, sizeof(one));
+	if (setsockopt(fd, SOL_NETLINK, NETLINK_EXT_ACK, &one, sizeof(one)) < 0)
+		TAP_LOG(NOTICE, "Unable to request netlink error information");
 #endif
 
 	if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
Signature · 1 line
2.43.0
#4 lore raw

PATCH 3/6 examples/l2fwd-keepalive: use rte_drand_max

In reply to Stephen Hemminger

There is a better way than using rand() to compute a random interval.

---
 examples/l2fwd-keepalive/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
examples/l2fwd-keepalive/main.c +2 -1
index 7e0f99a361bc..c077e7f3d4f0 100644
@@ -26,6 +26,7 @@
 #include <rte_launch.h>
 #include <rte_cycles.h>
 #include <rte_prefetch.h>
+#include <rte_random.h>
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_branch_prediction.h>
@@ -220,7 +221,7 @@ l2fwd_main_loop(void)
 	}
 
 	uint64_t tsc_initial = rte_rdtsc();
-	uint64_t tsc_lifetime = (rand()&0x07) * rte_get_tsc_hz();
+	uint64_t tsc_lifetime = rte_rand_max(8 * rte_get_tsc_hz());
 
 	while (!terminate_signal_received) {
 		/* Keepalive heartbeat. 8< */
Signature · 1 line
2.43.0
#5 lore raw

PATCH 4/6 net/qede: replace use of rand()

In reply to Stephen Hemminger

The function of rand() is a weak random number generator. Use the DPDK rte_rand() instead.

Note: this doesn't matter for real security, since most drivers use a fixed RSS default key.

---
 drivers/net/qede/qede_ethdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/qede/qede_ethdev.c +2 -2
index 254548d40638..bee9fa4f60a1 100644
@@ -7,6 +7,7 @@
 #include "qede_ethdev.h"
 #include <rte_string_fns.h>
 #include <rte_alarm.h>
+#include <rte_random.h>
 #include <rte_kvargs.h>
 
 static const struct qed_eth_ops *qed_ops;
@@ -1040,9 +1041,8 @@ static void qede_prandom_bytes(uint32_t *buff)
 {
 	uint8_t i;
 
-	srand((unsigned int)time(NULL));
 	for (i = 0; i < ECORE_RSS_KEY_SIZE; i++)
-		buff[i] = rand();
+		buff[i] = rte_rand();
 }
 
 int qede_config_rss(struct rte_eth_dev *eth_dev)
Signature · 1 line
2.43.0
#7 lore raw

PATCH 5/6 pipeline: replace use of rand()

In reply to Stephen Hemminger

The rand() function is weak and using it for salt might be a future security issue. Use rte_rand() which has a bigger period and more secure.

---
 lib/pipeline/rte_swx_ipsec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/pipeline/rte_swx_ipsec.c +2 -1
index 28576c2a4812..eb97b9eb9106 100644
@@ -7,6 +7,7 @@
 #include <arpa/inet.h>
 
 #include <rte_common.h>
+#include <rte_random.h>
 #include <rte_ip.h>
 #include <rte_tailq.h>
 #include <rte_eal_memconfig.h>
@@ -1453,7 +1454,7 @@ crypto_xform_get(struct rte_swx_ipsec_sa_params *p,
 		switch (p->crypto.cipher_auth.cipher.alg) {
 		case RTE_CRYPTO_CIPHER_AES_CBC:
 		case RTE_CRYPTO_CIPHER_3DES_CBC:
-			salt = (uint32_t)rand();
+			salt = rte_rand();
 			break;
 
 		case RTE_CRYPTO_CIPHER_AES_CTR:
Signature · 1 line
2.43.0
#9 lore raw

PATCH 6/6 baseband/fpga_5gnr: don't use rand()

In reply to Stephen Hemminger

The function rand is very weak and should not be used. Use the DPDK rte_rand() which is seeded from entropy instead.

Coverity issue: 414987

Fixes b3d326e438f1 ("baseband/fpga_5gnr_fec: add FPGA mutex")
---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +2 -1
index efc1d3a7725b..9b253cde280d 100644
@@ -14,6 +14,7 @@
 #include <bus_pci_driver.h>
 #include <rte_byteorder.h>
 #include <rte_cycles.h>
+#include <rte_random.h>
 
 #include <rte_bbdev.h>
 #include <rte_bbdev_pmd.h>
@@ -1990,7 +1991,7 @@ fpga_5gnr_mutex_acquisition(struct fpga_5gnr_queue *q)
 {
 	uint32_t mutex_ctrl, mutex_read, cnt = 0;
 	/* Assign a unique id for the duration of the DDR access */
-	q->ddr_mutex_uuid = rand();
+	q->ddr_mutex_uuid = rte_rand();
 	/* Request and wait for acquisition of the mutex */
 	mutex_ctrl = (q->ddr_mutex_uuid << 16) + 1;
 	do {
Signature · 1 line
2.43.0
Acked-by on v1 6/6
#11 lore raw

RE: [PATCH 6/6] baseband/fpga_5gnr: don't use rand()

In reply to Stephen Hemminger
Quoted 9 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, March 1, 2024 9:57 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Vargas, Hernan <[email protected]>; Chautru, Nicolas <[email protected]>
Subject: [PATCH 6/6] baseband/fpga_5gnr: don't use rand()

Quoted 7 lines

The function rand is very weak and should not be used. Use the DPDK rte_rand() which is seeded from entropy instead.

Coverity issue: 414987

Fixes b3d326e438f1 ("baseband/fpga_5gnr_fec: add FPGA mutex")
Quoted 28 lines
---
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c +2 -2
index efc1d3a7725b..9b253cde280d 100644
@@ -14,6 +14,7 @@
 #include <bus_pci_driver.h>
 #include <rte_byteorder.h>
 #include <rte_cycles.h>
+#include <rte_random.h>
 
 #include <rte_bbdev.h>
 #include <rte_bbdev_pmd.h>
@@ -1990,7 +1991,7 @@ fpga_5gnr_mutex_acquisition(struct
 fpga_5gnr_queue *q)  {
 	uint32_t mutex_ctrl, mutex_read, cnt = 0;
 	/* Assign a unique id for the duration of the DDR access */
-	q->ddr_mutex_uuid = rand();
+	q->ddr_mutex_uuid = rte_rand();
 	/* Request and wait for acquisition of the mutex */
 	mutex_ctrl = (q->ddr_mutex_uuid << 16) + 1;
 	do {
--

2.43.0

#12 lore raw
In reply to Stephen Hemminger
Quoted 11 lines · Stephen Hemminger

Some small stuff that can be picked up after 24.03

Stephen Hemminger (6):
test/bpf: make sure mbuf is initialized
net/tap: log if netlink ext ack not possible
examples/l2fwd-keepalive: use rte_drand_max
net/qede: replace use of rand()
pipeline: replace use of rand()
baseband/fpga_5gnr: don't use rand()

Quoted 7 lines
 app/test/test_bpf.c                                | 1 +
 drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 3 ++-
 drivers/net/qede/qede_ethdev.c                     | 4 ++--
 drivers/net/tap/tap_netlink.c                      | 3 ++-
 examples/l2fwd-keepalive/main.c                    | 3 ++-
 lib/pipeline/rte_swx_ipsec.c                       | 3 ++-
 6 files changed, 11 insertions(+), 6 deletions(-)

Series applied, thanks.

Signature · 1 line
David Marchand