Skip to content

Bluetooth HCI Error Handling Double Free

Low
ceolin published GHSA-w525-fm68-ppq3 Jan 19, 2023

Package

zephyr (west)

Affected versions

<= 3.2

Patched versions

None

Description

Impact

Inconsistent handling of error cases in bluetooth hci may lead
to a double free condition of a network buffer.

Details

In a bluetooth driver, when sending a packet via bt_send fails in the
lower driver's send function (such as bt_spi_send), then the
convention is that the ownership remains with the caller of bt_send.

This means that in the error case, the caller of bt_send will clean up
all references to the netbuf it provided to bt_send(net_buf *buf).

This convention is observed by most driver functions. For example:

h4_send handles sending packets by indicating success in all cases
initially, and then cleaning up the reference itself.

This is, however, not always adhered to. For example:

  1. bt_spi_send netbuf is unreferenced in the error case
    bt_spi_transceive fails:

    (however, other error cases do not unreference the netbuf. For example,
    the case of a too long buffer:
    } while ((rxmsg[STATUS_HEADER_READY] != READY_NOW ||
    )
  2. bt_esp32_send unreferences the netbuf in the timeout error case:
    err = -ETIMEDOUT;

    (for the other error case "unknown type", however, the function
    indicates a zero result, in which case the convention is not broken. So
    only the presumably much less frequently observed timeout case breaks
    the convention)

Bug trigger source code references:

For completeness, the different hci implementations should be re-checked
for exhibiting this issue depending on error code paths.

A possible attack scenario here could be an attacker who compromised a
radio chip and then proceeds to attack the bluetooth host stack via the
HCI interface. Such an attacker could also be in a position to induce
SPI errors on the sending side such as spamming traffic or indicating
errors to the sender (e.g., in spi flow control). An attacker which is
able to induce errors in different SPI bluetooth sending functions can
cause a double free scenario on a network buffer. I have not checked the
exploitability of this specific situation, but apart from a simple crash
(DoS), double frees are typically a strong primitive for an attacker to
achieve more with this, such as RCE.

Patches

Credits

Tobias Scharnowski
Simon Woerner
Felix Buchmann

For more information

If you have any questions or comments about this advisory:

embargo: 2023-01-17

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-2022-3806

Weaknesses

Credits