aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2019-06-22 09:47:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-06-22 12:07:39 -0400
commit693cd8ce3f882524a5d06f7800dd8492411877b3 (patch)
tree4dd842b6a37f1e1c5d0af000c6bdc6267dcd45b3
parentc356dc4b540edd6c02b409dd8cf3208ba2804c38 (diff)
Bluetooth: Fix regression with minimum encryption key size alignment
When trying to align the minimum encryption key size requirement for Bluetooth connections, it turns out doing this in a central location in the HCI connection handling code is not possible. Original Bluetooth version up to 2.0 used a security model where the L2CAP service would enforce authentication and encryption. Starting with Bluetooth 2.1 and Secure Simple Pairing that model has changed into that the connection initiator is responsible for providing an encrypted ACL link before any L2CAP communication can happen. Now connecting Bluetooth 2.1 or later devices with Bluetooth 2.0 and before devices are causing a regression. The encryption key size check needs to be moved out of the HCI connection handling into the L2CAP channel setup. To achieve this, the current check inside hci_conn_security() has been moved into l2cap_check_enc_key_size() helper function and then called from four decisions point inside L2CAP to cover all combinations of Secure Simple Pairing enabled devices and device using legacy pairing and legacy service security model. Fixes: d5bb334a8e17 ("Bluetooth: Align minimum encryption key size for LE and BR/EDR connections") Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203643 Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Cc: stable@vger.kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--net/bluetooth/hci_conn.c18
-rw-r--r--net/bluetooth/l2cap_core.c33
2 files changed, 37 insertions, 14 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 3cf0764d5793..15d1cb5aee18 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1276,14 +1276,6 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
1276 !test_bit(HCI_CONN_ENCRYPT, &conn->flags)) 1276 !test_bit(HCI_CONN_ENCRYPT, &conn->flags))
1277 return 0; 1277 return 0;
1278 1278
1279 /* The minimum encryption key size needs to be enforced by the
1280 * host stack before establishing any L2CAP connections. The
1281 * specification in theory allows a minimum of 1, but to align
1282 * BR/EDR and LE transports, a minimum of 7 is chosen.
1283 */
1284 if (conn->enc_key_size < HCI_MIN_ENC_KEY_SIZE)
1285 return 0;
1286
1287 return 1; 1279 return 1;
1288} 1280}
1289 1281
@@ -1400,8 +1392,16 @@ auth:
1400 return 0; 1392 return 0;
1401 1393
1402encrypt: 1394encrypt:
1403 if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) 1395 if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) {
1396 /* Ensure that the encryption key size has been read,
1397 * otherwise stall the upper layer responses.
1398 */
1399 if (!conn->enc_key_size)
1400 return 0;
1401
1402 /* Nothing else needed, all requirements are met */
1404 return 1; 1403 return 1;
1404 }
1405 1405
1406 hci_conn_encrypt(conn); 1406 hci_conn_encrypt(conn);
1407 return 0; 1407 return 0;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index b53acd6c9a3d..9f77432dbe38 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1341,6 +1341,21 @@ static void l2cap_request_info(struct l2cap_conn *conn)
1341 sizeof(req), &req); 1341 sizeof(req), &req);
1342} 1342}
1343 1343
1344static bool l2cap_check_enc_key_size(struct hci_conn *hcon)
1345{
1346 /* The minimum encryption key size needs to be enforced by the
1347 * host stack before establishing any L2CAP connections. The
1348 * specification in theory allows a minimum of 1, but to align
1349 * BR/EDR and LE transports, a minimum of 7 is chosen.
1350 *
1351 * This check might also be called for unencrypted connections
1352 * that have no key size requirements. Ensure that the link is
1353 * actually encrypted before enforcing a key size.
1354 */
1355 return (!test_bit(HCI_CONN_ENCRYPT, &hcon->flags) ||
1356 hcon->enc_key_size > HCI_MIN_ENC_KEY_SIZE);
1357}
1358
1344static void l2cap_do_start(struct l2cap_chan *chan) 1359static void l2cap_do_start(struct l2cap_chan *chan)
1345{ 1360{
1346 struct l2cap_conn *conn = chan->conn; 1361 struct l2cap_conn *conn = chan->conn;
@@ -1358,9 +1373,14 @@ static void l2cap_do_start(struct l2cap_chan *chan)
1358 if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)) 1373 if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE))
1359 return; 1374 return;
1360 1375
1361 if (l2cap_chan_check_security(chan, true) && 1376 if (!l2cap_chan_check_security(chan, true) ||
1362 __l2cap_no_conn_pending(chan)) 1377 !__l2cap_no_conn_pending(chan))
1378 return;
1379
1380 if (l2cap_check_enc_key_size(conn->hcon))
1363 l2cap_start_connection(chan); 1381 l2cap_start_connection(chan);
1382 else
1383 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
1364} 1384}
1365 1385
1366static inline int l2cap_mode_supported(__u8 mode, __u32 feat_mask) 1386static inline int l2cap_mode_supported(__u8 mode, __u32 feat_mask)
@@ -1439,7 +1459,10 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
1439 continue; 1459 continue;
1440 } 1460 }
1441 1461
1442 l2cap_start_connection(chan); 1462 if (l2cap_check_enc_key_size(conn->hcon))
1463 l2cap_start_connection(chan);
1464 else
1465 l2cap_chan_close(chan, ECONNREFUSED);
1443 1466
1444 } else if (chan->state == BT_CONNECT2) { 1467 } else if (chan->state == BT_CONNECT2) {
1445 struct l2cap_conn_rsp rsp; 1468 struct l2cap_conn_rsp rsp;
@@ -7490,7 +7513,7 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
7490 } 7513 }
7491 7514
7492 if (chan->state == BT_CONNECT) { 7515 if (chan->state == BT_CONNECT) {
7493 if (!status) 7516 if (!status && l2cap_check_enc_key_size(hcon))
7494 l2cap_start_connection(chan); 7517 l2cap_start_connection(chan);
7495 else 7518 else
7496 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT); 7519 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
@@ -7499,7 +7522,7 @@ static void l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
7499 struct l2cap_conn_rsp rsp; 7522 struct l2cap_conn_rsp rsp;
7500 __u16 res, stat; 7523 __u16 res, stat;
7501 7524
7502 if (!status) { 7525 if (!status && l2cap_check_enc_key_size(hcon)) {
7503 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) { 7526 if (test_bit(FLAG_DEFER_SETUP, &chan->flags)) {
7504 res = L2CAP_CR_PEND; 7527 res = L2CAP_CR_PEND;
7505 stat = L2CAP_CS_AUTHOR_PEND; 7528 stat = L2CAP_CS_AUTHOR_PEND;