Skip to content

Commit bda93ee

Browse files
Niebelungen-DVudentz
authored andcommitted
Bluetooth: MGMT: validate mesh send advertising payload length
mesh_send() currently bounds MGMT_OP_MESH_SEND by total command length, but it never verifies that the bytes supplied for the flexible adv_data[] array actually match the embedded adv_data_len field. MGMT_MESH_SEND_SIZE only covers the fixed header, so a truncated command can still pass the existing 20..50 byte range check and later drive the async mesh send path past the end of the queued command buffer. Keep rejecting zero-length and oversized advertising payloads, but validate adv_data_len explicitly and require the command length to exactly match the flexible array size before queueing the request. Fixes: b338d91 ("Bluetooth: Implement support for Mesh") Reported-by: Keenan Dong <keenanat2000@gmail.com> Signed-off-by: Keenan Dong <keenanat2000@gmail.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent b255531 commit bda93ee

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

net/bluetooth/mgmt.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,19 +2478,27 @@ static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)
24782478
struct mgmt_mesh_tx *mesh_tx;
24792479
struct mgmt_cp_mesh_send *send = data;
24802480
struct mgmt_rp_mesh_read_features rp;
2481+
u16 expected_len;
24812482
bool sending;
24822483
int err = 0;
24832484

24842485
if (!lmp_le_capable(hdev) ||
24852486
!hci_dev_test_flag(hdev, HCI_MESH_EXPERIMENTAL))
24862487
return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND,
24872488
MGMT_STATUS_NOT_SUPPORTED);
2488-
if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) ||
2489-
len <= MGMT_MESH_SEND_SIZE ||
2490-
len > (MGMT_MESH_SEND_SIZE + 31))
2489+
if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED))
2490+
return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND,
2491+
MGMT_STATUS_REJECTED);
2492+
2493+
if (!send->adv_data_len || send->adv_data_len > 31)
24912494
return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND,
24922495
MGMT_STATUS_REJECTED);
24932496

2497+
expected_len = struct_size(send, adv_data, send->adv_data_len);
2498+
if (expected_len != len)
2499+
return mgmt_cmd_status(sk, hdev->id, MGMT_OP_MESH_SEND,
2500+
MGMT_STATUS_INVALID_PARAMS);
2501+
24942502
hci_dev_lock(hdev);
24952503

24962504
memset(&rp, 0, sizeof(rp));

0 commit comments

Comments
 (0)