Skip to contentSkip to conversation

RFC: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow

PATCH Applied Wang Chen 3 participants 10 messages Jun 16, 2008 – Jun 18, 2008

Subsystems (2)
lore
Share & tools
lore

Wang Chen

author
#0 lore raw

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.

---
 net/core/dev.c |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)
net/core/dev.c +25 -4
index 5829630..a3c692d 100644
@@ -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);
Signature · 1 line
1.5.3.4
#1 lore raw
Quoted 15 lines · Wang Chen
net/core/dev.c +3 -3
index 5829630..a3c692d 100644
@@ -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.

net/core/dev.c static void __dev_set_promiscuity(struct net_device *dev, int inc) · line 2769

Quoted 10 lines
net/core/dev.c +10 -0
+		 * 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");
+		}

Additional parens around the inner block would make this more readable.

I question the need for this though, userspace can only trigger an increase/decrease by one no matter how often it enables the ALLMULTI/PROMISC flags, and I doubt any codepath in the kernel would lead to an overflow.

If this can really happen it would be better to leave the counter untouched and return an error, we already have too many device operations that might fail more or less silently.

author
#2 lore raw

Patrick McHardy said the following on 2008-6-16 17:38:

Quoted 22 lines
Quoted 21 lines · Wang Chen
net/core/dev.c +8 -3
index 5829630..a3c692d 100644
@@ -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 {
Quoted 9 lines

net/core/dev.c static void __dev_set_promiscuity(struct net_device *dev, int inc) · line 2769

Quoted 5 lines
net/core/dev.c +5 -0
+            dev->promiscuity -= inc;
+            printk(KERN_ERR "%s: promiscuity touches roof, "
+                "set promiscuity failed, promiscuity feature "
+                "of device will be broken.\n");
+        }

Additional parens around the inner block would make this more readable.

Will fix.

Quoted 5 lines

I question the need for this though, userspace can only trigger an increase/decrease by one no matter how often it enables the ALLMULTI/PROMISC flags, and I doubt any codepath in the kernel would lead to an overflow.

How about mif6_add()?
Do we have a limit for mif6?

Quoted 4 lines

If this can really happen it would be better to leave the counter untouched and return an error, we already have too many device operations that might fail more or less silently.

This can be done.

#3 lore raw
Quoted 10 lines · Wang Chen

Patrick McHardy said the following on 2008-6-16 17:38:

Quoted 6 lines

I question the need for this though, userspace can only trigger an increase/decrease by one no matter how often it enables the ALLMULTI/PROMISC flags, and I doubt any codepath in the kernel would lead to an overflow.

How about mif6_add()?
Do we have a limit for mif6?

No, so I guess your patch makes sense.

Quoted 6 lines
Quoted 4 lines

If this can really happen it would be better to leave the counter untouched and return an error, we already have too many device operations that might fail more or less silently.

This can be done.

Thanks.

author
#4 lore raw

v2: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow

In reply to Wang Chen

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 makes the counters touch the roof, we return error.

Change of v2:
Change void function dev_set_promiscuity/allmulti to return int. So callers can get the overflow error.
Caller's fix will be done later.

---
 include/linux/netdevice.h |    4 +-
 net/core/dev.c            |   54 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 46 insertions(+), 12 deletions(-)
include/linux/netdevice.h +2 -2
index f27fd20..f2ab98e 100644
@@ -1476,8 +1476,8 @@ extern int 		__dev_addr_delete(struct dev_addr_list **list, int *count, void *ad
 extern int		__dev_addr_add(struct dev_addr_list **list, int *count, void *addr, int alen, int newonly);
 extern int		__dev_addr_sync(struct dev_addr_list **to, int *to_count, struct dev_addr_list **from, int *from_count);
 extern void		__dev_addr_unsync(struct dev_addr_list **to, int *to_count, struct dev_addr_list **from, int *from_count);
-extern void		dev_set_promiscuity(struct net_device *dev, int inc);
-extern void		dev_set_allmulti(struct net_device *dev, int inc);
+extern int		dev_set_promiscuity(struct net_device *dev, int inc);
+extern int		dev_set_allmulti(struct net_device *dev, int inc);
 extern void		netdev_state_change(struct net_device *dev);
 extern void		netdev_features_change(struct net_device *dev);
 /* Load a device via the kmod */
net/core/dev.c +44 -10

102 lines not on this page · raw message

Signature · 1 line
1.5.3.4
#5 lore raw

Re: v2: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow

Quoted 5 lines · Wang Chen
net/core/dev.c +5 -0
+	if (dev->promiscuity == 0) {
+		/*
+		 * Avoid overflow.
+		 * If inc causes overflow, untouch promisc and return error.
+		 */

net/core/dev.c int netdev_set_master(struct net_device *slave, struct net_device *master) · line 2772

Quoted 10 lines
net/core/dev.c +10 -0
+		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", dev->name);
+			return -EOVERFLOW;
+		}
+	}

Assuming the caller does proper error handling, that printk is not true.

author
#6 lore raw

Re: v2: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow

Patrick McHardy said the following on 2008-6-17 20:59:

Quoted 10 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+            printk(KERN_ERR "%s: promiscuity touches roof, "
+                "set promiscuity failed, promiscuity feature "
+                "of device will be broken.\n", dev->name);
+            return -EOVERFLOW;
+        }
+    }

Assuming the caller does proper error handling, that printk is not true.

Yes.
But currently, no caller handling this, and I think even if I make some callers to handle this, but there maybe some callers and their callers do not want to handle error condition.
So I need a KERN_WARNING here.
If some day, all of the caller handle the error properly, we can remove this printk.

Here is v3:

---
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 makes the counters touch the roof, we return error.

Change of v2:
Change void function dev_set_promiscuity/allmulti to return int. So callers can get the overflow error.
Caller's fix will be done later.

Change of v3:
1. Since we return error to caller, we don't need to print KERN_ERROR, KERN_WARNING is enough.
2. In dev_set_promiscuity(), if __dev_set_promiscuity() failed, we return at once.

---
 include/linux/netdevice.h |    4 +-
 net/core/dev.c            |   55 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 47 insertions(+), 12 deletions(-)
include/linux/netdevice.h +2 -2
index f27fd20..f2ab98e 100644
@@ -1476,8 +1476,8 @@ extern int 		__dev_addr_delete(struct dev_addr_list **list, int *count, void *ad
 extern int		__dev_addr_add(struct dev_addr_list **list, int *count, void *addr, int alen, int newonly);
 extern int		__dev_addr_sync(struct dev_addr_list **to, int *to_count, struct dev_addr_list **from, int *from_count);
 extern void		__dev_addr_unsync(struct dev_addr_list **to, int *to_count, struct dev_addr_list **from, int *from_count);
-extern void		dev_set_promiscuity(struct net_device *dev, int inc);
-extern void		dev_set_allmulti(struct net_device *dev, int inc);
+extern int		dev_set_promiscuity(struct net_device *dev, int inc);
+extern int		dev_set_allmulti(struct net_device *dev, int inc);
 extern void		netdev_state_change(struct net_device *dev);
 extern void		netdev_features_change(struct net_device *dev);
 /* Load a device via the kmod */
net/core/dev.c +45 -10

103 lines not on this page · raw message

Signature · 1 line
1.5.3.4
maintainer
#7 lore raw

Re: v2: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow

From: Wang Chen <[email protected]>
Date: Wed, 18 Jun 2008 09:51:00 +0800

Quoted 20 lines

Patrick McHardy said the following on 2008-6-17 20:59:

Quoted 10 lines

net/core/dev.c int netdev_set_master(struct net_device *slave, struct net_device *master) · line 2772

Quoted 6 lines
net/core/dev.c +6 -0
+            printk(KERN_ERR "%s: promiscuity touches roof, "
+                "set promiscuity failed, promiscuity feature "
+                "of device will be broken.\n", dev->name);
+            return -EOVERFLOW;
+        }
+    }

Assuming the caller does proper error handling, that printk is not true.

Yes.
But currently, no caller handling this, and I think even if I make some callers to handle this, but there maybe some callers and their callers do not want to handle error condition.
So I need a KERN_WARNING here.
If some day, all of the caller handle the error properly, we can remove this printk.

Quoted 1 line

Here is v3:

Patrick, ACK?

#8 lore raw

Re: v2: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow

Quoted 13 lines · David Miller

From: Wang Chen <[email protected]>
Date: Wed, 18 Jun 2008 09:51:00 +0800

Quoted 11 lines

Patrick McHardy said the following on 2008-6-17 20:59:

Quoted 2 lines

Assuming the caller does proper error handling, that printk is not true.

Yes.
But currently, no caller handling this, and I think even if I make some callers to handle this, but there maybe some callers and their callers do not want to handle error condition.
So I need a KERN_WARNING here.
If some day, all of the caller handle the error properly, we can remove this printk.

Quoted 3 lines
Quoted 1 line

Here is v3:

Patrick, ACK?

Yes, thanks.

maintainer Applied
#9 lore raw

Re: v2: [PATCH 2/3] netdevice: Fix promiscuity and allmulti overflow

From: Patrick McHardy <[email protected]>
Date: Wed, 18 Jun 2008 10:44:10 +0200

Quoted 14 lines
Quoted 13 lines · David Miller

From: Wang Chen <[email protected]>
Date: Wed, 18 Jun 2008 09:51:00 +0800

Quoted 11 lines

Patrick McHardy said the following on 2008-6-17 20:59:

Quoted 2 lines

Assuming the caller does proper error handling, that printk is not true.

Yes.
But currently, no caller handling this, and I think even if I make some callers to handle this, but there maybe some callers and their callers do not want to handle error condition.
So I need a KERN_WARNING here.
If some day, all of the caller handle the error properly, we can remove this printk.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Here is v3:

Patrick, ACK?

Yes, thanks.

Thanks, applied to net-next-2.6, I'll push to kernel.org after some build sanity checks.

Since this is a bug fix we could put it into net-2.6, but I really would like this to brew for a while in net-next-2.6 before doing so.