Bluetooth: Security related fixes for SMP
Subsystems (2)
cover Bluetooth: Security related fixes for SMP
Hi,
Here's a set of patches to fix handling of MITM requirement and the pending_sec_level value for hci_conn.
Johan
----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Fix overriding higher security level in SMP
Bluetooth: Refactor authentication method lookup into its own function
Bluetooth: Fix rejecting pairing in case of insufficient capabilities
net/bluetooth/smp.c | 60 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 14 deletions(-)
PATCH 1/3 Bluetooth: Fix overriding higher security level in SMP
From: Johan Hedberg <[email protected]>
When we receive a pairing request or an internal request to start pairing we shouldn't blindly overwrite the existing pending_sec_level value as that may actually be higher than the new one. This patch fixes the SMP code to only overwrite the value in case the new one is higher than the old.
--- net/bluetooth/smp.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
net/bluetooth/smp.c +14 -9
@@ -668,7 +668,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) {struct smp_cmd_pairing rsp, *req = (void *) skb->data;struct smp_chan *smp; -u8 key_size, auth; +u8 key_size, auth, sec_level;int ret;BT_DBG ("conn %p" , conn);
@@ -694,7 +694,9 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)/* We didn't start the pairing, so match remote */ auth = req->auth_req; - conn->hcon->pending_sec_level =authreq_to_seclevel (auth); + sec_level =authreq_to_seclevel (auth); +if (sec_level > conn->hcon->pending_sec_level) + conn->hcon->pending_sec_level = sec_level;build_pairing_cmd (conn, req, &rsp, auth);
@@ -837,6 +839,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)struct smp_cmd_pairing cp;struct hci_conn *hcon = conn->hcon;struct smp_chan *smp; +u8 sec_level;BT_DBG ("conn %p" , conn);
@@ -846,7 +849,9 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)if (!(conn->hcon->link_mode &HCI_LM_MASTER ))return SMP_CMD_NOTSUPP ; - hcon->pending_sec_level =authreq_to_seclevel (rp->auth_req); + sec_level =authreq_to_seclevel (rp->auth_req); +if (sec_level > hcon->pending_sec_level) + hcon->pending_sec_level = sec_level;if (smp_ltk_encrypt (conn, hcon->pending_sec_level))return 0 ;
@@ -902,9 +907,12 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)if (smp_sufficient_security (hcon, sec_level))return 1 ; +if (sec_level > hcon->pending_sec_level) + hcon->pending_sec_level = sec_level; +if (hcon->link_mode &HCI_LM_MASTER ) -if (smp_ltk_encrypt (conn, sec_level)) - goto done; +if (smp_ltk_encrypt (conn, hcon->pending_sec_level)) +return 0 ;if (test_and_set_bit (HCI_CONN_LE_SMP_PEND , &hcon->flags))return 0 ;
@@ -919,7 +927,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)* requires it. */ if (hcon->io_capability !=HCI_IO_NO_INPUT_OUTPUT || - sec_level >BT_SECURITY_MEDIUM ) + hcon->pending_sec_level >BT_SECURITY_MEDIUM ) authreq |=SMP_AUTH_MITM ;if (hcon->link_mode &HCI_LM_MASTER ) {
@@ -938,9 +946,6 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)set_bit (SMP_FLAG_INITIATOR , &smp->flags); -done: - hcon->pending_sec_level = sec_level; -return 0 ; }
Signature · 1 line
1.9.3
PATCH 2/3 Bluetooth: Refactor authentication method lookup into its own function
In reply to [email protected]From: Johan Hedberg <[email protected]>
We'll need to do authentication method lookups from more than one place, so refactor the lookup into its own function.
--- net/bluetooth/smp.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
net/bluetooth/smp.c +12 -5
@@ -381,6 +381,16 @@ static const u8 gen_method[5][5] = { { CFM_PASSKEY, CFM_PASSKEY, REQ_PASSKEY, JUST_WORKS, OVERLAP }, }; +static u8 get_auth_method (struct smp_chan *smp,u8 local_io,u8 remote_io) +{ +/* If either side has unknown io_caps, use JUST WORKS */ +if (local_io >SMP_IO_KEYBOARD_DISPLAY || + remote_io >SMP_IO_KEYBOARD_DISPLAY ) +return JUST_WORKS ; + +return gen_method[remote_io][local_io]; +} +static int tk_request (struct l2cap_conn *conn,u8 remote_oob,u8 auth,u8 local_io,u8 remote_io) {
@@ -397,14 +407,11 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,BT_DBG ("tk_request: auth:%d lcl:%d rem:%d" , auth, local_io, remote_io);/* If neither side wants MITM, use JUST WORKS */ -/* If either side has unknown io_caps, use JUST WORKS */ /* Otherwise, look up method from the table */ -if (!(auth &SMP_AUTH_MITM ) || - local_io >SMP_IO_KEYBOARD_DISPLAY || - remote_io >SMP_IO_KEYBOARD_DISPLAY ) +if (!(auth &SMP_AUTH_MITM )) method =JUST_WORKS ;else - method = gen_method[remote_io][local_io]; + method =get_auth_method (smp, local_io, remote_io);/* If not bonding, don't ask user to confirm a Zero TK */ if (!(auth &SMP_AUTH_BONDING ) && method ==JUST_CFM )
Signature · 1 line
1.9.3
PATCH 3/3 Bluetooth: Fix rejecting pairing in case of insufficient capabilities
In reply to [email protected]From: Johan Hedberg <[email protected]>
If we need an MITM protected connection but the local and remote IO capabilities cannot provide it we should reject the pairing attempt in the appropriate way. This patch adds the missing checks for such a situation to the smp_cmd_pairing_req() and smp_cmd_pairing_req() functions.
--- net/bluetooth/smp.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
net/bluetooth/smp.c +20 -0
@@ -705,6 +705,16 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)if (sec_level > conn->hcon->pending_sec_level) conn->hcon->pending_sec_level = sec_level; +/* If we need MITM check that it can be acheived */ +if (conn->hcon->pending_sec_level >=BT_SECURITY_HIGH ) { +u8 method; + + method =get_auth_method (smp, conn->hcon->io_capability, + req->io_capability); +if (method ==JUST_WORKS || method ==JUST_CFM ) +return SMP_AUTH_REQUIREMENTS ; + } +build_pairing_cmd (conn, req, &rsp, auth); key_size =min (req->max_key_size, rsp.max_key_size);
@@ -751,6 +761,16 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)if (check_enc_key_size (conn, key_size))return SMP_ENC_KEY_SIZE ; +/* If we need MITM check that it can be acheived */ +if (conn->hcon->pending_sec_level >=BT_SECURITY_HIGH ) { +u8 method; + + method =get_auth_method (smp, req->io_capability, + rsp->io_capability); +if (method ==JUST_WORKS || method ==JUST_CFM ) +return SMP_AUTH_REQUIREMENTS ; + } +get_random_bytes (smp->prnd,sizeof (smp->prnd)); smp->prsp[0 ] =SMP_CMD_PAIRING_RSP ;
Signature · 1 line
1.9.3
Marcel Holtmann
maintainerHi Johan,
Quoted 5 lines
Here's a set of patches to fix handling of MITM requirement and the
pending_sec_levelvalue forhci_conn.Johan
Quoted 8 lines
----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Fix overriding higher security level in SMP
Bluetooth: Refactor authentication method lookup into its own function
Bluetooth: Fix rejecting pairing in case of insufficient capabilities
net/bluetooth/smp.c| 60 +++++++++++++++++++++++++++++++++++++++------------1 file changed, 46 insertions(+), 14 deletions(-)
all 3 patches have been applied to bluetooth-next tree.
Regards
Marcel