netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow
@ 2008-06-16  9:15 Wang Chen
  2008-06-16  9:38 ` Patrick McHardy
  2008-06-16 15:05 ` v2: " Wang Chen
  0 siblings, 2 replies; 10+ messages in thread
From: Wang Chen @ 2008-06-16  9:15 UTC (permalink / raw)
  To: David S. Miller; +Cc: NETDEV

Max of promiscuity and allmulti plus positive @inc can cause overflow.
Fox example: when allmulti=0xFFFFFFFF, any caller give dev_set_allmulti() a
positive @inc will cause allmulti be off.
This is not what we want, though it's rare case.
The fix is that only negative @inc will cause allmulti or promiscuity be off
and when any caller will make the counters touch the roof, we report error.

Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com>
---
 net/core/dev.c |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 5829630..a3c692d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2753,10 +2753,20 @@ static void __dev_set_promiscuity(struct net_device *dev, int inc)
 
 	ASSERT_RTNL();
 
+	dev->flags |= IFF_PROMISC;
 	if ((dev->promiscuity += inc) == 0)
-		dev->flags &= ~IFF_PROMISC;
-	else
-		dev->flags |= IFF_PROMISC;
+		/*
+		 * Avoid overflow.
+		 * If inc causes overflow, ignore it and warn user.
+		 */
+		if (inc < 0)
+			dev->flags &= ~IFF_PROMISC;
+		else {
+			dev->promiscuity -= inc;
+			printk(KERN_ERR "%s: promiscuity touches roof, "
+				"set promiscuity failed, promiscuity feature "
+				"of device will be broken.\n");
+		}
 	if (dev->flags != old_flags) {
 		printk(KERN_INFO "device %s %s promiscuous mode\n",
 		       dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
@@ -2815,7 +2825,18 @@ void dev_set_allmulti(struct net_device *dev, int inc)
 
 	dev->flags |= IFF_ALLMULTI;
 	if ((dev->allmulti += inc) == 0)
-		dev->flags &= ~IFF_ALLMULTI;
+		/*
+		 * Avoid overflow.
+		 * If inc causes overflow, ignore it and warn user.
+		 */
+		if (inc < 0)
+			dev->flags &= ~IFF_ALLMULTI;
+		else {
+			dev->allmulti -= inc;
+			printk(KERN_ERR "%s: allmulti touches roof, "
+				"set allmulti failed, allmulti feature of "
+				"device will be broken.\n");
+		}
 	if (dev->flags ^ old_flags) {
 		if (dev->change_rx_flags)
 			dev->change_rx_flags(dev, IFF_ALLMULTI);
-- 
1.5.3.4





^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-06-18  8:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-16  9:15 RFC: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow Wang Chen
2008-06-16  9:38 ` Patrick McHardy
2008-06-16  9:51   ` Wang Chen
2008-06-16 10:04     ` Patrick McHardy
2008-06-16 15:05 ` v2: " Wang Chen
2008-06-17 12:59   ` Patrick McHardy
2008-06-18  1:51     ` Wang Chen
2008-06-18  4:54       ` David Miller
2008-06-18  8:44         ` Patrick McHardy
2008-06-18  8:49           ` David Miller

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).