Skip to content

Commit e9bb833

Browse files
ivaniushkovrlubos
authored andcommitted
[nrf fromtree] Bluetooth: fixing null-pointer dereference in l2cap channel destroyer
During local testing with UBSAN enabled, warning was reported: bluetooth/host/l2cap.c:980:25: runtime error: member access within null pointer of type 'struct k_work_q' It turned out that le_chan->rtx_work.queue can be NULL. Since null-pointer dereference is a UB, additional check was added to ensure we don't access `le_chan->rtx_work.queue->thread` when `le_chan->rtx_work.queue == NULL` The same changes applied to l2cap_br.c Signed-off-by: Ivan Iushkov <[email protected]> (cherry picked from commit a3cbf8e) Signed-off-by: Ivan Iushkov <[email protected]>
1 parent 2ef9e28 commit e9bb833

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

subsys/bluetooth/host/l2cap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,9 @@ static void l2cap_chan_destroy(struct bt_l2cap_chan *chan)
977977
* In the case where we are in the context of executing the rtx_work
978978
* item, we don't sync as it will deadlock the workqueue.
979979
*/
980-
if (k_current_get() != &le_chan->rtx_work.queue->thread) {
980+
struct k_work_q *rtx_work_queue = le_chan->rtx_work.queue;
981+
982+
if (rtx_work_queue == NULL || k_current_get() != &rtx_work_queue->thread) {
981983
k_work_cancel_delayable_sync(&le_chan->rtx_work, &le_chan->rtx_sync);
982984
} else {
983985
k_work_cancel_delayable(&le_chan->rtx_work);

subsys/bluetooth/host/l2cap_br.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ static void l2cap_br_chan_destroy(struct bt_l2cap_chan *chan)
165165
* In the case where we are in the context of executing the rtx_work
166166
* item, we don't sync as it will deadlock the workqueue.
167167
*/
168-
if (k_current_get() != &br_chan->rtx_work.queue->thread) {
168+
struct k_work_q *rtx_work_queue = br_chan->rtx_work.queue;
169+
170+
if (rtx_work_queue == NULL || k_current_get() != &rtx_work_queue->thread) {
169171
k_work_cancel_delayable_sync(&br_chan->rtx_work, &br_chan->rtx_sync);
170172
} else {
171173
k_work_cancel_delayable(&br_chan->rtx_work);

0 commit comments

Comments
 (0)