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

This patch fix the loop iteration by not walking over the last
iteration. The cmpri compressing value exempt the last segment. As the
code shows the last iteration will be overwritten by cmpre value
handling which is for the last segment.

I think this doesn't end in any bufferoverflows because we work on worst
case temporary buffer sizes but it ends in not best compression settings
in some cases.

Fixes: 8610c7c6e3bd ("net: ipv6: add support for rpl sr exthdr")
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
Sorry, I should have caught this earlier and was sure I tested this code.
It's likely to have a off by one error because sometimes you want to walk
over all segments and sometimes you want to walk over all exempt the last
(because cmpri affects all segments exempt the last one).

 net/ipv6/rpl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/rpl.c b/net/ipv6/rpl.c
index dc4f20e23bf7..d38b476fc7f2 100644
--- a/net/ipv6/rpl.c
+++ b/net/ipv6/rpl.c
@@ -48,7 +48,7 @@ void ipv6_rpl_srh_decompress(struct ipv6_rpl_sr_hdr *outhdr,
 	outhdr->cmpri = 0;
 	outhdr->cmpre = 0;
 
-	for (i = 0; i <= n; i++)
+	for (i = 0; i < n; i++)
 		ipv6_rpl_addr_decompress(&outhdr->rpl_segaddr[i], daddr,
 					 ipv6_rpl_segdata_pos(inhdr, i),
 					 inhdr->cmpri);
@@ -66,7 +66,7 @@ static unsigned char ipv6_rpl_srh_calc_cmpri(const struct ipv6_rpl_sr_hdr *inhdr
 	int i;
 
 	for (plen = 0; plen < sizeof(*daddr); plen++) {
-		for (i = 0; i <= n; i++) {
+		for (i = 0; i < n; i++) {
 			if (daddr->s6_addr[plen] !=
 			    inhdr->rpl_segaddr[i].s6_addr[plen])
 				return plen;
@@ -114,7 +114,7 @@ void ipv6_rpl_srh_compress(struct ipv6_rpl_sr_hdr *outhdr,
 	outhdr->cmpri = cmpri;
 	outhdr->cmpre = cmpre;
 
-	for (i = 0; i <= n; i++)
+	for (i = 0; i < n; i++)
 		ipv6_rpl_addr_compress(ipv6_rpl_segdata_pos(outhdr, i),
 				       &inhdr->rpl_segaddr[i], cmpri);
 
-- 
2.20.1


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

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

From: Alexander Aring <alex.aring@gmail.com>
Date: Sat,  4 Apr 2020 11:22:57 -0400

> This patch fix the loop iteration by not walking over the last
> iteration. The cmpri compressing value exempt the last segment. As the
> code shows the last iteration will be overwritten by cmpre value
> handling which is for the last segment.
> 
> I think this doesn't end in any bufferoverflows because we work on worst
> case temporary buffer sizes but it ends in not best compression settings
> in some cases.
> 
> Fixes: 8610c7c6e3bd ("net: ipv6: add support for rpl sr exthdr")
> Signed-off-by: Alexander Aring <alex.aring@gmail.com>

Applied, thanks.

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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-04 15:22 [PATCH net] ipv6: rpl: fix loop iteration Alexander Aring
2020-04-06 17:06 ` 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).