All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] ipv6: rpl: fix full address compression
@ 2020-04-15 13:06 Alexander Aring
  2020-04-18 22:04 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Aring @ 2020-04-15 13:06 UTC (permalink / raw)
  To: davem; +Cc: kuznet, yoshfuji, kuba, mcr, stefan, netdev, Alexander Aring

This patch makes it impossible that cmpri or cmpre values are set to the
value 16 which is not possible, because these are 4 bit values. We
currently run in an overflow when assigning the value 16 to it.

According to the standard a value of 16 can be interpreted as a full
elided address which isn't possible to set as compression value. A reason
why this cannot be set is that the current ipv6 header destination address
should never show up inside the segments of the rpl header. In this case we
run in a overflow and the address will have no compression at all. Means
cmpri or compre is set to 0.

As we handle cmpri and cmpre sometimes as unsigned char or 4 bit value
inside the rpl header the current behaviour ends in an invalid header
format. This patch simple use the best compression method if we ever run
into the case that the destination address is showed up inside the rpl
segments. We avoid the overflow handling and the rpl header is still valid,
even when we have the destination address inside the rpl segments.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ipv6/rpl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/rpl.c b/net/ipv6/rpl.c
index d38b476fc7f2..307f336b5353 100644
--- a/net/ipv6/rpl.c
+++ b/net/ipv6/rpl.c
@@ -8,6 +8,7 @@
 #include <net/rpl.h>
 
 #define IPV6_PFXTAIL_LEN(x) (sizeof(struct in6_addr) - (x))
+#define IPV6_RPL_BEST_ADDR_COMPRESSION 15
 
 static void ipv6_rpl_addr_decompress(struct in6_addr *dst,
 				     const struct in6_addr *daddr,
@@ -73,7 +74,7 @@ static unsigned char ipv6_rpl_srh_calc_cmpri(const struct ipv6_rpl_sr_hdr *inhdr
 		}
 	}
 
-	return plen;
+	return IPV6_RPL_BEST_ADDR_COMPRESSION;
 }
 
 static unsigned char ipv6_rpl_srh_calc_cmpre(const struct in6_addr *daddr,
@@ -83,10 +84,10 @@ static unsigned char ipv6_rpl_srh_calc_cmpre(const struct in6_addr *daddr,
 
 	for (plen = 0; plen < sizeof(*daddr); plen++) {
 		if (daddr->s6_addr[plen] != last_segment->s6_addr[plen])
-			break;
+			return plen;
 	}
 
-	return plen;
+	return IPV6_RPL_BEST_ADDR_COMPRESSION;
 }
 
 void ipv6_rpl_srh_compress(struct ipv6_rpl_sr_hdr *outhdr,
-- 
2.20.1


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

* Re: [PATCH net] ipv6: rpl: fix full address compression
  2020-04-15 13:06 [PATCH net] ipv6: rpl: fix full address compression Alexander Aring
@ 2020-04-18 22:04 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-04-18 22:04 UTC (permalink / raw)
  To: alex.aring; +Cc: kuznet, yoshfuji, kuba, mcr, stefan, netdev

From: Alexander Aring <alex.aring@gmail.com>
Date: Wed, 15 Apr 2020 09:06:53 -0400

> This patch makes it impossible that cmpri or cmpre values are set to the
> value 16 which is not possible, because these are 4 bit values. We
> currently run in an overflow when assigning the value 16 to it.
> 
> According to the standard a value of 16 can be interpreted as a full
> elided address which isn't possible to set as compression value. A reason
> why this cannot be set is that the current ipv6 header destination address
> should never show up inside the segments of the rpl header. In this case we
> run in a overflow and the address will have no compression at all. Means
> cmpri or compre is set to 0.
> 
> As we handle cmpri and cmpre sometimes as unsigned char or 4 bit value
> inside the rpl header the current behaviour ends in an invalid header
> format. This patch simple use the best compression method if we ever run
> into the case that the destination address is showed up inside the rpl
> segments. We avoid the overflow handling and the rpl header is still valid,
> even when we have the destination address inside the rpl segments.
> 
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>

Applied, thank you.

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

end of thread, other threads:[~2020-04-18 22:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 13:06 [PATCH net] ipv6: rpl: fix full address compression Alexander Aring
2020-04-18 22:04 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.