Cordio BLE: Fix integer overflows (CVE-2024-48983) #388
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of changes
hciTrSerialRxIncoming
parses incoming hci packets. In doing so, it dynamically determines the length of the packet body. For the case ofHCI_ACL_TYPE
this is done by reading 2 bytes from the packet header.mbed-os/connectivity/FEATURE_BLE/source/cordio/stack_adaptation/hci_tr.c
Lines 182 to 195 in 54e8693
A buffer is then allocated to hold the packet, the length of which is determined by the sum of this 16bit integer and the length of the packet header.
mbed-os/connectivity/FEATURE_BLE/source/cordio/stack_adaptation/hci_tr.c
Lines 197 to 201 in 54e8693
The final buffer size is also increased by
WsfMsgAlloc
, which adds the size of onewsfMsg_t
.mbed-os/connectivity/FEATURE_BLE/libraries/cordio_stack/wsf/sources/port/baremetal/wsf_msg.c
Line 72 in 54e8693
For large
dataLen
values, this addition may result in an integer overflow which causes the allocated buffer to be very small. Header and body are then copied separately, resulting in one operation of sizehdrLen
and one of sizedataLen
, the latter of which is always larger than the allocated buffer. This leads to a buffer overflow which, if large amounts of data are written, will likely result in corruption of memory data and may cause the system to crash.This fix eliminates the issue by check for integer overflows, both in
hciTrSerialRxIncoming
andWsfMsgAlloc
.Impact of changes
Migration actions required
Documentation
None
Pull request type
Test results