patches for DPDK stable branches
 help / color / mirror / Atom feed
* [RFC 2/7] net/qede: fix use after free
       [not found] <20250127180842.97907-1-stephen@networkplumber.org>
@ 2025-01-27 18:03 ` Stephen Hemminger
  2025-01-27 18:03 ` [RFC 3/7] bus/fslmc: " Stephen Hemminger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2025-01-27 18:03 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_ethdev.h |  3 +--
 drivers/net/qede/qede_filter.c | 13 +++++--------
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/net/qede/qede_ethdev.h b/drivers/net/qede/qede_ethdev.h
index 3015c18504..b502658425 100644
--- a/drivers/net/qede/qede_ethdev.h
+++ b/drivers/net/qede/qede_ethdev.h
@@ -8,8 +8,7 @@
 #ifndef _QEDE_ETHDEV_H_
 #define _QEDE_ETHDEV_H_
 
-#include <sys/queue.h>
-
+#include <rte_queue.h>
 #include <rte_ether.h>
 #include <ethdev_driver.h>
 #include <ethdev_pci.h>
diff --git a/drivers/net/qede/qede_filter.c b/drivers/net/qede/qede_filter.c
index 14fb4338e9..c3f74c89d9 100644
--- a/drivers/net/qede/qede_filter.c
+++ b/drivers/net/qede/qede_filter.c
@@ -154,15 +154,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.45.2


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

* [RFC 3/7] bus/fslmc: fix use after free
       [not found] <20250127180842.97907-1-stephen@networkplumber.org>
  2025-01-27 18:03 ` [RFC 2/7] net/qede: fix use after free Stephen Hemminger
@ 2025-01-27 18:03 ` Stephen Hemminger
  2025-01-27 18:03 ` [RFC 4/7] net/bnxt: " Stephen Hemminger
       [not found] ` <20250214172134.73908-1-stephen@networkplumber.org>
  3 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2025-01-27 18:03 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>
---
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 2dfcf7a498..6ae15c2054 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -15,7 +15,6 @@
 #include <signal.h>
 #include <pthread.h>
 #include <sys/types.h>
-#include <sys/queue.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
@@ -27,6 +26,7 @@
 #include <ethdev_driver.h>
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
+#include <rte_queue.h>
 #include <rte_string_fns.h>
 #include <rte_cycles.h>
 #include <rte_kvargs.h>
@@ -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) {
+	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.45.2


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

* [RFC 4/7] net/bnxt: fix use after free
       [not found] <20250127180842.97907-1-stephen@networkplumber.org>
  2025-01-27 18:03 ` [RFC 2/7] net/qede: fix use after free Stephen Hemminger
  2025-01-27 18:03 ` [RFC 3/7] bus/fslmc: " Stephen Hemminger
@ 2025-01-27 18:03 ` Stephen Hemminger
  2025-01-27 19:25   ` Ajit Khaparde
       [not found] ` <20250214172134.73908-1-stephen@networkplumber.org>
  3 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2025-01-27 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, ajit.khaparde, stable, Somnath Kotur, Kalesh AP

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")
Cc: ajit.khaparde@broadcom.com
Cc: stable@dpdk.org

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

diff --git a/drivers/net/bnxt/bnxt_filter.c b/drivers/net/bnxt/bnxt_filter.c
index 7b90ba651f..f083f3aa94 100644
--- a/drivers/net/bnxt/bnxt_filter.c
+++ b/drivers/net/bnxt/bnxt_filter.c
@@ -3,14 +3,12 @@
  * All rights reserved.
  */
 
-#include <sys/queue.h>
-
 #include <rte_byteorder.h>
 #include <rte_log.h>
 #include <rte_malloc.h>
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
-#include <rte_tailq.h>
+#include <rte_queue.h>
 
 #include "bnxt.h"
 #include "bnxt_filter.h"
@@ -151,7 +149,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);
-- 
2.45.2


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

* Re: [RFC 4/7] net/bnxt: fix use after free
  2025-01-27 18:03 ` [RFC 4/7] net/bnxt: " Stephen Hemminger
@ 2025-01-27 19:25   ` Ajit Khaparde
  0 siblings, 0 replies; 8+ messages in thread
From: Ajit Khaparde @ 2025-01-27 19:25 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, stable, Somnath Kotur, Kalesh AP

[-- Attachment #1: Type: text/plain, Size: 1749 bytes --]

On Mon, Jan 27, 2025 at 10:08 AM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> 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")
> Cc: ajit.khaparde@broadcom.com
> Cc: stable@dpdk.org
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
> ---
>  drivers/net/bnxt/bnxt_filter.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/bnxt/bnxt_filter.c b/drivers/net/bnxt/bnxt_filter.c
> index 7b90ba651f..f083f3aa94 100644
> --- a/drivers/net/bnxt/bnxt_filter.c
> +++ b/drivers/net/bnxt/bnxt_filter.c
> @@ -3,14 +3,12 @@
>   * All rights reserved.
>   */
>
> -#include <sys/queue.h>
> -
>  #include <rte_byteorder.h>
>  #include <rte_log.h>
>  #include <rte_malloc.h>
>  #include <rte_flow.h>
>  #include <rte_flow_driver.h>
> -#include <rte_tailq.h>
> +#include <rte_queue.h>
>
>  #include "bnxt.h"
>  #include "bnxt_filter.h"
> @@ -151,7 +149,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);
> --
> 2.45.2
>

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4218 bytes --]

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

* [PATCH v2 2/7] net/qede: fix use after free
       [not found] ` <20250214172134.73908-1-stephen@networkplumber.org>
@ 2025-02-14 17:20   ` Stephen Hemminger
  2025-02-14 17:20   ` [PATCH v2 3/7] bus/fslmc: " Stephen Hemminger
  2025-02-14 17:20   ` [PATCH v2 4/7] net/bnxt: " Stephen Hemminger
  2 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2025-02-14 17:20 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_ethdev.h |  3 +--
 drivers/net/qede/qede_filter.c | 13 +++++--------
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/net/qede/qede_ethdev.h b/drivers/net/qede/qede_ethdev.h
index 3015c18504..b502658425 100644
--- a/drivers/net/qede/qede_ethdev.h
+++ b/drivers/net/qede/qede_ethdev.h
@@ -8,8 +8,7 @@
 #ifndef _QEDE_ETHDEV_H_
 #define _QEDE_ETHDEV_H_
 
-#include <sys/queue.h>
-
+#include <rte_queue.h>
 #include <rte_ether.h>
 #include <ethdev_driver.h>
 #include <ethdev_pci.h>
diff --git a/drivers/net/qede/qede_filter.c b/drivers/net/qede/qede_filter.c
index 14fb4338e9..c3f74c89d9 100644
--- a/drivers/net/qede/qede_filter.c
+++ b/drivers/net/qede/qede_filter.c
@@ -154,15 +154,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] 8+ messages in thread

* [PATCH v2 3/7] bus/fslmc: fix use after free
       [not found] ` <20250214172134.73908-1-stephen@networkplumber.org>
  2025-02-14 17:20   ` [PATCH v2 2/7] net/qede: " Stephen Hemminger
@ 2025-02-14 17:20   ` Stephen Hemminger
  2025-02-15 11:12     ` Hemant Agrawal
  2025-02-14 17:20   ` [PATCH v2 4/7] net/bnxt: " Stephen Hemminger
  2 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2025-02-14 17:20 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>
---
 drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
index 2dfcf7a498..6ae15c2054 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -15,7 +15,6 @@
 #include <signal.h>
 #include <pthread.h>
 #include <sys/types.h>
-#include <sys/queue.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
@@ -27,6 +26,7 @@
 #include <ethdev_driver.h>
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
+#include <rte_queue.h>
 #include <rte_string_fns.h>
 #include <rte_cycles.h>
 #include <rte_kvargs.h>
@@ -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) {
+	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] 8+ messages in thread

* [PATCH v2 4/7] net/bnxt: fix use after free
       [not found] ` <20250214172134.73908-1-stephen@networkplumber.org>
  2025-02-14 17:20   ` [PATCH v2 2/7] net/qede: " Stephen Hemminger
  2025-02-14 17:20   ` [PATCH v2 3/7] bus/fslmc: " Stephen Hemminger
@ 2025-02-14 17:20   ` Stephen Hemminger
  2 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2025-02-14 17:20 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, ajit.khaparde, stable, Somnath Kotur, Kalesh AP

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")
Cc: ajit.khaparde@broadcom.com
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_filter.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_filter.c b/drivers/net/bnxt/bnxt_filter.c
index 7b90ba651f..f083f3aa94 100644
--- a/drivers/net/bnxt/bnxt_filter.c
+++ b/drivers/net/bnxt/bnxt_filter.c
@@ -3,14 +3,12 @@
  * All rights reserved.
  */
 
-#include <sys/queue.h>
-
 #include <rte_byteorder.h>
 #include <rte_log.h>
 #include <rte_malloc.h>
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
-#include <rte_tailq.h>
+#include <rte_queue.h>
 
 #include "bnxt.h"
 #include "bnxt_filter.h"
@@ -151,7 +149,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);
-- 
2.47.2


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

* RE: [PATCH v2 3/7] bus/fslmc: fix use after free
  2025-02-14 17:20   ` [PATCH v2 3/7] bus/fslmc: " Stephen Hemminger
@ 2025-02-15 11:12     ` Hemant Agrawal
  0 siblings, 0 replies; 8+ messages in thread
From: Hemant Agrawal @ 2025-02-15 11:12 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: stable, Sachin Saxena

Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>

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

end of thread, other threads:[~2025-02-15 11:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20250127180842.97907-1-stephen@networkplumber.org>
2025-01-27 18:03 ` [RFC 2/7] net/qede: fix use after free Stephen Hemminger
2025-01-27 18:03 ` [RFC 3/7] bus/fslmc: " Stephen Hemminger
2025-01-27 18:03 ` [RFC 4/7] net/bnxt: " Stephen Hemminger
2025-01-27 19:25   ` Ajit Khaparde
     [not found] ` <20250214172134.73908-1-stephen@networkplumber.org>
2025-02-14 17:20   ` [PATCH v2 2/7] net/qede: " Stephen Hemminger
2025-02-14 17:20   ` [PATCH v2 3/7] bus/fslmc: " Stephen Hemminger
2025-02-15 11:12     ` Hemant Agrawal
2025-02-14 17:20   ` [PATCH v2 4/7] net/bnxt: " Stephen Hemminger

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).