DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/2] fix use after free
@ 2025-03-13 17:22 Stephen Hemminger
  2025-03-13 17:22 ` [PATCH 1/2] net/qede: " Stephen Hemminger
  2025-03-13 17:22 ` [PATCH 2/2] bus/fslmc: " Stephen Hemminger
  0 siblings, 2 replies; 4+ messages in thread
From: Stephen Hemminger @ 2025-03-13 17:22 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

These are bug fixes reported by PVS studio.
Later patches can consolidate the FOREACH_SAFE macros,
but these patches are intended to fix the current bugs
in main and stable branches.

Stephen Hemminger (2):
  net/qede: fix use after free
  bus/fslmc: fix use after free

 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 10 +++++++++-
 drivers/net/qede/qede_filter.c           | 20 ++++++++++++--------
 2 files changed, 21 insertions(+), 9 deletions(-)

-- 
2.47.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] net/qede: fix use after free
  2025-03-13 17:22 [PATCH 0/2] fix use after free Stephen Hemminger
@ 2025-03-13 17:22 ` Stephen Hemminger
  2025-03-13 17:22 ` [PATCH 2/2] bus/fslmc: " Stephen Hemminger
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2025-03-13 17:22 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, shahed.shaikh, stable, Devendra Singh Rawat,
	Alok Prasad, Shahed Shaikh

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")
Cc: shahed.shaikh@cavium.com
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/qede/qede_filter.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/net/qede/qede_filter.c b/drivers/net/qede/qede_filter.c
index 14fb4338e9..cecb58c997 100644
--- a/drivers/net/qede/qede_filter.c
+++ b/drivers/net/qede/qede_filter.c
@@ -12,6 +12,13 @@
 
 #include "qede_ethdev.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
+
 /* VXLAN tunnel classification mapping */
 const struct _qede_udp_tunn_types {
 	uint16_t rte_filter_type;
@@ -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);
 	}
 }
 
-- 
2.47.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] bus/fslmc: fix use after free
  2025-03-13 17:22 [PATCH 0/2] fix use after free Stephen Hemminger
  2025-03-13 17:22 ` [PATCH 1/2] net/qede: " Stephen Hemminger
@ 2025-03-13 17:22 ` Stephen Hemminger
  2025-03-16 15:00   ` Markus Elfring
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2025-03-13 17:22 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, shreyansh.jain, stable, Hemant Agrawal, Sachin Saxena

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")
Cc: shreyansh.jain@nxp.com
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 2dfcf7a498..bc03b4dd05 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -38,6 +38,13 @@
 #include "dpaa2_hw_dpio.h"
 #include <mc/fsl_dpmng.h>
 
+#ifndef TAILQ_FOREACH_SAFE
+#define	TAILQ_FOREACH_SAFE(var, head, field, tvar)			\
+	for ((var) = TAILQ_FIRST((head));				\
+	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);		\
+	    (var) = (tvar))
+#endif
+
 #define NUM_HOST_CPUS RTE_MAX_LCORE
 
 struct dpaa2_io_portal_t dpaa2_io_portal[RTE_MAX_LCORE];
@@ -403,6 +410,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 +596,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) {
+	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);
-- 
2.47.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] bus/fslmc: fix use after free
  2025-03-13 17:22 ` [PATCH 2/2] bus/fslmc: " Stephen Hemminger
@ 2025-03-16 15:00   ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-03-16 15:00 UTC (permalink / raw)
  To: Stephen Hemminger, dev
  Cc: stable, LKML, Hemant Agrawal, Sachin Saxena, Shreyansh Jain

> The cleanup loop would deference the dpio_dev after freeing.
…
                         dereference?

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-17  9:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-13 17:22 [PATCH 0/2] fix use after free Stephen Hemminger
2025-03-13 17:22 ` [PATCH 1/2] net/qede: " Stephen Hemminger
2025-03-13 17:22 ` [PATCH 2/2] bus/fslmc: " Stephen Hemminger
2025-03-16 15:00   ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).