* [PATCH] net/nfp: fix use after free
@ 2025-11-04 5:29 Stephen Hemminger
0 siblings, 0 replies; only message in thread
From: Stephen Hemminger @ 2025-11-04 5:29 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, jin.liu, stable, Chaoyong He,
Niklas Söderlund, Peng Zhang
The code to cleanup metering was using the objects after calling
rte_free(). Fix by using LISTFOREACH_SAFE
Fixes: 2caf84a71cfd ("net/nfp: add meter options")
Cc: jin.liu@corigine.com
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/net/nfp/nfp_mtr.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/net/nfp/nfp_mtr.c b/drivers/net/nfp/nfp_mtr.c
index d4f2c4f2f0..4833ebd881 100644
--- a/drivers/net/nfp/nfp_mtr.c
+++ b/drivers/net/nfp/nfp_mtr.c
@@ -12,6 +12,13 @@
#include "flower/nfp_flower_representor.h"
#include "nfp_logs.h"
+#ifndef LIST_FOREACH_SAFE
+#define LIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = LIST_FIRST((head)); \
+ (var) && ((tvar) = LIST_NEXT((var), field), 1); \
+ (var) = (tvar))
+#endif
+
#define NFP_MAX_POLICY_CNT NFP_MAX_MTR_CNT
#define NFP_MAX_PROFILE_CNT NFP_MAX_MTR_CNT
@@ -1124,10 +1131,10 @@ nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev)
void
nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev)
{
- struct nfp_mtr *mtr;
+ struct nfp_mtr *mtr, *tmp_mtr;
struct nfp_mtr_priv *priv;
- struct nfp_mtr_policy *mtr_policy;
- struct nfp_mtr_profile *mtr_profile;
+ struct nfp_mtr_policy *mtr_policy, *tmp_policy;
+ struct nfp_mtr_profile *mtr_profile, *tmp_profile;
struct nfp_app_fw_flower *app_fw_flower;
app_fw_flower = NFP_PRIV_TO_APP_FW_FLOWER(pf_dev->app_fw_priv);
@@ -1135,17 +1142,17 @@ nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev)
rte_eal_alarm_cancel(nfp_mtr_stats_request, (void *)app_fw_flower);
- LIST_FOREACH(mtr, &priv->mtrs, next) {
+ LIST_FOREACH_SAFE(mtr, &priv->mtrs, next, tmp_mtr) {
LIST_REMOVE(mtr, next);
rte_free(mtr);
}
- LIST_FOREACH(mtr_profile, &priv->profiles, next) {
+ LIST_FOREACH_SAFE(mtr_profile, &priv->profiles, next, tmp_profile) {
LIST_REMOVE(mtr_profile, next);
rte_free(mtr_profile);
}
- LIST_FOREACH(mtr_policy, &priv->policies, next) {
+ LIST_FOREACH_SAFE(mtr_policy, &priv->policies, next, tmp_policy) {
LIST_REMOVE(mtr_policy, next);
rte_free(mtr_policy);
}
--
2.51.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-11-04 5:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-04 5:29 [PATCH] net/nfp: fix use after free 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).