btdev: Fix set PA data array overflow
cover btdev: Fix set PA data array overflow
This fixes an array overflow that can happen if the user issues the LE Set Periodic Advertising Data command with data length exceeding 31 bytes.
This can be noticed when running the Broadcast Source/Sink scenarios in bluetoothctl, using emulated controllers: If the source BASE exceeds 31 bytes, the PA reports received by the Sink looks something like the following:
Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 39
LE Periodic Advertising Report (0x0f)
Sync handle: 1
TX power: 127 dbm (0x7f)
RSSI: not available (0x7f)
CTE Type: No Constant Tone Extension (0xff)
Data status: Incomplete, more data to come
Data length: 0x1f
25 16 51 18 e0 99 89 01 01 06 00 00 00 00 10 02
01 03 02 02 01 03 04 28 00 05 03 03 00 00 00Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 15
LE Periodic Advertising Report (0x0f)
Sync handle: 1
TX power: 127 dbm (0x7f)
RSSI: not available (0x7f)
CTE Type: No Constant Tone Extension (0xff)
Data status: Complete
Data length: 0x07
00 00 00 00 00 00 00The second PA report contains invalid bytes that were read outside the PA data array.
Iulia Tanasescu (1):
btdev: Fix set PA data array overflow
emulator/btdev.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
base-commit: 41c7f3af0352d3e45f4f10b7584e955a7f5cc696
Signature · 1 line
2.39.2
PATCH 1/1 btdev: Fix set PA data array overflow
This fixes an array overflow that can happen if the user issues the LE Set Periodic Advertising Data command with data length exceeding 31 bytes.
The PA data set by the user is copied in an array of fixed length (31 bytes). However, the data length might exceed 31 bytes. This will cause an array overflow when the PA data is later processed (for instance, when sending PA reports).
According to specification, the data length provided at LE Set Periodic Advertising Data command can be maximum 252 bytes. The stored data len should also be true to the length copied in the array.
--- emulator/btdev.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
emulator/btdev.c +10 -4
@@ -5,7 +5,7 @@* * Copyright (C) 2011-2012 Intel Corporation * Copyright (C) 2004-2010 Marcel Holtmann <[email protected]> -* Copyright 2023 NXP +* Copyright 2023-2024 NXP * * */
@@ -44,6 +44,8 @@#define BIS_SIZE 3#define CIG_SIZE 3 +#define MAX_PA_DATA_LEN 252 +#define has_bredr (btdev) (!((btdev)->features[4] & 0x20))#define has_le (btdev) (!!((btdev)->features[4] & 0x40))
@@ -207,7 +209,7 @@ struct btdev {uint16_t le_pa_min_interval;uint16_t le_pa_max_interval;uint8_t le_pa_data_len; -uint8_t le_pa_data[31 ]; +uint8_t le_pa_data[MAX_PA_DATA_LEN ];struct bt_hci_cmd_le_pa_create_sync pa_sync_cmd;uint16_t le_pa_sync_handle;uint8_t big_handle;
@@ -5210,9 +5212,13 @@ static int cmd_set_pa_data(struct btdev *dev, const void *data, {const struct bt_hci_cmd_le_set_pa_data *cmd = data;uint8_t status =BT_HCI_ERR_SUCCESS ; +uint8_t data_len = cmd->data_len; + +if (data_len >MAX_PA_DATA_LEN ) + data_len =MAX_PA_DATA_LEN ; - dev->le_pa_data_len = cmd->data_len; -memcpy (dev->le_pa_data, cmd->data,31 ); + dev->le_pa_data_len = data_len; +memcpy (dev->le_pa_data, cmd->data, data_len);cmd_complete (dev,BT_HCI_CMD_LE_SET_PA_DATA , &status,sizeof (status));
Signature · 1 line
2.39.2
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=825705
---Test result---
Test Summary:
CheckPatch PASS 0.31 seconds GitLint PASS 0.22 seconds BuildEll PASS 23.97 seconds BluezMake PASS 716.04 seconds MakeCheck PASS 11.60 seconds MakeDistcheck PASS 162.51 seconds CheckValgrind PASS 228.35 seconds CheckSmatch WARNING 328.25 seconds bluezmakeextell PASS 106.95 seconds IncrementalBuild PASS 658.05 seconds ScanBuild WARNING 947.23 seconds
Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:emulator/btdev.c:422:29: warning: Variable length array is used.
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:emulator/btdev.c:1086:10: warning: Although the value stored to 'conn' is used in the enclosing expression, the value is never actually read from 'conn'
while ((conn = queue_find(dev->conns, match_handle,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
emulator/btdev.c:1369:24: warning: Access to field 'link' results in a dereference of a null pointer (loaded from variable 'conn')
pending_conn_del(dev, conn->link->dev);
^~~~~~~~~~
emulator/btdev.c:1491:13: warning: Access to field 'dev' results in a dereference of a null pointer (loaded from variable 'conn')
send_event(conn->dev, BT_HCI_EVT_AUTH_COMPLETE, &ev, sizeof(ev));
^~~~~~~~~3 warnings generated.
---
Regards,
Linux Bluetooth
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 10 lines · On Tue, 13 Feb 2024 17:58:02 +0200 you wrote:
This fixes an array overflow that can happen if the user issues the LE Set Periodic Advertising Data command with data length exceeding 31 bytes.
This can be noticed when running the Broadcast Source/Sink scenarios in bluetoothctl, using emulated controllers: If the source BASE exceeds 31 bytes, the PA reports received by the Sink looks something like the following:
[...]
Here is the summary with links:
- [BlueZ,1/1] btdev: Fix set PA data array overflow
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7c49568a2758
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html