Skip to content

Commit d828446

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: L2CAP_BR: CID of data sending is invalid
There is a corner case that the channel is in disconnecting status, due to there is a disconnect request sent from peer. At this time, the channel is status is `BT_L2CAP_CONNECTED`. But it has been removed from `conn->channels` by calling the function `l2cap_br_remove_tx_cid`. And the disconnect event is notified upper layer via the callback `ops->disconnected`. The thread of the callback context is blocked due to the the calling of `printk` in the callback function. Then the pending lower priority thread, sending the data in this l2cap channel, is activated. Then in the function `bt_l2cap_br_send_cb`, a NULL pointer will be got according to the given CID. And unexpected behavior happens when accessing a NULL pointer, since the invalid channel pointer is not checked in function `bt_l2cap_br_send_cb`. Check the channel pointer after function `bt_l2cap_br_lookup_tx_cid` called. If the channel pointer is invalid, return error code `-ESHUTDOWN` directly. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 6d01483 commit d828446

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

subsys/bluetooth/host/classic/l2cap_br.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,14 @@ int bt_l2cap_br_send_cb(struct bt_conn *conn, uint16_t cid, struct net_buf *buf,
310310
{
311311
struct bt_l2cap_hdr *hdr;
312312
struct bt_l2cap_chan *ch = bt_l2cap_br_lookup_tx_cid(conn, cid);
313-
struct bt_l2cap_br_chan *br_chan = CONTAINER_OF(ch, struct bt_l2cap_br_chan, chan);
313+
struct bt_l2cap_br_chan *br_chan;
314+
315+
if (ch == NULL) {
316+
LOG_WRN("CID %d is not found on conn %p", cid, conn);
317+
return -ESHUTDOWN;
318+
}
319+
320+
br_chan = CONTAINER_OF(ch, struct bt_l2cap_br_chan, chan);
314321

315322
LOG_DBG("chan %p buf %p len %zu", br_chan, buf, buf->len);
316323

0 commit comments

Comments
 (0)