Skip to content

Commit 7af8479

Browse files
committed
Bluetooth: L2CAP: Fix not checking l2cap_chan security level
l2cap_check_enc_key_size shall check the security level of the l2cap_chan rather than the hci_conn since for incoming connection request that may be different as hci_conn may already been encrypted using a different security level. Fixes: 522e9ed ("Bluetooth: l2cap: Check encryption key size on incoming connection") Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 0afc44d commit 7af8479

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

net/bluetooth/l2cap_core.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,8 @@ static void l2cap_request_info(struct l2cap_conn *conn)
14111411
sizeof(req), &req);
14121412
}
14131413

1414-
static bool l2cap_check_enc_key_size(struct hci_conn *hcon)
1414+
static bool l2cap_check_enc_key_size(struct hci_conn *hcon,
1415+
struct l2cap_chan *chan)
14151416
{
14161417
/* The minimum encryption key size needs to be enforced by the
14171418
* host stack before establishing any L2CAP connections. The
@@ -1425,7 +1426,7 @@ static bool l2cap_check_enc_key_size(struct hci_conn *hcon)
14251426
int min_key_size = hcon->hdev->min_enc_key_size;
14261427

14271428
/* On FIPS security level, key size must be 16 bytes */
1428-
if (hcon->sec_level == BT_SECURITY_FIPS)
1429+
if (chan->sec_level == BT_SECURITY_FIPS)
14291430
min_key_size = 16;
14301431

14311432
return (!test_bit(HCI_CONN_ENCRYPT, &hcon->flags) ||
@@ -1453,7 +1454,7 @@ static void l2cap_do_start(struct l2cap_chan *chan)
14531454
!__l2cap_no_conn_pending(chan))
14541455
return;
14551456

1456-
if (l2cap_check_enc_key_size(conn->hcon))
1457+
if (l2cap_check_enc_key_size(conn->hcon, chan))
14571458
l2cap_start_connection(chan);
14581459
else
14591460
__set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
@@ -1528,7 +1529,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
15281529
continue;
15291530
}
15301531

1531-
if (l2cap_check_enc_key_size(conn->hcon))
1532+
if (l2cap_check_enc_key_size(conn->hcon, chan))
15321533
l2cap_start_connection(chan);
15331534
else
15341535
l2cap_chan_close(chan, ECONNREFUSED);
@@ -3992,7 +3993,7 @@ static void l2cap_connect(struct l2cap_conn *conn, struct l2cap_cmd_hdr *cmd,
39923993
/* Check if the ACL is secure enough (if not SDP) */
39933994
if (psm != cpu_to_le16(L2CAP_PSM_SDP) &&
39943995
(!hci_conn_check_link_mode(conn->hcon) ||
3995-
!l2cap_check_enc_key_size(conn->hcon))) {
3996+
!l2cap_check_enc_key_size(conn->hcon, pchan))) {
39963997
conn->disc_reason = HCI_ERROR_AUTH_FAILURE;
39973998
result = L2CAP_CR_SEC_BLOCK;
39983999
goto response;
@@ -7352,7 +7353,7 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
73527353
}
73537354

73547355
if (chan->state == BT_CONNECT) {
7355-
if (!status && l2cap_check_enc_key_size(hcon))
7356+
if (!status && l2cap_check_enc_key_size(hcon, chan))
73567357
l2cap_start_connection(chan);
73577358
else
73587359
__set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
@@ -7362,7 +7363,7 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
73627363
struct l2cap_conn_rsp rsp;
73637364
__u16 res, stat;
73647365

7365-
if (!status && l2cap_check_enc_key_size(hcon)) {
7366+
if (!status && l2cap_check_enc_key_size(hcon, chan)) {
73667367
if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
73677368
res = L2CAP_CR_PEND;
73687369
stat = L2CAP_CS_AUTHOR_PEND;

0 commit comments

Comments
 (0)