Subject: Re: [PATCH] Fix infinite loop on dev_mc_unsync()

From: Patrick McHardy <[email-masked]>
Date: Sat, 10 Nov 2007 00:12:34 +0100

Luis R. Rodriguez wrote:
> diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
> index 15241cf..2aea8e1 100644
> --- a/net/core/dev_mcast.c
> +++ b/net/core/dev_mcast.c
> @@ -160,14 +160,12 @@ EXPORT_SYMBOL(dev_mc_sync);
>   */
>  void dev_mc_unsync(struct net_device *to, struct net_device *from)
>  {
> -	struct dev_addr_list *da, *next;
> +	struct dev_addr_list *da;
>  
>  	netif_tx_lock_bh(from);
>  	netif_tx_lock_bh(to);
>  
> -	da = from->mc_list;
> -	while (da != NULL) {
> -		next = da->next;
> +	for (da = from->mc_list; da; da = da->next) {
>   

This may cause a use-after-free since __dev_addr_delete frees the address
when all references are gone.

>  		if (!da->da_synced)
>  			continue;
>  		__dev_addr_delete(&to->mc_list, &to->mc_count,
> @@ -175,7 +173,6 @@ void dev_mc_unsync(struct net_device *to, struct net_device *from)
>  		da->da_synced = 0;
>  		__dev_addr_delete(&from->mc_list, &from->mc_count,
>  				  da->da_addr, da->da_addrlen, 0);
> -		da = next;
>  	}
>