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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Joe Perches
Date: Friday, November 9, 2007 - 5:08 pm

On Sat, 2007-11-10 at 00:12 +0100, Patrick McHardy wrote:

How about a comment then?  Perhaps:

diff --git a/net/core/dev_mcast.c b/net/core/dev_mcast.c
index ae35405..63576aa 100644
--- a/net/core/dev_mcast.c
+++ b/net/core/dev_mcast.c
@@ -165,16 +165,23 @@ void dev_mc_unsync(struct net_device *to, struct net_device *from)
 	netif_tx_lock_bh(from);
 	netif_tx_lock_bh(to);
 
+	/*
+	  This while loop can't be written as
+		for (da = from->mc_list; da; da = da->next)
+	  da = from->mc_list and __dev_addr_delete can kfree(from->mc_list)
+	  which could cause a use-after-free of da->next
+	*/
+
 	da = from->mc_list;
 	while (da != NULL) {
 		next = da->next;
-		if (!da->da_synced)
-			continue;
-		__dev_addr_delete(&to->mc_list, &to->mc_count,
-				  da->da_addr, da->da_addrlen, 0);
-		da->da_synced = 0;
-		__dev_addr_delete(&from->mc_list, &from->mc_count,
-				  da->da_addr, da->da_addrlen, 0);
+		if (da->da_synced) {
+			__dev_addr_delete(&to->mc_list, &to->mc_count,
+					  da->da_addr, da->da_addrlen, 0);
+			da->da_synced = 0;
+			__dev_addr_delete(&from->mc_list, &from->mc_count,
+					  da->da_addr, da->da_addrlen, 0);
+		}
 		da = next;
 	}
 	__dev_set_rx_mode(to);


-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Fix infinite loop on dev_mc_unsync(), Luis R. Rodriguez, (Fri Nov 9, 8:11 am)
Re: [PATCH] Fix infinite loop on dev_mc_unsync(), Luis R. Rodriguez, (Fri Nov 9, 11:51 am)
Re: [PATCH] Fix infinite loop on dev_mc_unsync(), Joe Perches, (Fri Nov 9, 12:07 pm)
Re: [PATCH] Fix infinite loop on dev_mc_unsync(), Luis R. Rodriguez, (Fri Nov 9, 12:21 pm)
Re: [PATCH] Fix infinite loop on dev_mc_unsync(), Patrick McHardy, (Fri Nov 9, 4:12 pm)
Re: [PATCH] Fix infinite loop on dev_mc_unsync(), Joe Perches, (Fri Nov 9, 5:08 pm)
Re: [PATCH] Fix infinite loop on dev_mc_unsync(), Patrick McHardy, (Fri Nov 9, 5:13 pm)
Re: [PATCH] Fix infinite loop on dev_mc_unsync(), David Miller, (Sat Nov 10, 10:34 pm)