diff --git a/subsys/net/l2/ieee802154/ieee802154_fragment.c b/subsys/net/l2/ieee802154/ieee802154_fragm
ent.c
index 790c159b56..816888f524 100644
--- a/subsys/net/l2/ieee802154/ieee802154_fragment.c
+++ b/subsys/net/l2/ieee802154/ieee802154_fragment.c
@@ -484,6 +487,7 @@ static inline enum net_verdict fragment_add_to_cache(struct net_pkt *pkt)
bool first_frag = false;
struct frag_cache *cache;
struct net_buf *frag;
+ uint8_t type;
uint16_t size;
uint16_t tag;
@@ -494,6 +498,15 @@ static inline enum net_verdict fragment_add_to_cache(struct net_pkt *pkt)
tag = get_datagram_tag(pkt->buffer->data +
NET_6LO_FRAG_DATAGRAM_SIZE_LEN);
+ /* Ensure large enough fragments */
+ type = pkt->buffer->data[0] & NET_FRAG_DISPATCH_MASK;
+ if (!((type == NET_6LO_DISPATCH_FRAG1 &&
+ pkt->buffer->len > NET_6LO_FRAG1_HDR_LEN) ||
+ (type == NET_6LO_DISPATCH_FRAGN &&
+ pkt->buffer->len > NET_6LO_FRAGN_HDR_LEN))) {
+ return NET_DROP;
+ }
+
/* If there are no fragments in the cache means this frag
* is the first one. So cache Rx pkt otherwise not.
*/
3. Integer Underflow in IEEE 802154 Fragment Reassembly Header Removal
Bug Details
High-Level reasoning for bug occurrence:
Vulnerable code path:
zephyr/subsys/net/l2/ieee802154/ieee802154_fragment.c
Line 503 in d969ace
zephyr/subsys/net/l2/ieee802154/ieee802154_fragment.c
Line 515 in d969ace
zephyr/subsys/net/l2/ieee802154/ieee802154_fragment.c
Line 471 in d969ace
zephyr/subsys/net/l2/ieee802154/ieee802154_fragment.c
Line 443 in d969ace
Proposed Fix
zephyr/subsys/net/l2/ieee802154/ieee802154_fragment.c
Line 491 in d969ace
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-114