Skip to content

Commit 9efb149

Browse files
PavelVPVrlubos
authored andcommitted
[nrf fromtree] bluetooth: host: l2cap: Check conn state before queueing PDU
In case of UATT, if a connection was lost while user was holding a read or write attribute callback, `bt_l2cap_send_pdu` (called from `att.c::chan_send`) will anyway queue a PDU and trigger tx work. The PDU won't be sent eventually, but neither will hold an error code, which will allow it to bypass the error check in `att_on_sent_cb` and call `att_sent` function. For EATT `bt_l2cap_chan_send` is used which already handles this case and the error code is passed to `att_on_sent_cb`. This change adds connection state check to `bt_l2cap_send_pdu` preventing from unnecessary code execution when connection does not exist anymore. Signed-off-by: Pavel Vasilyev <[email protected]> (cherry picked from commit 74972e6)
1 parent 3b53c65 commit 9efb149

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

subsys/bluetooth/host/l2cap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@ static void cancel_data_ready(struct bt_l2cap_le_chan *le_chan)
717717
int bt_l2cap_send_pdu(struct bt_l2cap_le_chan *le_chan, struct net_buf *pdu,
718718
bt_conn_tx_cb_t cb, void *user_data)
719719
{
720+
if (!le_chan->chan.conn || le_chan->chan.conn->state != BT_CONN_CONNECTED) {
721+
return -ENOTCONN;
722+
}
723+
720724
if (pdu->ref != 1) {
721725
/* The host may alter the buf contents when fragmenting. Higher
722726
* layers cannot expect the buf contents to stay intact. Extra

0 commit comments

Comments
 (0)