Skip to content

Commit ebecb36

Browse files
committed
net/nfp: fix use after free
The code to cleanup metering was using the objects after calling rte_free(). Fix by using LISTFOREACH_SAFE Fixes: 2caf84a ("net/nfp: add meter options") Cc: [email protected] Cc: [email protected] Signed-off-by: Stephen Hemminger <[email protected]>
1 parent a0a1368 commit ebecb36

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/net/nfp/nfp_mtr.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
#include "flower/nfp_flower_representor.h"
1313
#include "nfp_logs.h"
1414

15+
#ifndef LIST_FOREACH_SAFE
16+
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
17+
for ((var) = LIST_FIRST((head)); \
18+
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
19+
(var) = (tvar))
20+
#endif
21+
1522
#define NFP_MAX_POLICY_CNT NFP_MAX_MTR_CNT
1623
#define NFP_MAX_PROFILE_CNT NFP_MAX_MTR_CNT
1724

@@ -1124,28 +1131,28 @@ nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev)
11241131
void
11251132
nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev)
11261133
{
1127-
struct nfp_mtr *mtr;
1134+
struct nfp_mtr *mtr, *tmp_mtr;
11281135
struct nfp_mtr_priv *priv;
1129-
struct nfp_mtr_policy *mtr_policy;
1130-
struct nfp_mtr_profile *mtr_profile;
1136+
struct nfp_mtr_policy *mtr_policy, *tmp_policy;
1137+
struct nfp_mtr_profile *mtr_profile, *tmp_profile;
11311138
struct nfp_app_fw_flower *app_fw_flower;
11321139

11331140
app_fw_flower = NFP_PRIV_TO_APP_FW_FLOWER(pf_dev->app_fw_priv);
11341141
priv = app_fw_flower->mtr_priv;
11351142

11361143
rte_eal_alarm_cancel(nfp_mtr_stats_request, (void *)app_fw_flower);
11371144

1138-
LIST_FOREACH(mtr, &priv->mtrs, next) {
1145+
LIST_FOREACH_SAFE(mtr, &priv->mtrs, next, tmp_mtr) {
11391146
LIST_REMOVE(mtr, next);
11401147
rte_free(mtr);
11411148
}
11421149

1143-
LIST_FOREACH(mtr_profile, &priv->profiles, next) {
1150+
LIST_FOREACH_SAFE(mtr_profile, &priv->profiles, next, tmp_profile) {
11441151
LIST_REMOVE(mtr_profile, next);
11451152
rte_free(mtr_profile);
11461153
}
11471154

1148-
LIST_FOREACH(mtr_policy, &priv->policies, next) {
1155+
LIST_FOREACH_SAFE(mtr_policy, &priv->policies, next, tmp_policy) {
11491156
LIST_REMOVE(mtr_policy, next);
11501157
rte_free(mtr_policy);
11511158
}

0 commit comments

Comments
 (0)