Skip to content

Commit d811f69

Browse files
lylezhu2012henrikbrixandersen
authored andcommitted
Bluetooth: L2CAP_BR: Reject the conn req if sec levels do not match
If the ACL link has been encrypted and it has a authenticated link key, it means the pairing procedure has been done. And the security level of the link key can not be upgraded. In this case, if `conn->sec_level` is less than the required security level of the L2CAP channel, reject the L2CAP conn request. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent 110cd6b commit d811f69

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

subsys/bluetooth/host/classic/l2cap_br.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "host/buf_view.h"
2222
#include "host/hci_core.h"
2323
#include "host/conn_internal.h"
24+
#include "host/keys.h"
2425
#include "l2cap_br_internal.h"
2526
#include "avdtp_internal.h"
2627
#include "a2dp_internal.h"
@@ -766,7 +767,9 @@ enum l2cap_br_conn_security_result {
766767
* - channel connection process is on hold since there were valid security
767768
* conditions triggering authentication indirectly in subcall.
768769
* Returns L2CAP_CONN_SECURITY_REJECT if:
769-
* - bt_conn_set_security API returns < 0.
770+
* - bt_conn_set_security API returns < 0,
771+
* - Or, the ACL connection has been encrypted, the security level of link key cannot be upgraded,
772+
* and the security level is less than the required security level.
770773
*/
771774

772775
static enum l2cap_br_conn_security_result
@@ -807,6 +810,18 @@ l2cap_br_conn_security(struct bt_l2cap_chan *chan, const uint16_t psm)
807810
break;
808811
}
809812

813+
if (chan->conn->sec_level < br_chan->required_sec_level &&
814+
chan->conn->encrypt && chan->conn->br.link_key &&
815+
(chan->conn->br.link_key->flags & BT_LINK_KEY_AUTHENTICATED)) {
816+
/*
817+
* If the ACL link has been encrypted and it has a authenticated link key, it means
818+
* the pairing procedure has been done. And the security level of the link key can
819+
* not be upgraded. In this case, if `conn->sec_level` is less than the required
820+
* security level of the L2CAP channel, reject the L2CAP conn request.
821+
*/
822+
return L2CAP_CONN_SECURITY_REJECT;
823+
}
824+
810825
check = bt_conn_set_security(chan->conn, br_chan->required_sec_level);
811826

812827
/*

0 commit comments

Comments
 (0)