Skip to content

Commit 577cd82

Browse files
joerchancarlescufi
authored andcommitted
Bluetooth: host: Fix crash when receiving response after ATT timeout
Fix crash in ATT when the response for a request is received after the ATT timeout has fired and the ATT channel has been detached. Add similar handling for all ATT channel operations. Signed-off-by: Joakim Andersson <[email protected]>
1 parent 8b54f08 commit 577cd82

File tree

1 file changed

+20
-0
lines changed
  • subsys/bluetooth/host

1 file changed

+20
-0
lines changed

subsys/bluetooth/host/att.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ static void bt_att_sent(struct bt_l2cap_chan *ch)
284284

285285
atomic_clear_bit(chan->flags, ATT_PENDING_SENT);
286286

287+
if (!att) {
288+
BT_DBG("Ignore sent on detached ATT chan");
289+
return;
290+
}
291+
287292
/* Process pending requests first since they require a response they
288293
* can only be processed one at time while if other queues were
289294
* processed before they may always contain a buffer starving the
@@ -2433,6 +2438,11 @@ static int bt_att_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
24332438
BT_DBG("Received ATT chan %p code 0x%02x len %zu", att_chan, hdr->code,
24342439
net_buf_frags_len(buf));
24352440

2441+
if (!att_chan->att) {
2442+
BT_DBG("Ignore recv on detached ATT chan");
2443+
return 0;
2444+
}
2445+
24362446
for (i = 0, handler = NULL; i < ARRAY_SIZE(handlers); i++) {
24372447
if (hdr->code == handlers[i].op) {
24382448
handler = &handlers[i];
@@ -2690,6 +2700,11 @@ static void bt_att_encrypt_change(struct bt_l2cap_chan *chan,
26902700
BT_DBG("chan %p conn %p handle %u sec_level 0x%02x status 0x%02x", ch,
26912701
conn, conn->handle, conn->sec_level, hci_status);
26922702

2703+
if (!att_chan->att) {
2704+
BT_DBG("Ignore encrypt change on detached ATT chan");
2705+
return;
2706+
}
2707+
26932708
/*
26942709
* If status (HCI status of security procedure) is non-zero, notify
26952710
* outstanding request about security failure.
@@ -2734,6 +2749,11 @@ static void bt_att_status(struct bt_l2cap_chan *ch, atomic_t *status)
27342749
return;
27352750
}
27362751

2752+
if (!chan->att) {
2753+
BT_DBG("Ignore status on detached ATT chan");
2754+
return;
2755+
}
2756+
27372757
/* If there is a request pending don't attempt to send */
27382758
if (chan->req) {
27392759
return;

0 commit comments

Comments
 (0)