Bluetooth: eir: Fix possible crashes on eir_create_adv_data
Subsystems (4)
PATCH 1/1 Bluetooth: eir: Fix possible crashes on eir_create_adv_data
From: Luiz Augusto von Dentz <[email protected]>
[ Upstream commit 47c03902269aff377f959dc3fd94a9733aa31d6e ]
eir_create_adv_data may attempt to add EIR_FLAGS and EIR_TX_POWER without checking if that would fit.
[ Use pdu.data instead of pdu->data in hci_set_ext_adv_data_sync()
to keep context consistency. ]
--- net/bluetooth/eir.c | 7 ++++--- net/bluetooth/eir.h | 2 +- net/bluetooth/hci_sync.c | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-)
net/bluetooth/eir.c +4 -3
@@ -242,7 +242,7 @@ u8 eir_create_per_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr)return ad_len; } -u8 eir_create_adv_data (struct hci_dev *hdev,u8 instance,u8 *ptr) +u8 eir_create_adv_data (struct hci_dev *hdev,u8 instance,u8 *ptr,u8 size) {struct adv_info *adv =NULL ;u8 ad_len =0 , flags =0 ;
@@ -286,7 +286,7 @@ u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr)/* If flags would still be empty, then there is no need to * include the "Flags" AD field". */ -if (flags) { +if (flags && (ad_len +eir_precalc_len (1 ) <= size)) { ptr[0 ] =0x02 ; ptr[1 ] =EIR_FLAGS ; ptr[2 ] = flags;
@@ -316,7 +316,8 @@ u8 eir_create_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) }/* Provide Tx Power only if we can provide a valid value for it */ -if (adv_tx_power !=HCI_TX_POWER_INVALID ) { +if (adv_tx_power !=HCI_TX_POWER_INVALID && + (ad_len +eir_precalc_len (1 ) <= size)) { ptr[0 ] =0x02 ; ptr[1 ] =EIR_TX_POWER ; ptr[2 ] = (u8 )adv_tx_power;
net/bluetooth/eir.h +1 -1
@@ -9,7 +9,7 @@void eir_create (struct hci_dev *hdev,u8 *data); -u8 eir_create_adv_data (struct hci_dev *hdev,u8 instance,u8 *ptr); +u8 eir_create_adv_data (struct hci_dev *hdev,u8 instance,u8 *ptr,u8 size);u8 eir_create_scan_rsp (struct hci_dev *hdev,u8 instance,u8 *ptr);u8 eir_create_per_adv_data (struct hci_dev *hdev,u8 instance,u8 *ptr);
net/bluetooth/hci_sync.c +3 -2
@@ -1248,7 +1248,8 @@ static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance)return 0 ; } - len =eir_create_adv_data (hdev, instance, pdu.data); + len =eir_create_adv_data (hdev, instance, pdu.data, +HCI_MAX_EXT_AD_LENGTH ); pdu.cp.length = len; pdu.cp.handle = instance;
@@ -1279,7 +1280,7 @@ static int hci_set_adv_data_sync(struct hci_dev *hdev, u8 instance)memset (&cp,0 ,sizeof (cp)); - len =eir_create_adv_data (hdev, instance, cp.data); + len =eir_create_adv_data (hdev, instance, cp.data,sizeof (cp.data));/* There's nothing to do if the data hasn't changed */ if (hdev->adv_data_len == len &&
Signature · 1 line
2.34.1
This is an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
----- Output -----
error: patch failed: net/bluetooth/eir.c:242
error: net/bluetooth/eir.c: patch does not apply
error: patch failed: net/bluetooth/eir.h:9
error: net/bluetooth/eir.h: patch does not apply
error: patch failed: net/bluetooth/hci_sync.c:1248
error: net/bluetooth/hci_sync.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Please resolve the issue and submit the patches again.
---
Regards,
Linux Bluetooth