diff mbox series

[v2] net: fix IPv6 prefix route residue

Message ID 131bd64c-1484-39c3-d813-dde47ff4198c@huawei.com
State Accepted
Delegated to: David Miller
Headers show
Series [v2] net: fix IPv6 prefix route residue | expand

Commit Message

Zhiqiang Liu Feb. 11, 2019, 2:57 a.m. UTC
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>

Follow those steps:
 # ip addr add 2001:123::1/32 dev eth0
 # ip addr add 2001:123:456::2/64 dev eth0
 # ip addr del 2001:123::1/32 dev eth0
 # ip addr del 2001:123:456::2/64 dev eth0
and then prefix route of 2001:123::1/32 will still exist.

This is because ipv6_prefix_equal in check_cleanup_prefix_route
func does not check whether two IPv6 addresses have the same
prefix length. If the prefix of one address starts with another
shorter address prefix, even though their prefix lengths are
different, the return value of ipv6_prefix_equal is true.

Here I add a check of whether two addresses have the same prefix
to decide whether their prefixes are equal.

Fixes: 5b84efecb7d9 ("ipv6 addrconf: don't cleanup prefix route
for IFA_F_NOPREFIXROUTE")
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Reported-by: Wenhao Zhang <zhangwenhao8@huawei.com>
---
V1->V2:
- fix the indentation of the condition
- add Fixes tag

 net/ipv6/addrconf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Miller Feb. 12, 2019, 4:38 a.m. UTC | #1
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Date: Mon, 11 Feb 2019 10:57:46 +0800

> From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> 
> Follow those steps:
>  # ip addr add 2001:123::1/32 dev eth0
>  # ip addr add 2001:123:456::2/64 dev eth0
>  # ip addr del 2001:123::1/32 dev eth0
>  # ip addr del 2001:123:456::2/64 dev eth0
> and then prefix route of 2001:123::1/32 will still exist.
> 
> This is because ipv6_prefix_equal in check_cleanup_prefix_route
> func does not check whether two IPv6 addresses have the same
> prefix length. If the prefix of one address starts with another
> shorter address prefix, even though their prefix lengths are
> different, the return value of ipv6_prefix_equal is true.
> 
> Here I add a check of whether two addresses have the same prefix
> to decide whether their prefixes are equal.
> 
> Fixes: 5b84efecb7d9 ("ipv6 addrconf: don't cleanup prefix route
> for IFA_F_NOPREFIXROUTE")
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> Reported-by: Wenhao Zhang <zhangwenhao8@huawei.com>

Applied and queued up for -stable.

Please do not split up long Fixes: tag lines, keep the entire tag on
one line only.

I fixed it up for you this time.

Thanks.
Zhiqiang Liu Feb. 12, 2019, 7:43 a.m. UTC | #2
> From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> Date: Mon, 11 Feb 2019 10:57:46 +0800
> 
>> From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>>
>> Follow those steps:
>>  # ip addr add 2001:123::1/32 dev eth0
>>  # ip addr add 2001:123:456::2/64 dev eth0
>>  # ip addr del 2001:123::1/32 dev eth0
>>  # ip addr del 2001:123:456::2/64 dev eth0
>> and then prefix route of 2001:123::1/32 will still exist.
>>
>> This is because ipv6_prefix_equal in check_cleanup_prefix_route
>> func does not check whether two IPv6 addresses have the same
>> prefix length. If the prefix of one address starts with another
>> shorter address prefix, even though their prefix lengths are
>> different, the return value of ipv6_prefix_equal is true.
>>
>> Here I add a check of whether two addresses have the same prefix
>> to decide whether their prefixes are equal.
>>
>> Fixes: 5b84efecb7d9 ("ipv6 addrconf: don't cleanup prefix route
>> for IFA_F_NOPREFIXROUTE")
>> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>> Reported-by: Wenhao Zhang <zhangwenhao8@huawei.com>
> 
> Applied and queued up for -stable.Thank you for applying the patch.
> 
> Please do not split up long Fixes: tag lines, keep the entire tag on
> one line only.
> 
> I fixed it up for you this time.
> 
> Thanks.
This is the first patch in my life. Thank you and David Ahern again.
diff mbox series

Patch

diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 84c3588..72ffd3d 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -1165,7 +1165,8 @@  enum cleanup_prefix_rt_t {
 	list_for_each_entry(ifa, &idev->addr_list, if_list) {
 		if (ifa == ifp)
 			continue;
-		if (!ipv6_prefix_equal(&ifa->addr, &ifp->addr,
+		if (ifa->prefix_len != ifp->prefix_len ||
+		    !ipv6_prefix_equal(&ifa->addr, &ifp->addr,
 				       ifp->prefix_len))
 			continue;
 		if (ifa->flags & (IFA_F_PERMANENT | IFA_F_NOPREFIXROUTE))