* [PATCH] bus/fslmc: fix use after rte_free
@ 2024-12-18 17:05 Stephen Hemminger
[not found] ` <20241219225253.782792-1-stephen@networkplumber.org>
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2024-12-18 17:05 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, shreyansh.jain, stable, Hemant Agrawal, Sachin Saxena
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")
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 | 3 ++-
1 file changed, 2 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..fb7d1968d1 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -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);
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/5] bus/fslmc: fix use after rte_free
[not found] ` <20241219225253.782792-1-stephen@networkplumber.org>
@ 2024-12-19 22:49 ` Stephen Hemminger
2024-12-19 22:49 ` [PATCH v2 2/5] net/bnxt: fix use after free Stephen Hemminger
2024-12-19 22:49 ` [PATCH v2 4/5] net/qede: " Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2024-12-19 22:49 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 | 3 ++-
1 file changed, 2 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..fb7d1968d1 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c
@@ -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);
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/5] net/bnxt: fix use after free
[not found] ` <20241219225253.782792-1-stephen@networkplumber.org>
2024-12-19 22:49 ` [PATCH v2 1/5] " Stephen Hemminger
@ 2024-12-19 22:49 ` Stephen Hemminger
2024-12-19 22:49 ` [PATCH v2 4/5] net/qede: " Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2024-12-19 22:49 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 | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/net/bnxt/bnxt_filter.c b/drivers/net/bnxt/bnxt_filter.c
index 7b90ba651f..3804a5ec16 100644
--- a/drivers/net/bnxt/bnxt_filter.c
+++ b/drivers/net/bnxt/bnxt_filter.c
@@ -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);
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 4/5] net/qede: fix use after free
[not found] ` <20241219225253.782792-1-stephen@networkplumber.org>
2024-12-19 22:49 ` [PATCH v2 1/5] " Stephen Hemminger
2024-12-19 22:49 ` [PATCH v2 2/5] net/bnxt: fix use after free Stephen Hemminger
@ 2024-12-19 22:49 ` Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2024-12-19 22:49 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..5db36b03e2 100644
--- a/drivers/net/qede/qede_filter.c
+++ b/drivers/net/qede/qede_filter.c
@@ -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);
}
}
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-19 22:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-18 17:05 [PATCH] bus/fslmc: fix use after rte_free Stephen Hemminger
[not found] ` <20241219225253.782792-1-stephen@networkplumber.org>
2024-12-19 22:49 ` [PATCH v2 1/5] " Stephen Hemminger
2024-12-19 22:49 ` [PATCH v2 2/5] net/bnxt: fix use after free Stephen Hemminger
2024-12-19 22:49 ` [PATCH v2 4/5] net/qede: " 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).