Skip to content

Commit

Permalink
Bluetooth: controller: legacy: Fix Tx pool corruption
Browse files Browse the repository at this point in the history
Fix Tx pool from being corrupted when rough central device
uses invalid packet sequence numbers, causing NULL pointer
to be released into free data Tx pool.

Fixes zephyrproject-rtos#22968.

Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
  • Loading branch information
cvinayak committed Sep 23, 2020
1 parent d831818 commit 5c0c536
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions subsys/bluetooth/controller/ll_sw/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3648,6 +3648,7 @@ isr_rx_conn_pkt(struct radio_pdu_node_rx *node_rx,
/* Ack for transmitted data */
pdu_data_rx = (void *)node_rx->pdu_data;
if (pdu_data_rx->nesn != _radio.conn_curr->sn) {
struct radio_pdu_node_tx *node_tx;

/* Increment serial number */
_radio.conn_curr->sn++;
Expand All @@ -3659,11 +3660,16 @@ isr_rx_conn_pkt(struct radio_pdu_node_rx *node_rx,
_radio.conn_curr->slave.latency_enabled = 1U;
}

if (_radio.conn_curr->empty == 0) {
struct radio_pdu_node_tx *node_tx;
if (!_radio.conn_curr->empty) {
node_tx = _radio.conn_curr->pkt_tx_head;
} else {
_radio.conn_curr->empty = 0U;
node_tx = NULL;
}

if (node_tx) {
u8_t pdu_data_tx_len;

node_tx = _radio.conn_curr->pkt_tx_head;
pdu_data_tx = (void *)(node_tx->pdu_data +
_radio.conn_curr->packet_tx_head_offset);

Expand All @@ -3681,13 +3687,12 @@ isr_rx_conn_pkt(struct radio_pdu_node_rx *node_rx,
}
}

_radio.conn_curr->packet_tx_head_offset += pdu_data_tx_len;
_radio.conn_curr->packet_tx_head_offset +=
pdu_data_tx_len;
if (_radio.conn_curr->packet_tx_head_offset ==
_radio.conn_curr->packet_tx_head_len) {
*tx_release = isr_rx_conn_pkt_release(node_tx);
}
} else {
_radio.conn_curr->empty = 0U;
}
#if defined(CONFIG_BT_CTLR_TX_RETRY_DISABLE)
} else if (_radio.packet_counter != 1) {
Expand Down

0 comments on commit 5c0c536

Please sign in to comment.