Skip to content

Commit a0a1368

Browse files
committed
net/netvsc: fix use after free in cache list cleanup
The variable cache is referred to by LIST_FOREACH macro after was freed. Replace by the standard LIST_FOREACH_SAFE from BSD (and other drivers). Fixes: 9a9d038 ("net/netvsc: cache device parameters for hotplug events") Cc: [email protected] Acked-by: Long Li <[email protected]> Signed-off-by: Stephen Hemminger <[email protected]>
1 parent 0f711f9 commit a0a1368

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/net/netvsc/hn_ethdev.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
#include "hn_nvs.h"
4242
#include "ndis.h"
4343

44+
#ifndef LIST_FOREACH_SAFE
45+
#define LIST_FOREACH_SAFE(var, head, field, tvar) \
46+
for ((var) = LIST_FIRST((head)); \
47+
(var) && ((tvar) = LIST_NEXT((var), field), 1); \
48+
(var) = (tvar))
49+
#endif
50+
4451
#define HN_TX_OFFLOAD_CAPS (RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | \
4552
RTE_ETH_TX_OFFLOAD_TCP_CKSUM | \
4653
RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \
@@ -1479,14 +1486,14 @@ static int populate_cache_list(void)
14791486

14801487
static void remove_cache_list(void)
14811488
{
1482-
struct da_cache *cache;
1489+
struct da_cache *cache, *tmp;
14831490

14841491
rte_spinlock_lock(&netvsc_lock);
14851492
da_cache_usage--;
14861493
if (da_cache_usage)
14871494
goto out;
14881495

1489-
LIST_FOREACH(cache, &da_cache_list, list) {
1496+
LIST_FOREACH_SAFE(cache, &da_cache_list, list, tmp) {
14901497
LIST_REMOVE(cache, list);
14911498
free(cache);
14921499
}

0 commit comments

Comments
 (0)