Bluetooth: Consolidate encryption handling in hci_encrypt_cfm
PATCH 1/2 Bluetooth: Consolidate encryption handling in hci_encrypt_cfm
From: Luiz Augusto von Dentz <[email protected]>
This makes hci_encrypt_cfm calls hci_connect_cfm in case the connection state is BT_CONFIG so callers don't have to check the state.
---
AFAICT, fixing CVE 2020-10135 Bluetooth impersonation attacks have been left out for the 4.4 stable kernel. I cherry picked what I assume are the appropriate two patches missing from the 4.9 stable kernel. Please add them to upcoming 4.4 stable releases.
include/net/bluetooth/hci_core.h | 20 ++++++++++++++++++-- net/bluetooth/hci_event.c | 28 +++------------------------- 2 files changed, 21 insertions(+), 27 deletions(-)
include/net/bluetooth/hci_core.h +18 -2
@@ -1235,10 +1235,26 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) conn->security_cfm_cb (conn, status); } -static inline void hci_encrypt_cfm (struct hci_conn *conn,__u8 status, -__u8 encrypt) +static inline void hci_encrypt_cfm (struct hci_conn *conn,__u8 status) {struct hci_cb *cb; +__u8 encrypt; + +if (conn->state ==BT_CONFIG ) { +if (status) + conn->state =BT_CONNECTED ; + +hci_connect_cfm (conn, status); +hci_conn_drop (conn); +return ; + } + +if (!test_bit (HCI_CONN_ENCRYPT , &conn->flags)) + encrypt =0x00 ; +else if (test_bit (HCI_CONN_AES_CCM , &conn->flags)) + encrypt =0x02 ; +else + encrypt =0x01 ;if (conn->sec_level ==BT_SECURITY_SDP ) conn->sec_level =BT_SECURITY_LOW ;
net/bluetooth/hci_event.c +3 -25
@@ -2479,7 +2479,7 @@ static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) &cp); }else {clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags); -hci_encrypt_cfm (conn, ev->status,0x00 ); +hci_encrypt_cfm (conn, ev->status); } }
@@ -2565,22 +2565,7 @@ static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, conn->enc_key_size = rp->key_size; } -if (conn->state ==BT_CONFIG ) { - conn->state =BT_CONNECTED ; -hci_connect_cfm (conn,0 ); -hci_conn_drop (conn); - }else { -u8 encrypt; - -if (!test_bit (HCI_CONN_ENCRYPT , &conn->flags)) - encrypt =0x00 ; -else if (test_bit (HCI_CONN_AES_CCM , &conn->flags)) - encrypt =0x02 ; -else - encrypt =0x01 ; - -hci_encrypt_cfm (conn,0 , encrypt); - } +hci_encrypt_cfm (conn,0 ); unlock:hci_dev_unlock (hdev);
@@ -2674,14 +2659,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) } notify: -if (conn->state ==BT_CONFIG ) { -if (!ev->status) - conn->state =BT_CONNECTED ; - -hci_connect_cfm (conn, ev->status); -hci_conn_drop (conn); - }else -hci_encrypt_cfm (conn, ev->status, ev->encrypt); +hci_encrypt_cfm (conn, ev->status); unlock:hci_dev_unlock (hdev);
Signature · 1 line
2.27.0
PATCH 2/2 Bluetooth: Disconnect if E0 is used for Level 4
From: Luiz Augusto von Dentz <[email protected]>
E0 is not allowed with Level 4:
BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part C page 1319:
'128-bit equivalent strength for link and encryption keys
required using FIPS approved algorithms (E0 not allowed, SAFER+ not allowed, and P-192 not allowed; encryption key not shortened'
SC enabled:
Quoted 1 line
HCI Event: Read Remote Extended Features (
0x23) plen 13
Status: Success (0x00)
Handle: 256
Page: 1/2
Features: 0x0b 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Secure Simple Pairing (Host Support)
LE Supported (Host)
Secure Connections (Host Support)Quoted 1 line
HCI Event: Encryption Change (
0x08) plen 4
Status: Success (0x00)
Handle: 256
Encryption: Enabled with AES-CCM (0x02)SC disabled:
Quoted 1 line
HCI Event: Read Remote Extended Features (
0x23) plen 13
Status: Success (0x00)
Handle: 256
Page: 1/2
Features: 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Secure Simple Pairing (Host Support)
LE Supported (Host)Quoted 1 line
HCI Event: Encryption Change (
0x08) plen 4
Status: Success (0x00)
Handle: 256
Encryption: Enabled with E0 (0x01)
[May 8 20:23] Bluetooth: hci0: Invalid security: expect AES but E0 was used
< HCI Command: Disconnect (0x01|0x0006) plen 3
Handle: 256
Reason: Authentication Failure (0x05)---
AFAICT, fixing CVE 2020-10135 Bluetooth impersonation attacks have been left out for the 4.4 stable kernel. I cherry picked what I assume are the appropriate two patches missing from the 4.9 stable kernel. Please add them to upcoming 4.4 stable releases.
include/net/bluetooth/hci_core.h | 10 ++++++---- net/bluetooth/hci_conn.c | 17 +++++++++++++++++ net/bluetooth/hci_event.c | 20 ++++++++------------ 3 files changed, 31 insertions(+), 16 deletions(-)
include/net/bluetooth/hci_core.h +6 -4
@@ -1256,11 +1256,13 @@ static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status)else encrypt =0x01 ; -if (conn->sec_level ==BT_SECURITY_SDP ) - conn->sec_level =BT_SECURITY_LOW ; +if (!status) { +if (conn->sec_level ==BT_SECURITY_SDP ) + conn->sec_level =BT_SECURITY_LOW ; -if (conn->pending_sec_level > conn->sec_level) - conn->sec_level = conn->pending_sec_level; +if (conn->pending_sec_level > conn->sec_level) + conn->sec_level = conn->pending_sec_level; + }mutex_lock (&hci_cb_list_lock);list_for_each_entry (cb, &hci_cb_list, list) {
net/bluetooth/hci_conn.c +17 -0
@@ -1175,6 +1175,23 @@ int hci_conn_check_link_mode(struct hci_conn *conn)return 0 ; } +/* AES encryption is required for Level 4: +* +* BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part C +* page 1319: +* +* 128-bit equivalent strength for link and encryption keys +* required using FIPS approved algorithms (E0 not allowed, +* SAFER+ not allowed, and P-192 not allowed; encryption key +* not shortened) +*/ +if (conn->sec_level ==BT_SECURITY_FIPS && + !test_bit (HCI_CONN_AES_CCM , &conn->flags)) { +bt_dev_err (conn->hdev, +"Invalid security: Missing AES-CCM usage" ); +return 0 ; + } +if (hci_conn_ssp_enabled (conn) && !test_bit (HCI_CONN_ENCRYPT , &conn->flags))return 0 ;
net/bluetooth/hci_event.c +8 -12
@@ -2612,24 +2612,20 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags); +/* Check link security requirements are met */ +if (!hci_conn_check_link_mode (conn)) + ev->status =HCI_ERROR_AUTH_FAILURE ; +if (ev->status && conn->state ==BT_CONNECTED ) { +/* Notify upper layers so they can cleanup before +* disconnecting. +*/ +hci_encrypt_cfm (conn, ev->status);hci_disconnect (conn,HCI_ERROR_AUTH_FAILURE );hci_conn_drop (conn); goto unlock; } -/* In Secure Connections Only mode, do not allow any connections -* that are not encrypted with AES-CCM using a P-256 authenticated -* combination key. -*/ -if (hci_dev_test_flag (hdev,HCI_SC_ONLY ) && - (!test_bit (HCI_CONN_AES_CCM , &conn->flags) || - conn->key_type !=HCI_LK_AUTH_COMBINATION_P256 )) { -hci_connect_cfm (conn,HCI_ERROR_AUTH_FAILURE ); -hci_conn_drop (conn); - goto unlock; - } -/* Try reading the encryption key size for encrypted ACL links */ if (!ev->status && ev->encrypt && conn->type ==ACL_LINK ) {struct hci_cp_read_enc_key_size cp;
Signature · 1 line
2.27.0
Re: [PATCH v4.4/bluetooth 2/2] Bluetooth: Disconnect if E0 is used for Level 4
Quoted 44 lines · Hans-Christian Noren Egtvedt
From: Luiz Augusto von Dentz <[email protected]>
E0 is not allowed with Level 4:
BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part C page 1319:
'128-bit equivalent strength for link and encryption keys
required using FIPS approved algorithms (E0 not allowed, SAFER+ not allowed, and P-192 not allowed; encryption key not shortened'SC enabled:
Quoted 1 line
HCI Event: Read Remote Extended Features (
0x23) plen 13Status: Success (0x00) Handle: 256 Page: 1/2 Features: 0x0b 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Secure Simple Pairing (Host Support) LE Supported (Host) Secure Connections (Host Support)Quoted 1 line
HCI Event: Encryption Change (
0x08) plen 4Status: Success (0x00) Handle: 256 Encryption: Enabled with AES-CCM (0x02)SC disabled:
Quoted 1 line
HCI Event: Read Remote Extended Features (
0x23) plen 13Status: Success (0x00) Handle: 256 Page: 1/2 Features: 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 Secure Simple Pairing (Host Support) LE Supported (Host)Quoted 1 line
HCI Event: Encryption Change (
0x08) plen 4Status: Success (0x00) Handle: 256 Encryption: Enabled with E0 (0x01) [May 8 20:23] Bluetooth: hci0: Invalid security: expect AES but E0 was used < HCI Command: Disconnect (0x01|0x0006) plen 3 Handle: 256 Reason: Authentication Failure (0x05)
Quoted 4 lines
Signed-off-by Luiz Augusto von Dentz <[email protected]>Signed-off-by Marcel Holtmann <[email protected]>(cherry picked from commit 8746f135bb01872ff412d408ea1aa9ebd328c1f5)(cherry picked from commit f263237a1709a6dbf1dc9945187f1e64c53a4b73)
I do not see this commit in Linus's tree.
Quoted 5 lines
---
AFAICT, fixing CVE 2020-10135 Bluetooth impersonation attacks have been left out for the 4.4 stable kernel. I cherry picked what I assume are the appropriate two patches missing from the 4.9 stable kernel. Please add them to upcoming 4.4 stable releases.
Same thing as before, we need this in all kernels.
thanks,
greg k-h
Quoted 8 lines · Hans-Christian Noren Egtvedt
From: Luiz Augusto von Dentz <[email protected]>
This makes
hci_encrypt_cfmcallshci_connect_cfmin case the connection state isBT_CONFIGso callers don't have to check the state.Signed-off-by Luiz Augusto von Dentz <[email protected]>Signed-off-by Marcel Holtmann <[email protected]>(cherry picked from commit 3ca44c16b0dcc764b641ee4ac226909f5c421aa3)
This is only in 5.8, what about all the other stable kernels?
Quoted 1 line
(cherry picked from commit
0a60996c7fa7010ea00d9b62fb6996d908a01ead)
Where is this commit from? I don't see it in Linus's tree.
Quoted 5 lines
---
AFAICT, fixing CVE 2020-10135 Bluetooth impersonation attacks have been left out for the 4.4 stable kernel. I cherry picked what I assume are the appropriate two patches missing from the 4.9 stable kernel. Please add them to upcoming 4.4 stable releases.
Why are you merging 2 commits together? Please provide backports for all stable kernels, if you want to see this in the 4.4.y tree. We can not have someone move from an older tree to a newer one and have a regression.
thanks,
greg k-h
Quoted 10 lines · Greg KH
Quoted 8 lines · Hans-Christian Noren Egtvedt
From: Luiz Augusto von Dentz <[email protected]>
This makes
hci_encrypt_cfmcallshci_connect_cfmin case the connection state isBT_CONFIGso callers don't have to check the state.Signed-off-by Luiz Augusto von Dentz <[email protected]>Signed-off-by Marcel Holtmann <[email protected]>(cherry picked from commit 3ca44c16b0dcc764b641ee4ac226909f5c421aa3)
Quoted 5 lines
This is only in 5.8, what about all the other stable kernels?
Quoted 1 line
(cherry picked from commit
0a60996c7fa7010ea00d9b62fb6996d908a01ead)Where is this commit from? I don't see it in Linus's tree.
Ops, my bad, I have a Linux 4.9 branch, which also includes the Android 4.9 kernel changes from Google. And since I noticed the patches in my (merged from Android latest) linux-4.9.y branch, I thought the patches were applied through all stable releases 4.9 and up.
Quoted 10 lines
Quoted 5 lines
---
AFAICT, fixing CVE 2020-10135 Bluetooth impersonation attacks have been left out for the 4.4 stable kernel. I cherry picked what I assume are the appropriate two patches missing from the 4.9 stable kernel. Please add them to upcoming 4.4 stable releases.Why are you merging 2 commits together? Please provide backports for all stable kernels, if you want to see this in the 4.4.y tree. We can not have someone move from an older tree to a newer one and have a regression.
Agreed, I have managed to trick myself into thinking the 4.4.y branch was left out, but I assume these patches are required for all LTS branches.
That is a bigger job AFAIK, the newer branches might need additional patches. Perhaps Luiz can assist?
Signature · 1 line
Best regards, Hans-Christian Noren Egtvedt
Quoted 13 lines · Hans-Christian Egtvedt (hegtvedt)
Quoted 12 lines · Greg KH
Quoted 8 lines · Hans-Christian Noren Egtvedt
From: Luiz Augusto von Dentz <[email protected]>
This makes
hci_encrypt_cfmcallshci_connect_cfmin case the connection state isBT_CONFIGso callers don't have to check the state.Signed-off-by Luiz Augusto von Dentz <[email protected]>Signed-off-by Marcel Holtmann <[email protected]>(cherry picked from commit 3ca44c16b0dcc764b641ee4ac226909f5c421aa3)This is only in 5.8, what about all the other stable kernels?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
(cherry picked from commit
0a60996c7fa7010ea00d9b62fb6996d908a01ead)Where is this commit from? I don't see it in Linus's tree.
Ops, my bad, I have a Linux 4.9 branch, which also includes the Android 4.9 kernel changes from Google. And since I noticed the patches in my (merged from Android latest) linux-4.9.y branch, I thought the patches were applied through all stable releases 4.9 and up.
I just looked at the google common android trees, and do not see this commit in the android-4.9-q branch. What branch are you seeing it in?
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
---
AFAICT, fixing CVE 2020-10135 Bluetooth impersonation attacks have been left out for the 4.4 stable kernel. I cherry picked what I assume are the appropriate two patches missing from the 4.9 stable kernel. Please add them to upcoming 4.4 stable releases.
Quoted 7 lines
Quoted 4 lines
Why are you merging 2 commits together? Please provide backports for all stable kernels, if you want to see this in the 4.4.y tree. We can not have someone move from an older tree to a newer one and have a regression.
Agreed, I have managed to trick myself into thinking the 4.4.y branch was left out, but I assume these patches are required for all LTS branches.
They are, but if you have copies of them, please feel free to share them.
thanks,
greg k-h
Quoted 18 lines · Greg KH
Quoted 17 lines · Hans-Christian Egtvedt (hegtvedt)
Quoted 15 lines · Greg KH
Quoted 8 lines · Hans-Christian Noren Egtvedt
From: Luiz Augusto von Dentz <[email protected]>
This makes
hci_encrypt_cfmcallshci_connect_cfmin case the connection state isBT_CONFIGso callers don't have to check the state.Signed-off-by Luiz Augusto von Dentz <[email protected]>Signed-off-by Marcel Holtmann <[email protected]>(cherry picked from commit 3ca44c16b0dcc764b641ee4ac226909f5c421aa3)This is only in 5.8, what about all the other stable kernels?
Quoted 1 line
(cherry picked from commit
0a60996c7fa7010ea00d9b62fb6996d908a01ead)Where is this commit from? I don't see it in Linus's tree.
Quoted 7 lines
Quoted 4 lines
Ops, my bad, I have a Linux 4.9 branch, which also includes the Android 4.9 kernel changes from Google. And since I noticed the patches in my (merged from Android latest) linux-4.9.y branch, I thought the patches were applied through all stable releases 4.9 and up.
I just looked at the google common android trees, and do not see this commit in the android-4.9-q branch. What branch are you seeing it in?
Well this is embarrassing:
commit 0a60996c7fa7010ea00d9b62fb6996d908a01ead
Author: Luiz Augusto von Dentz <[email protected]>
Commit: Hans-Christian Noren Egtvedt <[email protected]>
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
---
AFAICT, fixing CVE 2020-10135 Bluetooth impersonation attacks have been left out for the 4.4 stable kernel. I cherry picked what I assume are the appropriate two patches missing from the 4.9 stable kernel. Please add them to upcoming 4.4 stable releases.Why are you merging 2 commits together? Please provide backports for all stable kernels, if you want to see this in the 4.4.y tree. We can not have someone move from an older tree to a newer one and have a regression.
Quoted 5 lines
Quoted 2 lines
Agreed, I have managed to trick myself into thinking the 4.4.y branch was left out, but I assume these patches are required for all LTS branches.
They are, but if you have copies of them, please feel free to share them.
I will repeat cherry-picking from a clean linux-stable git tree and send patches, sorry for this noise.
I see linux-5.8.y has partial patches, while the older branches need the full series of three commits. I just discovered an additional fix.
Signature · 1 line
Best regards, Hans-Christian Noren Egtvedt
Quoted 5 lines · Hans-Christian Egtvedt (hegtvedt)
Quoted 4 lines · Greg KH
Quoted 3 lines · Hans-Christian Egtvedt (hegtvedt)
Quoted 2 lines · Greg KH
Quoted 1 line · Hans-Christian Noren Egtvedt
From: Luiz Augusto von Dentz <[email protected]>
<snipp embarrassing reference to local commit>
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
Quoted 5 lines
---
AFAICT, fixing CVE 2020-10135 Bluetooth impersonation attacks have been left out for the 4.4 stable kernel. I cherry picked what I assume are the appropriate two patches missing from the 4.9 stable kernel. Please add them to upcoming 4.4 stable releases.Why are you merging 2 commits together? Please provide backports for all stable kernels, if you want to see this in the 4.4.y tree. We can not have someone move from an older tree to a newer one and have a regression.
Agreed, I have managed to trick myself into thinking the 4.4.y branch was left out, but I assume these patches are required for all LTS branches.
Quoted 8 lines
Quoted 2 lines
They are, but if you have copies of them, please feel free to share them.
I will repeat cherry-picking from a clean linux-stable git tree and send patches, sorry for this noise.
I see linux-5.8.y has partial patches, while the older branches need the full series of three commits. I just discovered an additional fix.
I sent three iterations.
5.8.y only requires a single cherry-pick.
4.9.y to 5.4.y has non-conflicting cherry-pick from upstream commits.
4.4.y needs to resolve a conflict when cherry-picking.
I would still want Luiz to ack that this completes the mitigation for this Bluetooth vulnerability in the stable kernels.
Signature · 1 line
Best regards, Hans-Christian Noren Egtvedt