Skip to content

Commit

Permalink
btdev: Fix set PA data array overflow
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iulia-tanasescu authored and Vudentz committed Feb 13, 2024
1 parent b16b198 commit 7c49568
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions emulator/btdev.c
Expand Up @@ -5,7 +5,7 @@
*
* Copyright (C) 2011-2012 Intel Corporation
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
* Copyright 2023 NXP
* Copyright 2023-2024 NXP
*
*
*/
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit 7c49568

Please sign in to comment.