Skip to content

Commit a980762

Browse files
Tomasz Bursztykanashif
Tomasz Bursztyka
authored andcommitted
net/ieee802154: Drop fragmented packet if first frag is not present
Bogus fragmented packet could be sent without a FRAG1 fragment and hit reassembly. Let's make sure this does not happen. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent 2a423bc commit a980762

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

subsys/net/l2/ieee802154/ieee802154_fragment.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ static inline void fragment_reconstruct_packet(struct net_pkt *pkt)
472472
fragment_remove_headers(pkt);
473473
}
474474

475+
static inline bool fragment_packet_valid(struct net_pkt *pkt)
476+
{
477+
return (get_datagram_type(pkt->buffer->data) == NET_6LO_DISPATCH_FRAG1);
478+
}
479+
475480
/**
476481
* Parse size and tag from the fragment, check if we have any cache
477482
* related to it. If not create a new cache.
@@ -537,11 +542,14 @@ static inline enum net_verdict fragment_add_to_cache(struct net_pkt *pkt)
537542
cache->pkt = NULL;
538543
}
539544

545+
clear_reass_cache(size, tag);
540546

541-
fragment_reconstruct_packet(pkt);
547+
if (!fragment_packet_valid(pkt)) {
548+
NET_ERR("Invalid fragmented packet");
549+
return NET_DROP;
550+
}
542551

543-
/* Once reassemble is done, cache is no longer needed. */
544-
clear_reass_cache(size, tag);
552+
fragment_reconstruct_packet(pkt);
545553

546554
if (!net_6lo_uncompress(pkt)) {
547555
NET_ERR("Could not uncompress. Bogus packet?");

0 commit comments

Comments
 (0)