Bluetooth: Fix SMP support for encryption key refresh
Subsystems (2)
cover Bluetooth: Fix SMP support for encryption key refresh
Hi,
These two patches are necessary for elevating the security level from medium (unauthenticated) to high (authenticated), aka. encryption key refresh.
Johan
PATCH 1/2 Bluetooth: Fix SMP security elevation from medium to high
From: Johan Hedberg <[email protected]>
If we have an unauthenticated key it is not sufficient to acheive high security. Therefore, when deciding whether to encrypt the link or request pairing, it is essential to in addition to checking the existence of a key to also check whether it is authenticated or not.
--- net/bluetooth/smp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/bluetooth/smp.c +6 -3
@@ -704,7 +704,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)return 0 ; } -static u8 smp_ltk_encrypt (struct l2cap_conn *conn) +static u8 smp_ltk_encrypt (struct l2cap_conn *conn,u8 sec_level) {struct smp_ltk *key;struct hci_conn *hcon = conn->hcon;
@@ -713,6 +713,9 @@ static u8 smp_ltk_encrypt(struct l2cap_conn *conn)if (!key)return 0 ; +if (sec_level >BT_SECURITY_MEDIUM && !key->authenticated) +return 0 ; +if (test_and_set_bit (HCI_CONN_ENCRYPT_PEND , &hcon->flags))return 1 ;
@@ -733,7 +736,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) hcon->pending_sec_level =authreq_to_seclevel (rp->auth_req); -if (smp_ltk_encrypt (conn)) +if (smp_ltk_encrypt (conn, hcon->pending_sec_level))return 0 ;if (test_and_set_bit (HCI_CONN_LE_SMP_PEND , &hcon->flags))
@@ -772,7 +775,7 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)return 1 ;if (hcon->link_mode &HCI_LM_MASTER ) -if (smp_ltk_encrypt (conn)) +if (smp_ltk_encrypt (conn, sec_level)) goto done;if (test_and_set_bit (HCI_CONN_LE_SMP_PEND , &hcon->flags))
Signature · 1 line
1.7.10
Re: [PATCH 1/2] Bluetooth: Fix SMP security elevation from medium to high
Hi Johan,
Quoted 11 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
If we have an unauthenticated key it is not sufficient to acheive high security. Therefore, when deciding whether to encrypt the link or request pairing, it is essential to in addition to checking the existence of a key to also check whether it is authenticated or not.
Signed-off-by Johan Hedberg <[email protected]>--- net/bluetooth/smp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Patch has been applied to bluetooth.git. Thanks.
Gustavo
PATCH 2/2 Bluetooth: Add support for encryption key refresh
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
With LE/SMP the completion of a security level elavation from medium to high is indicated by a HCI Encryption Key Refresh complete event. The necessary behavior upon receiving this event is a mix of what's done for auth_complete and encryption_change, which is also where most of the event handling code has been copied from.
--- include/net/bluetooth/hci.h | 6 ++++++ net/bluetooth/hci_event.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
include/net/bluetooth/hci.h +6 -0
@@ -1195,6 +1195,12 @@ struct extended_inquiry_info {__u8 data[240 ]; } __packed; +#define HCI_EV_KEY_REFRESH_COMPLETE 0x30 +struct hci_ev_key_refresh_complete { +__u8 status; +__le16 handle; +} __packed; +#define HCI_EV_IO_CAPA_REQUEST 0x31struct hci_ev_io_capa_request {bdaddr_t bdaddr;
net/bluetooth/hci_event.c +48 -0
60 lines not on this page · raw message
Signature · 1 line
1.7.10
Re: [PATCH 2/2] Bluetooth: Add support for encryption key refresh
Hi Johan,
Quoted 9 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
With LE/SMP the completion of a security level elavation from medium to high is indicated by a HCI Encryption Key Refresh complete event. The necessary behavior upon receiving this event is a mix of what's done for
auth_completeandencryption_change, which is also where most of the event handling code has been copied from.Signed-off-by Johan Hedberg <[email protected]>
...
Quoted 26 lines
net/bluetooth/hci_event.c +26
-0+static void hci_key_refresh_complete_evt (struct hci_dev *hdev, +struct sk_buff *skb) +{ +struct hci_ev_key_refresh_complete *ev = (void *) skb->data; +struct hci_conn *conn; + +BT_DBG ("%s status %u handle %u" , hdev->name, ev->status, +__le16_to_cpu (ev->handle)); + +hci_dev_lock (hdev); + + conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (ev->handle)); +if (!conn) + goto unlock; + +if (!ev->status) + conn->sec_level = conn->pending_sec_level; + +clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags); + +if (ev->status && conn->state ==BT_CONNECTED ) { +hci_acl_disconn (conn,HCI_ERROR_AUTH_FAILURE ); +hci_conn_put (conn); + goto unlock; + } +
net/bluetooth/hci_event.c static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, · line 3078
Quoted 10 lines
net/bluetooth/hci_event.c +10
-0+if (conn->state ==BT_CONFIG ) { +if (!ev->status) + conn->state =BT_CONNECTED ; + +hci_proto_connect_cfm (conn, ev->status); +hci_conn_put (conn); + }else { +hci_auth_cfm (conn, ev->status); + +hci_conn_hold (conn);
If you want to keep extra hold(conn) you may just not put. Is this typo?
net/bluetooth/hci_event.c static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, · line 3081
Quoted 3 lines
net/bluetooth/hci_event.c +3
-0+ conn->disc_timeout =HCI_DISCONN_TIMEOUT ; +hci_conn_put (conn); + }
Best regards
Andrei Emeltchenko
Re: [PATCH 2/2] Bluetooth: Add support for encryption key refresh
Hi Andrei,
Quoted 13 lines · Andrei Emeltchenko
net/bluetooth/hci_event.c static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, · line 3078
Quoted 10 lines
net/bluetooth/hci_event.c +10
-0+if (conn->state ==BT_CONFIG ) { +if (!ev->status) + conn->state =BT_CONNECTED ; + +hci_proto_connect_cfm (conn, ev->status); +hci_conn_put (conn); + }else { +hci_auth_cfm (conn, ev->status); + +hci_conn_hold (conn);If you want to keep extra hold(conn) you may just not put. Is this typo?
Quoted 3 lines
net/bluetooth/hci_event.c static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, · line 3081
Quoted 3 lines
net/bluetooth/hci_event.c +3
-0+ conn->disc_timeout =HCI_DISCONN_TIMEOUT ; +hci_conn_put (conn); + }
This is just copy-paste from hci_auth_complete_evt(). I think the intention of the hold+put is to restart or remove the disconnect timer with the new disc_timeout value or something similar. If the code above needs fixing then so does the code in hci_auth_complete_evt().
Johan
Re: [PATCH 2/2] Bluetooth: Add support for encryption key refresh
Hi Johan,
Quoted 14 lines · Johan Hedberg
Quoted 13 lines · Andrei Emeltchenko
net/bluetooth/hci_event.c static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, · line 3078
Quoted 10 lines
net/bluetooth/hci_event.c +10
-0+if (conn->state ==BT_CONFIG ) { +if (!ev->status) + conn->state =BT_CONNECTED ; + +hci_proto_connect_cfm (conn, ev->status); +hci_conn_put (conn); + }else { +hci_auth_cfm (conn, ev->status); + +hci_conn_hold (conn);If you want to keep extra hold(conn) you may just not put. Is this typo?
Quoted 8 lines
Quoted 3 lines
net/bluetooth/hci_event.c static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, · line 3081
Quoted 3 lines
net/bluetooth/hci_event.c +3
-0+ conn->disc_timeout =HCI_DISCONN_TIMEOUT ; +hci_conn_put (conn); + }This is just copy-paste from
hci_auth_complete_evt(). I think the intention of the hold+put is to restart or remove the disconnect timer with the newdisc_timeoutvalue or something similar. If the code above needs fixing then so does the code inhci_auth_complete_evt().
OK. Got it. Seems that cancel_delayed_work(&conn->disc_work); is enough here.
Best regards
Andrei Emeltchenko
Re: [PATCH 2/2] Bluetooth: Add support for encryption key refresh
In reply to Johan HedbergHi Johan,
Quoted 8 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
With LE/SMP the completion of a security level elavation from medium to high is indicated by a HCI Encryption Key Refresh complete event. The necessary behavior upon receiving this event is a mix of what's done for
auth_completeandencryption_change, which is also where most of the event handling code has been copied from.
Quoted 5 lines
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci.h | 6 ++++++ net/bluetooth/hci_event.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
This patch look ok to me, but if we want to get it into bluetooth.git we need a rebased version here.
Gustavo
PATCH v2 1/1 Bluetooth: Add support for encryption key refresh
From: Johan Hedberg <[email protected]>
With LE/SMP the completion of a security level elavation from medium to high is indicated by a HCI Encryption Key Refresh Complete event. The necessary behavior upon receiving this event is a mix of what's done for auth_complete and encryption_change, which is also where most of the event handling code has been copied from.
---
v2: Rebased on top of latest bluetooth.git
include/net/bluetooth/hci.h | 6 ++++++ net/bluetooth/hci_event.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
include/net/bluetooth/hci.h +6 -0
@@ -1144,6 +1144,12 @@ struct extended_inquiry_info {__u8 data[240 ]; } __packed; +#define HCI_EV_KEY_REFRESH_COMPLETE 0x30 +struct hci_ev_key_refresh_complete { +__u8 status; +__le16 handle; +} __packed; +#define HCI_EV_IO_CAPA_REQUEST 0x31struct hci_ev_io_capa_request {bdaddr_t bdaddr;
net/bluetooth/hci_event.c +48 -0
60 lines not on this page · raw message
Signature · 1 line
1.7.10
Re: [PATCH v2] Bluetooth: Add support for encryption key refresh
Hi Johan,
Quoted 8 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
With LE/SMP the completion of a security level elavation from medium to high is indicated by a HCI Encryption Key Refresh Complete event. The necessary behavior upon receiving this event is a mix of what's done for
auth_completeandencryption_change, which is also where most of the event handling code has been copied from.
Quoted 7 lines
Signed-off-by Johan Hedberg <[email protected]>---
v2: Rebased on top of latest bluetooth.gitinclude/net/bluetooth/hci.h | 6 ++++++ net/bluetooth/hci_event.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
Patch has been applied to bluetooth.git. Thanks.
Gustavo