Skip to content

Buffer Overflow during IPHC receive

Critical
chrysn published GHSA-fv97-2448-gcf6 Apr 24, 2023

Package

RIOT-OS

Affected versions

< 2022.10

Patched versions

2022.10

Description

Impact

RIOT-OS contains a network stack with the ability to process 6LoWPAN frames. An attacker can send a crafted frame to the device resulting in an out of bounds write in the packet buffer. The overflow can be used to corrupt other packets and the allocator metadata. Corrupting a pointer will easily lead to denial of service. While carefully manipulating the allocator metadata gives an attacker the possibility to write data to arbitrary locations and thus execute arbitrary code.

Patches

Workarounds

  • Disabling support for fragmented IP datagrams, or
  • Backport the patches listed above

For more information

If you have any questions or comments about this advisory:

Bug Details

During reassembling of 6LoWPAN packets _rbuf_add is used to add incoming fragments to the buffer.
In _rbuf_add the datagram_size is retrieved from the fragment (source):

    datagram_size = sixlowpan_frag_datagram_size(pkt->data);

If it is the first fragment, datagram_size is used to create a new reassembly buffer in _rbuf_get:

    else if ((res = _rbuf_get(src, netif_hdr->src_l2addr_len,
                              dst, netif_hdr->dst_l2addr_len,
                              datagram_size, datagram_tag, page)) < 0) {

Afterwards the fragment size is checked to not exceed the datagram size.
But this check doesn't consider the increased size due to header decompression (source):

    if ((offset + frag_size) > entry.super->datagram_size) {

Later the 6LoWPAN fragment is decompressed into the reassembly buffer (source):

    gnrc_sixlowpan_iphc_recv(pkt, entry.rbuf, 0);

For unfragmented packets gnrc_sixlowpan_iphc_recv reallocates the buffer to the proper size (source):

    if ((rbuf == NULL) &&
        /* (rbuf == NULL) => forwarding is not affected by this */
        (gnrc_pktbuf_realloc_data(ipv6, uncomp_hdr_len + payload_len) != 0)) {

But for fragmented packets this is not the case and no additional check is performed.
(Also: reallocation size should be payload_len + sizeof(ipv6_hdr_t) as payload_len already includes uncomp_hdr_len).

The buffer is now assumed to be large enough for the packet payload.
But due to the uncompressed IPv6 header being larger than the 6LoWPAN header this is no longer true.
While copying the payload from the 6LoWPAN snippet to the IPv6 snippet an out of bounds write in the packet buffer occurs (source):

    memcpy(((uint8_t *)ipv6->data) + uncomp_hdr_len,
           ((uint8_t *)sixlo->data) + payload_offset,
           sixlo->size - payload_offset);

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

CVE ID

CVE-2023-24819

Credits