Skip to content

Missing Size Checks in Bluetooth HCI over SPI

Low
d3zd3z published GHSA-hg2w-62p6-g67c Apr 26, 2021

Package

zephyr (west)

Affected versions

v1.14.2, v2.2.0-v2.7.0

Patched versions

v3.0.0

Description

Issue Description

OOB Write after not validating user-supplied length (<= 0xffff) and
copying to fixed-size buffer (default: 77 bytes) for HCI_ACL packets in
bluetooth HCI over SPI driver.

Vulnerable Code

In drivers/bluetooth/hci/spi.c#bt_spi_rx_thread

size read directly from acl_hdr
static void bt_spi_rx_thread(void)
{
    struct net_buf *buf;
    u8_t header_master[5] = { SPI_READ, 0x00, 0x00, 0x00, 0x00 };
    u8_t header_slave[5];
    struct bt_hci_acl_hdr acl_hdr;
    u8_t size = 0U;
    int ret;

    (void)memset(&txmsg, 0xFF, SPI_MAX_MSG_LEN);
    ...
    switch (rxmsg[PACKET_TYPE]) {
    ...
    case HCI_ACL:
        // Tobias Scharnowski: Constant size buffer
        buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);
        // Tobias Scharnowski: Direct read of potentially untrusted data
into acl header
        memcpy(&acl_hdr, &rxmsg[1], sizeof(acl_hdr));
        net_buf_add_mem(buf, &acl_hdr, sizeof(acl_hdr));
        // Tobias Scharnowski: Use of size without sanitization
        net_buf_add_mem(buf, &rxmsg[5],
                sys_le16_to_cpu(acl_hdr.len));
        break;
    ...
    }
}

// Constant size (defined in `include/bluetooth/buf.h`):
#define BT_BUF_RESERVE CONFIG_BT_HCI_RESERVE
#define BT_BUF_SIZE(size) (BT_BUF_RESERVE + (size))
/** Data size neeed for HCI RX buffers */
#define BT_BUF_RX_SIZE (BT_BUF_SIZE(CONFIG_BT_RX_BUF_LEN))

- CONFIG_BT_HCI_RESERVE defaults to 0/1
- CONFIG_BT_RX_BUF_LEN defaults to 76
-> default full size BT_BUF_RX_SIZE is 77

Source Code References

Impact

  • Raw serial data via an SPI channel should generally not be trusted.
    Even if the other party is trusted (radio chip connected via SPI to
    application chip in dual-chip setup), the compromise of the radio chip
    should not lead to a full compromise of the application chip (elevation
    of privilege).
  • This is at least a DoS with a large specified size
  • Most likely also exploitable to RCE via OOB write accesses

Patches

Pull Request: #41334

For more information

If you have any questions or comments about this advisory:

embargo: 2020-06-29
zepsec: ZEPSEC-66
thanks: Steffen Schulz

Severity

Low

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
Physical
Attack complexity
High
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
Low
Integrity
Low
Availability
Low

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:P/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:L

CVE ID

CVE-2020-10065

Weaknesses