Skip to contentSkip to conversation

bus/fslmc: fix use after rte_free

PATCH Superseded Stephen Hemminger 3 participants 10 messages Dec 18, 2024 – Jan 14, 2025 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bus/fslmc: fix use after rte_free

The cleanup loop would derefence the dpio_dev after freeing. Use TAILQ_FOREACH_SAFE to fix that.
Found by building with sanitizer undefined flag.

Fixes e55d0494ab98 ("bus/fslmc: support secondary process")
---
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +2 -1
index 2dfcf7a498..fb7d1968d1 100644
@@ -403,6 +403,7 @@ dpaa2_create_dpio_device(int vdev_fd,
 	struct rte_dpaa2_device *obj)
 {
 	struct dpaa2_dpio_dev *dpio_dev = NULL;
+	struct dpaa2_dpio_dev *dpio_tmp;
 	struct vfio_region_info reg_info = { .argsz = sizeof(reg_info)};
 	struct qbman_swp_desc p_des;
 	struct dpio_attr attr;
@@ -588,7 +589,7 @@ dpaa2_create_dpio_device(int vdev_fd,
 	rte_free(dpio_dev);
 
 	/* For each element in the list, cleanup */
-	TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) {
+	RTE_TAILQ_FOREACH_SAFE(dpio_dev, &dpio_dev_list, next, dpio_tmp) {
 		if (dpio_dev->dpio) {
 			dpio_disable(dpio_dev->dpio, CMD_PRI_LOW,
 				dpio_dev->token);
Signature · 1 line
2.45.2
#1 lore raw

v2 cover Fixes for build with -Dsanitize=undefined

Recent bug report https://bugs.dpdk.org/show_bug.cgi?id=1605
highlighted that no build is done with -Dsanitize=address,undefined. Doing a test build showed some new issues that were not being reported.

Note: a couple of these required introducing the equivalent _FOREACH_SAFE variant macros. These are in FreeBSD and in DPDK windows versions of queue.h but never made it to Linux sys/queue.h. Put the macro in the file where used (rather than a common spot) to make backporting the fixes easier.

Stephen Hemminger (5):
bus/fslmc: fix use after rte_free
net/bnxt: fix use after free
net/bnx2x: use RTE_BIT32
net/qede: fix use after free
vhost: use strlcpy instead of strncpy

 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c |   3 +-
 drivers/net/bnx2x/ecore_reg.h            | 130 +++++++++++------------
 drivers/net/bnxt/bnxt_filter.c           |  11 +-
 drivers/net/qede/qede_filter.c           |  20 ++--
 lib/vhost/socket.c                       |   3 +-
 5 files changed, 90 insertions(+), 77 deletions(-)
Signature · 1 line
2.45.2
#2 lore raw

PATCH v2 1/5 bus/fslmc: fix use after rte_free

The cleanup loop would deference the dpio_dev after freeing. Use TAILQ_FOREACH_SAFE to fix that.
Found by building with sanitizer undefined flag.

Fixes e55d0494ab98 ("bus/fslmc: support secondary process")
---
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +2 -1
index 2dfcf7a498..fb7d1968d1 100644
@@ -403,6 +403,7 @@ dpaa2_create_dpio_device(int vdev_fd,
 	struct rte_dpaa2_device *obj)
 {
 	struct dpaa2_dpio_dev *dpio_dev = NULL;
+	struct dpaa2_dpio_dev *dpio_tmp;
 	struct vfio_region_info reg_info = { .argsz = sizeof(reg_info)};
 	struct qbman_swp_desc p_des;
 	struct dpio_attr attr;
@@ -588,7 +589,7 @@ dpaa2_create_dpio_device(int vdev_fd,
 	rte_free(dpio_dev);
 
 	/* For each element in the list, cleanup */
-	TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) {
+	RTE_TAILQ_FOREACH_SAFE(dpio_dev, &dpio_dev_list, next, dpio_tmp) {
 		if (dpio_dev->dpio) {
 			dpio_disable(dpio_dev->dpio, CMD_PRI_LOW,
 				dpio_dev->token);
Signature · 1 line
2.45.2
#3 lore raw

PATCH v2 2/5 net/bnxt: fix use after free

In reply to Stephen Hemminger

The filter cleanup loop was using STAILQ_FOREACH and rte_free and would dereference the filter after free.

Found by build with -Dbsanitize=address,undefined

Fixes e8fe0e067b68 ("net/bnxt: fix allocation of PF info struct")
---
 drivers/net/bnxt/bnxt_filter.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/bnxt/bnxt_filter.c +10 -1
index 7b90ba651f..3804a5ec16 100644
@@ -12,6 +12,13 @@
 #include <rte_flow_driver.h>
 #include <rte_tailq.h>
 
+#ifndef STAILQ_FOREACH_SAFE
+#define	STAILQ_FOREACH_SAFE(var, head, field, tvar)			\
+	for ((var) = STAILQ_FIRST((head));				\
+	    (var) && ((tvar) = STAILQ_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+#endif
+
 #include "bnxt.h"
 #include "bnxt_filter.h"
 #include "bnxt_hwrm.h"
@@ -151,7 +158,9 @@ void bnxt_free_filter_mem(struct bnxt *bp)
 	bp->filter_info = NULL;
 
 	for (i = 0; i < bp->pf->max_vfs; i++) {
-		STAILQ_FOREACH(filter, &bp->pf->vf_info[i].filter, next) {
+		struct bnxt_filter_info *tmp;
+
+		STAILQ_FOREACH_SAFE(filter, &bp->pf->vf_info[i].filter, next, tmp) {
 			rte_free(filter);
 			STAILQ_REMOVE(&bp->pf->vf_info[i].filter, filter,
 				      bnxt_filter_info, next);
Signature · 1 line
2.45.2
#4 lore raw

PATCH v2 3/5 net/bnx2x: use RTE_BIT32

In reply to Stephen Hemminger

The expression "0x1 << 31" is actually undefined since 0x1 is an integer not unsigned. Fix the general problem by using the existing RTE_BIT32() macros instead.

Shows up as a cryptic warning when building with -Dbsanitize=undefined.

../drivers/net/bnx2x/bnx2x.c:3362:25: error: case label does not reduce to an integer constant

 3362 |                         case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
      |                         ^~~~
---
 drivers/net/bnx2x/ecore_reg.h | 130 +++++++++++++++++-----------------
 1 file changed, 65 insertions(+), 65 deletions(-)
drivers/net/bnx2x/ecore_reg.h +65 -65
index 6f7b0522f2..bddea3b832 100644
@@ -4359,71 +4359,71 @@
 #define HW_LOCK_RESOURCE_RECOVERY_REG				 11
 #define HW_LOCK_RESOURCE_RESET					 5
 #define HW_LOCK_RESOURCE_SPIO					 2
-#define AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT			 (0x1 << 4)
-#define AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR			 (0x1 << 5)
-#define AEU_INPUTS_ATTN_BITS_BRB_HW_INTERRUPT			 (0x1 << 19)
-#define AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR			 (0x1 << 18)
-#define AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT			 (0x1 << 31)
-#define AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR			 (0x1 << 30)
-#define AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT			 (0x1 << 9)
-#define AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR			 (0x1 << 8)
-#define AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT			 (0x1 << 7)
-#define AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR			 (0x1 << 6)
-#define AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT			 (0x1 << 29)
-#define AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR			 (0x1 << 28)
-#define AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT			 (0x1 << 1)
-#define AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR			 (0x1 << 0)
-#define AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR			 (0x1 << 18)
-#define AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT			 (0x1 << 11)
-#define AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR			 (0x1 << 10)
-#define AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT		 (0x1 << 13)
-#define AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR		 (0x1 << 12)
-#define AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0			 (0x1 << 2)
-#define AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR			 (0x1 << 12)
-#define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY		 (0x1 << 28)
-#define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY		 (0x1 << 31)
-#define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY		 (0x1 << 29)
-#define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY		 (0x1 << 30)
-#define AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT			 (0x1 << 15)
-#define AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR			 (0x1 << 14)
-#define AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR			 (0x1 << 14)
-#define AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR		 (0x1 << 20)
-#define AEU_INPUTS_ATTN_BITS_PBCLIENT_HW_INTERRUPT		 (0x1 << 31)
-#define AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR		 (0x1 << 30)
-#define AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR			 (0x1 << 0)
-#define AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT			 (0x1 << 2)
-#define AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR			 (0x1 << 3)
-#define AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT	 (0x1 << 5)
-#define AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR	 (0x1 << 4)
-#define AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT			 (0x1 << 3)
-#define AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR			 (0x1 << 2)
-#define AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT			 (0x1 << 3)
-#define AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR			 (0x1 << 2)
-#define AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR		 (0x1 << 22)
-#define AEU_INPUTS_ATTN_BITS_SPIO5				 (0x1 << 15)
-#define AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT			 (0x1 << 27)
-#define AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR			 (0x1 << 26)
-#define AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT		 (0x1 << 5)
-#define AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR		 (0x1 << 4)
-#define AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT			 (0x1 << 25)
-#define AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR			 (0x1 << 24)
-#define AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT			 (0x1 << 29)
-#define AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR			 (0x1 << 28)
-#define AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT			 (0x1 << 23)
-#define AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR			 (0x1 << 22)
-#define AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT			 (0x1 << 27)
-#define AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR			 (0x1 << 26)
-#define AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT			 (0x1 << 21)
-#define AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR			 (0x1 << 20)
-#define AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT			 (0x1 << 25)
-#define AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR			 (0x1 << 24)
-#define AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR		 (0x1 << 16)
-#define AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT			 (0x1 << 9)
-#define AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR			 (0x1 << 8)
-#define AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT			 (0x1 << 7)
-#define AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR			 (0x1 << 6)
-#define AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT			 (0x1 << 11)
-#define AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR			 (0x1 << 10)
+#define AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT			 RTE_BIT32(4)
+#define AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR			 RTE_BIT32(5)
+#define AEU_INPUTS_ATTN_BITS_BRB_HW_INTERRUPT			 RTE_BIT32(19)
+#define AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR			 RTE_BIT32(18)
+#define AEU_INPUTS_ATTN_BITS_CCM_HW_INTERRUPT			 RTE_BIT32(31)
+#define AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR			 RTE_BIT32(30)
+#define AEU_INPUTS_ATTN_BITS_CDU_HW_INTERRUPT			 RTE_BIT32(9)
+#define AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR			 RTE_BIT32(8)
+#define AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT			 RTE_BIT32(7)
+#define AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR			 RTE_BIT32(6)
+#define AEU_INPUTS_ATTN_BITS_CSDM_HW_INTERRUPT			 RTE_BIT32(29)
+#define AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR			 RTE_BIT32(28)
+#define AEU_INPUTS_ATTN_BITS_CSEMI_HW_INTERRUPT			 RTE_BIT32(1)
+#define AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR			 RTE_BIT32(0)
+#define AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR			 RTE_BIT32(18)
+#define AEU_INPUTS_ATTN_BITS_DMAE_HW_INTERRUPT			 RTE_BIT32(11)
+#define AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR			 RTE_BIT32(10)
+#define AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT		 RTE_BIT32(13)
+#define AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR		 RTE_BIT32(12)
+#define AEU_INPUTS_ATTN_BITS_GPIO0_FUNCTION_0			 RTE_BIT32(2)
+#define AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR			 RTE_BIT32(12)
+#define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY		 RTE_BIT32(28)
+#define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY		 RTE_BIT32(31)
+#define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY		 RTE_BIT32(29)
+#define AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY		 RTE_BIT32(30)
+#define AEU_INPUTS_ATTN_BITS_MISC_HW_INTERRUPT			 RTE_BIT32(15)
+#define AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR			 RTE_BIT32(14)
+#define AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR			 RTE_BIT32(14)
+#define AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR		 RTE_BIT32(20)
+#define AEU_INPUTS_ATTN_BITS_PBCLIENT_HW_INTERRUPT		 RTE_BIT32(31)
+#define AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR		 RTE_BIT32(30)
+#define AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR			 RTE_BIT32(0)
+#define AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT			 RTE_BIT32(2)
+#define AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR			 RTE_BIT32(3)
+#define AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_HW_INTERRUPT	 RTE_BIT32(5)
+#define AEU_INPUTS_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR	 RTE_BIT32(4)
+#define AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT			 RTE_BIT32(3)
+#define AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR			 RTE_BIT32(2)
+#define AEU_INPUTS_ATTN_BITS_QM_HW_INTERRUPT			 RTE_BIT32(3)
+#define AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR			 RTE_BIT32(2)
+#define AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR		 RTE_BIT32(22)
+#define AEU_INPUTS_ATTN_BITS_SPIO5				 RTE_BIT32(15)
+#define AEU_INPUTS_ATTN_BITS_TCM_HW_INTERRUPT			 RTE_BIT32(27)
+#define AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR			 RTE_BIT32(26)
+#define AEU_INPUTS_ATTN_BITS_TIMERS_HW_INTERRUPT		 RTE_BIT32(5)
+#define AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR		 RTE_BIT32(4)
+#define AEU_INPUTS_ATTN_BITS_TSDM_HW_INTERRUPT			 RTE_BIT32(25)
+#define AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR			 RTE_BIT32(24)
+#define AEU_INPUTS_ATTN_BITS_TSEMI_HW_INTERRUPT			 RTE_BIT32(29)
+#define AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR			 RTE_BIT32(28)
+#define AEU_INPUTS_ATTN_BITS_UCM_HW_INTERRUPT			 RTE_BIT32(23)
+#define AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR			 RTE_BIT32(22)
+#define AEU_INPUTS_ATTN_BITS_UPB_HW_INTERRUPT			 RTE_BIT32(27)
+#define AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR			 RTE_BIT32(26)
+#define AEU_INPUTS_ATTN_BITS_USDM_HW_INTERRUPT			 RTE_BIT32(21)
+#define AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR			 RTE_BIT32(20)
+#define AEU_INPUTS_ATTN_BITS_USEMI_HW_INTERRUPT			 RTE_BIT32(25)
+#define AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR			 RTE_BIT32(24)
+#define AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR		 RTE_BIT32(16)
+#define AEU_INPUTS_ATTN_BITS_XCM_HW_INTERRUPT			 RTE_BIT32(9)
+#define AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR			 RTE_BIT32(8)
+#define AEU_INPUTS_ATTN_BITS_XSDM_HW_INTERRUPT			 RTE_BIT32(7)
+#define AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR			 RTE_BIT32(6)
+#define AEU_INPUTS_ATTN_BITS_XSEMI_HW_INTERRUPT			 RTE_BIT32(11)
+#define AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR			 RTE_BIT32(10)
 #define RESERVED_GENERAL_ATTENTION_BIT_0	0
 
 #define EVEREST_GEN_ATTN_IN_USE_MASK		0x7ffe0
Signature · 1 line
2.45.2
#5 lore raw

PATCH v2 4/5 net/qede: fix use after free

In reply to Stephen Hemminger

The loop cleaning up flowdir resources was using SLIST_FOREACH but the inner loop would call rte_free. Found by building with address sanitizer undefined check.

Also remove needless initialization, and null check.

Fixes f5765f66f9bb ("net/qede: refactor flow director into generic aRFS")
---
 drivers/net/qede/qede_filter.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/net/qede/qede_filter.c +12 -8
index 14fb4338e9..5db36b03e2 100644
@@ -10,6 +10,13 @@
 #include <rte_errno.h>
 #include <rte_flow_driver.h>
 
+#ifndef SLIST_FOREACH_SAFE
+#define	SLIST_FOREACH_SAFE(var, head, field, tvar)			\
+	for ((var) = SLIST_FIRST((head));				\
+	    (var) && ((tvar) = SLIST_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+#endif
+
 #include "qede_ethdev.h"
 
 /* VXLAN tunnel classification mapping */
@@ -154,15 +161,12 @@ int qede_check_fdir_support(struct rte_eth_dev *eth_dev)
 void qede_fdir_dealloc_resc(struct rte_eth_dev *eth_dev)
 {
 	struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
-	struct qede_arfs_entry *tmp = NULL;
+	struct qede_arfs_entry *tmp, *tmp2;
 
-	SLIST_FOREACH(tmp, &qdev->arfs_info.arfs_list_head, list) {
-		if (tmp) {
-			rte_memzone_free(tmp->mz);
-			SLIST_REMOVE(&qdev->arfs_info.arfs_list_head, tmp,
-				     qede_arfs_entry, list);
-			rte_free(tmp);
-		}
+	SLIST_FOREACH_SAFE(tmp, &qdev->arfs_info.arfs_list_head, list, tmp2) {
+		rte_memzone_free(tmp->mz);
+		SLIST_REMOVE(&qdev->arfs_info.arfs_list_head, tmp, qede_arfs_entry, list);
+		rte_free(tmp);
 	}
 }
 
Signature · 1 line
2.45.2
#6 lore raw

PATCH v2 5/5 vhost: use strlcpy instead of strncpy

In reply to Stephen Hemminger

Some tools such as gcc address sanitizer will complain if strncpy is used to completely fill a string since it will not be null terminated. Since the previous code forced as null at end, use strlcpy() to get the same effect.

---
 lib/vhost/socket.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/vhost/socket.c +1 -2
index d29d15494c..f938189cc2 100644
@@ -359,8 +359,7 @@ create_unix_socket(struct vhost_user_socket *vsocket)
 
 	memset(un, 0, sizeof(*un));
 	un->sun_family = AF_UNIX;
-	strncpy(un->sun_path, vsocket->path, sizeof(un->sun_path));
-	un->sun_path[sizeof(un->sun_path) - 1] = '\0';
+	strlcpy(un->sun_path, vsocket->path, sizeof(un->sun_path));
 
 	vsocket->socket_fd = fd;
 	return 0;
Signature · 1 line
2.45.2
Acked-by on v2 5/5
#7 lore raw

Re: [PATCH v2 5/5] vhost: use strlcpy instead of strncpy

Quoted 15 lines · Stephen Hemminger

Some tools such as gcc address sanitizer will complain if strncpy is used to completely fill a string since it will not be null terminated. Since the previous code forced as null at end, use strlcpy() to get the same effect.

---
 lib/vhost/socket.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
lib/vhost/socket.c +0 -0
index d29d15494c..f938189cc2 100644

lib/vhost/socket.c create_unix_socket(struct vhost_user_socket *vsocket) · line 363

Quoted 7 lines
lib/vhost/socket.c +1 -2
@@ -359,8 +359,7 @@ create_unix_socket(struct vhost_user_socket *vsocket)
 
 	memset(un, 0, sizeof(*un));
 	un->sun_family = AF_UNIX;
-	strncpy(un->sun_path, vsocket->path, sizeof(un->sun_path));
-	un->sun_path[sizeof(un->sun_path) - 1] = '\0';
+	strlcpy(un->sun_path, vsocket->path, sizeof(un->sun_path));
 
#8 lore raw

Re: [PATCH v2 5/5] vhost: use strlcpy instead of strncpy

In reply to Stephen Hemminger
Quoted 6 lines · On Thu, 19 Dec 2024 14:49:55 -0800 Stephen Hemminger…

Some tools such as gcc address sanitizer will complain if strncpy is used to completely fill a string since it will not be null terminated. Since the previous code forced as null at end, use strlcpy() to get the same effect.

Recheck-request: iol-compile-amd64-testing