Skip to contentSkip to conversation

6lowpan: Off by one handling ->nexthdr

PATCH In review Dan Carpenter 4 participants 4 messages Apr 3, 2019 – Apr 23, 2019

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 6lowpan: Off by one handling ->nexthdr

NEXTHDR_MAX is 255. What happens here is that we take a u8 value "hdr->nexthdr" from the network and then look it up in lowpan_nexthdr_nhcs[]. The problem is that if hdr->nexthdr is 0xff then we read one element beyond the end of the array so the array needs to be one element larger.

Fixes 92aa7c65d295 ("6lowpan: add generic nhc layer interface")

---
This is the only place which uses the NEXTHDR_MAX define, so I considered changing that to 256 instead. Either fix would work.

 net/6lowpan/nhc.c  | 2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/6lowpan/nhc.c +1 -1
index 4fa2fdda174d..9e56fb98f33c 100644
@@ -18,7 +18,7 @@
 #include "nhc.h"
 
 static struct rb_root rb_root = RB_ROOT;
-static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
+static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX + 1];
 static DEFINE_SPINLOCK(lowpan_nhc_lock);
 
 static int lowpan_nhc_insert(struct lowpan_nhc *nhc)
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw

Hi Dan,

Quoted 22 lines · Dan Carpenter

NEXTHDR_MAX is 255. What happens here is that we take a u8 value "hdr->nexthdr" from the network and then look it up in lowpan_nexthdr_nhcs[]. The problem is that if hdr->nexthdr is 0xff then
we read one element beyond the end of the array so the array needs to be one element larger.

Fixes 92aa7c65d295 ("6lowpan: add generic nhc layer interface")

---
This is the only place which uses the NEXTHDR_MAX define, so I considered
changing that to 256 instead. Either fix would work.

 net/6lowpan/nhc.c  | 2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/6lowpan/nhc.c +0 -0
index 4fa2fdda174d..9e56fb98f33c 100644

net/6lowpan/nhc.c line 24

Quoted 8 lines
net/6lowpan/nhc.c +1 -1
@@ -18,7 +18,7 @@
 #include "nhc.h"
 
 static struct rb_root rb_root = RB_ROOT;
-static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX];
+static struct lowpan_nhc *lowpan_nexthdr_nhcs[NEXTHDR_MAX + 1];
 static DEFINE_SPINLOCK(lowpan_nhc_lock);
 
 static int lowpan_nhc_insert(struct lowpan_nhc *nhc)

Nice catch!

Cheers,
Jukka

Acked-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter

Hi,

Quoted 8 lines · Dan Carpenter

NEXTHDR_MAX is 255. What happens here is that we take a u8 value "hdr->nexthdr" from the network and then look it up in lowpan_nexthdr_nhcs[]. The problem is that if hdr->nexthdr is 0xff then we read one element beyond the end of the array so the array needs to be one element larger.

Fixes 92aa7c65d295 ("6lowpan: add generic nhc layer interface")

Thanks.

- Alex

maintainer
#3 lore raw
In reply to Dan Carpenter

Hi Dan,

Quoted 6 lines

NEXTHDR_MAX is 255. What happens here is that we take a u8 value "hdr->nexthdr" from the network and then look it up in lowpan_nexthdr_nhcs[]. The problem is that if hdr->nexthdr is 0xff then we read one element beyond the end of the array so the array needs to be one element larger.

Quoted 8 lines
Fixes 92aa7c65d295 ("6lowpan: add generic nhc layer interface")

---
This is the only place which uses the NEXTHDR_MAX define, so I considered changing that to 256 instead. Either fix would work.

net/6lowpan/nhc.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel