Skip to contentSkip to conversation

ipv6: fix the bug of address check

PATCH In review Shan Wei 3 participants 5 messages May 17, 2010 – May 18, 2010

Subsystems (3)
lore
Share & tools
lore

Shan Wei

author
#0 lore raw

PATCH 1/1 ipv6: fix the bug of address check

If there are several IPv6 addresses with same hash value in hashlist, and they are all not matched with addr argument.
In this case, ipv6_chk_addr() should return 0.

This bug is introduced by commit c2e21293c054817c42eb5fa9c613d2ad51954136 (title: ipv6: convert addrconf list to hlist).

---
 net/ipv6/addrconf.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/ipv6/addrconf.c +1 -1
index 3984f52..d8e5907 100644
@@ -1291,7 +1291,7 @@ int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
 	}
 	rcu_read_unlock_bh();
 
-	return ifp != NULL;
+	return node != NULL;
 }
 EXPORT_SYMBOL(ipv6_chk_addr);
 
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 18 lines · On Mon, 17 May 2010 20:23:38 +0800 Shan Wei <[email protected]> wrote:

If there are several IPv6 addresses with same hash value in hashlist, and they are all not matched with addr argument.
In this case, ipv6_chk_addr() should return 0.

This bug is introduced by commit c2e21293c054817c42eb5fa9c613d2ad51954136 (title: ipv6: convert addrconf list to hlist).

---
 net/ipv6/addrconf.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/ipv6/addrconf.c +0 -0
index 3984f52..d8e5907 100644

net/ipv6/addrconf.c int ipv6_chk_addr(struct net *net, struct in6_addr *addr, · line 1297

Quoted 8 lines
net/ipv6/addrconf.c +1 -1
@@ -1291,7 +1291,7 @@ int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
 	}
 	rcu_read_unlock_bh();
 
-	return ifp != NULL;
+	return node != NULL;
 }
 EXPORT_SYMBOL(ipv6_chk_addr);
 

Why not this instead. I don't like depending on the value of the loop variable in the hlist_for_each()

net/ipv6/addrconf.c +8 -7
@@ -1274,7 +1274,7 @@ static int ipv6_count_addresses(struct i
 int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
 		  struct net_device *dev, int strict)
 {
-	struct inet6_ifaddr *ifp = NULL;
+	struct inet6_ifaddr *ifp;
 	struct hlist_node *node;
 	unsigned int hash = ipv6_addr_hash(addr);
 
@@ -1283,15 +1283,16 @@ int ipv6_chk_addr(struct net *net, struc
 		if (!net_eq(dev_net(ifp->idev->dev), net))
 			continue;
 		if (ipv6_addr_equal(&ifp->addr, addr) &&
-		    !(ifp->flags&IFA_F_TENTATIVE)) {
-			if (dev == NULL || ifp->idev->dev == dev ||
-			    !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))
-				break;
+		    !(ifp->flags&IFA_F_TENTATIVE) &&
+		    (dev == NULL || ifp->idev->dev == dev ||
+		     !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
+			rcu_read_unlock_bh();
+			return 1;
 		}
 	}
-	rcu_read_unlock_bh();
 
-	return ifp != NULL;
+	rcu_read_unlock_bh();
+	return 0;
 }
 EXPORT_SYMBOL(ipv6_chk_addr);
 
author
#2 lore raw

Stephen Hemminger wrote, at 05/18/2010 01:31 AM:

Quoted 30 lines

Why not this instead. I don't like depending on the value of the loop variable in the hlist_for_each()

net/ipv6/addrconf.c +6 -5
@@ -1274,7 +1274,7 @@ static int ipv6_count_addresses(struct i
 int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
 		  struct net_device *dev, int strict)
 {
-	struct inet6_ifaddr *ifp = NULL;
+	struct inet6_ifaddr *ifp;
 	struct hlist_node *node;
 	unsigned int hash = ipv6_addr_hash(addr);
 
@@ -1283,15 +1283,16 @@ int ipv6_chk_addr(struct net *net, struc
 		if (!net_eq(dev_net(ifp->idev->dev), net))
 			continue;
 		if (ipv6_addr_equal(&ifp->addr, addr) &&
-		    !(ifp->flags&IFA_F_TENTATIVE)) {
-			if (dev == NULL || ifp->idev->dev == dev ||
-			    !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))
-				break;
+		    !(ifp->flags&IFA_F_TENTATIVE) &&
+		    (dev == NULL || ifp->idev->dev == dev ||
+		     !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
+			rcu_read_unlock_bh();
+			return 1;

net/ipv6/addrconf.c int ipv6_chk_addr(struct net *net, struc · line 1298

Quoted 10 lines
net/ipv6/addrconf.c +2 -2
 		}
 	}
-	rcu_read_unlock_bh();
 
-	return ifp != NULL;
+	rcu_read_unlock_bh();
+	return 0;
 }
 EXPORT_SYMBOL(ipv6_chk_addr);
 

This looks good to me.
Can you send a intact patch to David with my Report-by or Review-by ?

Signature · 3 lines
Best Regards
-----
Shan Wei
#3 lore raw

PATCH 1/1 ipv6: fix the bug of address check

The duplicate address check code got broken in the conversion to hlist (2.6.35). The earlier patch did not fix the case where two addresses match same hash value. Use two exit paths, rather than depending on state of loop variables (from macro).

Based on earlier fix by Shan Wei.

net/ipv6/addrconf.c +8 -7
@@ -1274,7 +1274,7 @@ static int ipv6_count_addresses(struct i
 int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
 		  struct net_device *dev, int strict)
 {
-	struct inet6_ifaddr *ifp = NULL;
+	struct inet6_ifaddr *ifp;
 	struct hlist_node *node;
 	unsigned int hash = ipv6_addr_hash(addr);
 
@@ -1283,15 +1283,16 @@ int ipv6_chk_addr(struct net *net, struc
 		if (!net_eq(dev_net(ifp->idev->dev), net))
 			continue;
 		if (ipv6_addr_equal(&ifp->addr, addr) &&
-		    !(ifp->flags&IFA_F_TENTATIVE)) {
-			if (dev == NULL || ifp->idev->dev == dev ||
-			    !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))
-				break;
+		    !(ifp->flags&IFA_F_TENTATIVE) &&
+		    (dev == NULL || ifp->idev->dev == dev ||
+		     !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
+			rcu_read_unlock_bh();
+			return 1;
 		}
 	}
-	rcu_read_unlock_bh();
 
-	return ifp != NULL;
+	rcu_read_unlock_bh();
+	return 0;
 }
 EXPORT_SYMBOL(ipv6_chk_addr);
 
maintainer Applied
#4 lore raw

From: Stephen Hemminger <[email protected]>
Date: Mon, 17 May 2010 18:02:21 -0700

Quoted 9 lines

The duplicate address check code got broken in the conversion to hlist (2.6.35). The earlier patch did not fix the case where two addresses match same hash value. Use two exit paths, rather than depending on state of loop variables (from macro).

Based on earlier fix by Shan Wei.

Applied, thanks everyone.