Open fireknight-hJ opened 1 year ago
Hi, @fireknight-hJ would you create a pull request to fix this issue?
Hi, @0xc0170 I've fixed the issue and created a pull request (#15474) for your review. Please take a look and let me know if everything is in order.
Description of defect
Reference: https://github.com/ARMmbed/mbed-os/blob/master/connectivity/FEATURE_BLE/source/cordio/stack_adaptation/hci_tr.c
Function: hciTrSerialRxIncoming
From: mbed-os/blob/master/connectivity/FEATURE_BLE/source/cordio/stack_adaptation/hci_tr.c Line: 125
https://github.com/ARMmbed/mbed-os/blob/7c7d20da6527885237094d9d50ce099404414201/connectivity/FEATURE_BLE/source/cordio/stack_adaptation/hci_tr.c#L125-L125
Type: Buffer overflow
The BLE Cordio implementation in Mbed OS utilizes the
hciTrSerialRxIncoming
function to manage incoming HCI data. However, I have identified and verified a potential issue that could lead to a buffer overflow inhdrRx
if packet types are excluded from the valid ones.To elaborate, when an invalid packet type is encountered, the
hdrlen
(line 36) remain the inital value (i.e.,0) but theiRx
has been increased (Line 19). Consequently, the condition in Line 41 is not satisfied and thestateRx
variable remains in theHCI_RX_STATE_HEADER
state. This, in turn, allows incoming data to continuously accumulate in the hdrRx buffer inwhile
loop execution, as shown in line 19. However, it's important to note that thehdrRx
's size is constrained by theHCI_ACL_HDR_LEN
macro, which is set to a mere 4 bytes. This causes a vulnerability to buffer overflow.In addition, note that
WSF_ASSERT
is turned off by default. However, even if theWSF_ASSERT
is turn on the execution will be simple return or directly hang which depends on how the mbed_error function works, as shown its following defination.Target(s) affected by this defect ?
MbedOS BLE Cordio stack
Toolchain(s) (name and version) displaying this defect ?
N/A
What version of Mbed-os are you using (tag or sha) ?
mbed-os-6.17.0 (the latest version)
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
mbed-cli2
How is this defect reproduced ?
Send problematic HCI protocol packets to the target demo board using the Cordio protocol stack.