diff --git a/subsys/net/ip/6lo.c b/subsys/net/ip/6lo.c
index 736cf05839..f870abf4fc 100644
--- a/subsys/net/ip/6lo.c
+++ b/subsys/net/ip/6lo.c
@@ -1348,6 +1348,12 @@ static bool uncompress_IPHC_header(struct net_pkt *pkt)
nhc_inline_size;
}
+ /* Proposed fix: Make sure the buffer holds the full compressed header */
+ if (compressed_hdr_size > pkt->buffer->len) {
+ NET_ERR("Too small packet to hold compressed IPHC header");
+ return false;
+ }
+
if (net_buf_tailroom(pkt->buffer) >= diff) {
NET_DBG("Enough tailroom. Uncompress inplace");
frag = pkt->buffer;
5. Integer Underflow in 6LoWPAN IPHC Header Uncompression
Bug Details
High-Level reasoning for bug occurrence:
zephyr/subsys/net/ip/6lo.c
Line 1356 in d969ace
zephyr/subsys/net/ip/6lo.c
Line 1366 in d969ace
Vulnerable code path:
zephyr/subsys/net/l2/ieee802154/ieee802154_fragment.c
Line 517 in d969ace
zephyr/subsys/net/l2/ieee802154/ieee802154_fragment.c
Line 527 in d969ace
zephyr/subsys/net/ip/6lo.c
Line 1330 in d969ace
zephyr/subsys/net/ip/6lo.c
Line 1366 in d969ace
zephyr/subsys/net/buf.c
Line 1126 in d969ace
Proposed Fix
After calculating the size of the expected uncompressed header based on the iphc metadata field, check that enough space is actually present within the buffer.
Note that the single pkt->buffer fragment may not represent all data within the packet, which may consist of multiple fragments
If the uncompressed header is expected to be present in the first fragment, the following check could be implemented:
Patches
This has been fixed in:
For more information
If you have any questions or comments about this advisory:
embargo: 2021-04-14
zepsec: ZEPSEC-116