Skip to content

Commit 3af3c12

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: Controller: Restrict AD Data to BT_CTLR_ADV_DATA_LEN_MAX
Strictly restrict AD Data length to BT_CTLR_ADV_DATA_LEN_MAX when there can be free bytes in Advertising PDU with common extended header format of less that the maximum 64 bytes. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent d72126d commit 3af3c12

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

subsys/bluetooth/controller/ll_sw/ull_adv_aux.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,19 @@ uint8_t ll_adv_aux_sr_data_set(uint8_t handle, uint8_t op, uint8_t frag_pref,
313313
sr_adi = NULL;
314314
#endif
315315

316+
/* Check Max Advertising Data Length */
317+
if (len > CONFIG_BT_CTLR_ADV_DATA_LEN_MAX) {
318+
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
319+
}
320+
316321
/* Check if data will fit in remaining space */
317322
/* TODO: need aux_chain_ind support */
318323
ext_hdr_len = sr_dptr - &sr_com_hdr->ext_hdr_adv_data[0];
319324
if ((PDU_AC_EXT_HEADER_SIZE_MIN + ext_hdr_len + len) >
320325
PDU_AC_PAYLOAD_SIZE_MAX) {
326+
/* Will use packet too long error to determine fragmenting
327+
* long data
328+
*/
321329
return BT_HCI_ERR_PACKET_TOO_LONG;
322330
}
323331

@@ -824,18 +832,22 @@ uint8_t ull_adv_aux_hdr_set_clear(struct ll_adv_set *adv,
824832
ad_data = sec_dptr_prev;
825833
}
826834

827-
/* Add AD len to secondary PDU length */
828-
sec_len += ad_len;
835+
/* Check Max Advertising Data Length */
836+
if (ad_len > CONFIG_BT_CTLR_ADV_DATA_LEN_MAX) {
837+
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
838+
}
829839

830840
/* Check AdvData overflow */
831841
/* TODO: need aux_chain_ind support */
832-
if (sec_len > PDU_AC_PAYLOAD_SIZE_MAX) {
833-
/* FIXME: release allocations */
842+
if ((sec_len + ad_len) > PDU_AC_PAYLOAD_SIZE_MAX) {
843+
/* Will use packet too long error to determine fragmenting
844+
* long data
845+
*/
834846
return BT_HCI_ERR_PACKET_TOO_LONG;
835847
}
836848

837849
/* set the secondary PDU len */
838-
sec_pdu->len = sec_len;
850+
sec_pdu->len = sec_len + ad_len;
839851

840852
/* Start filling pri and sec PDU payload based on flags from here
841853
* ==============================================================

subsys/bluetooth/controller/ll_sw/ull_adv_sync.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,16 +1311,21 @@ uint8_t ull_adv_sync_pdu_set_clear(struct lll_adv_sync *lll_sync,
13111311
ad_data = NULL;
13121312
}
13131313

1314-
/* Add AD len to tertiary PDU length */
1315-
ter_len += ad_len;
1314+
/* Check Max Advertising Data Length */
1315+
if (ad_len > CONFIG_BT_CTLR_ADV_DATA_LEN_MAX) {
1316+
return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
1317+
}
13161318

13171319
/* Check AdvData overflow */
1318-
if (ter_len > PDU_AC_PAYLOAD_SIZE_MAX) {
1320+
if ((ter_len + ad_len) > PDU_AC_PAYLOAD_SIZE_MAX) {
1321+
/* Will use packet too long error to determine fragmenting
1322+
* long data
1323+
*/
13191324
return BT_HCI_ERR_PACKET_TOO_LONG;
13201325
}
13211326

13221327
/* set the tertiary PDU len */
1323-
ter_pdu->len = ter_len;
1328+
ter_pdu->len = ter_len + ad_len;
13241329

13251330
/* Start filling tertiary PDU payload based on flags from here
13261331
* ==============================================================

0 commit comments

Comments
 (0)