Skip to content

Commit 66dc901

Browse files
committed
Bluetooth: host: Handle multiple step security elevation
When ATT resends an ATT request it is sent as a "response" instead of as a request. This causes the ATT request buffer to be released and the ATT request cannot be resent one more time. This causes a problem when the ATT request requires authentication but the elevation of security is not enforcing MITM protection. In this case the ATT will first require security level 2 and then resend the request once this has been reached. This will lead to a new ATT error response and ATT will require security level L3. Signed-off-by: Joakim Andersson <[email protected]>
1 parent c2b562b commit 66dc901

File tree

1 file changed

+9
-9
lines changed
  • subsys/bluetooth/host

1 file changed

+9
-9
lines changed

subsys/bluetooth/host/att.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ static void att_req_destroy(struct bt_att_req *req)
119119

120120
if (req->buf) {
121121
net_buf_unref(req->buf);
122+
req->buf = NULL;
122123
}
123124

124125
if (req->destroy) {
@@ -2074,14 +2075,9 @@ static uint8_t att_error_rsp(struct bt_att_chan *chan, struct net_buf *buf)
20742075

20752076
err = rsp->error;
20762077
#if defined(CONFIG_BT_SMP)
2077-
if (chan->req->retrying) {
2078-
goto done;
2079-
}
2080-
2081-
/* Check if security needs to be changed */
2078+
/* Check if error can be handled by elevating security. */
20822079
if (!att_change_security(chan->chan.chan.conn, err)) {
20832080
chan->req->retrying = true;
2084-
/* Wait security_changed: TODO: Handle fail case */
20852081
return 0;
20862082
}
20872083
#endif /* CONFIG_BT_SMP */
@@ -2725,10 +2721,14 @@ static void bt_att_encrypt_change(struct bt_l2cap_chan *chan,
27252721
BT_DBG("Retrying");
27262722

27272723
/* Resend buffer */
2728-
bt_att_chan_send_rsp(att_chan, att_chan->req->buf,
2729-
chan_cb(att_chan->req->buf));
27302724

2731-
att_chan->req->buf = NULL;
2725+
/* Since packets are created in ATT and released in L2CAP we need to
2726+
* take a new reference to "create" the packet in ATT again.
2727+
*/
2728+
if (chan_send(att_chan, net_buf_ref(att_chan->req->buf), NULL)) {
2729+
net_buf_unref(att_chan->req->buf);
2730+
att_handle_rsp(att_chan, NULL, 0, BT_ATT_ERR_AUTHENTICATION);
2731+
}
27322732
}
27332733
#endif /* CONFIG_BT_SMP */
27342734

0 commit comments

Comments
 (0)