Bluetooth: Bluetooth: LE CoC fixes
Subsystems (2)
v2 cover Bluetooth: Bluetooth: LE CoC fixes
Hi,
Here's v2 of this patch set, now without the l2cap_chan locking hack thanks to the nesting level patches that were already applied.
Quoted 1 line
From the original cover letter:
This patch set contains various fixes for LE CoC. The biggest functional change is in the last patch proper reaction to the insufficient authentication/encryption connection responses is implemented.
Johan
----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Fix sending incorrect LE CoC PDU in BT_CONNECT2 state
Bluetooth: Add key preference parameter to smp_sufficient_security
Bluetooth: Trigger SMP for the appropriate LE CoC errors
net/bluetooth/l2cap_core.c | 29 ++++++++++++++++++++++++++--- net/bluetooth/smp.c | 20 +++++++++++--------- net/bluetooth/smp.h | 9 ++++++++- 3 files changed, 45 insertions(+), 13 deletions(-)
PATCH v2 1/3 Bluetooth: Fix sending incorrect LE CoC PDU in BT_CONNECT2 state
From: Johan Hedberg <[email protected]>
For LE CoC L2CAP servers we don't do security level elevation during the BT_CONNECT2 state (instead LE CoC simply sends an immediate error response if the security level isn't high enough). Therefore if we get a security level change while an LE CoC channel is in the BT_CONNECT2 state we should simply do nothing.
--- net/bluetooth/l2cap_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +2 -1
@@ -7332,7 +7332,8 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)l2cap_start_connection (chan); else__set_chan_timer (chan ,L2CAP_DISC_TIMEOUT ); - }else if (chan->state ==BT_CONNECT2 ) { + }else if (chan->state ==BT_CONNECT2 && + chan->mode !=L2CAP_MODE_LE_FLOWCTL ) {struct l2cap_conn_rsp rsp;__u16 res, stat;
Signature · 1 line
2.1.0
PATCH v2 2/3 Bluetooth: Add key preference parameter to smp_sufficient_security
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
So far smp_sufficient_security() has returned false if we're encrypted with an STK but do have an LTK available. However, for the sake of LE CoC servers we do want to let the incoming connection through even though we're only encrypted with the STK.
This patch adds a key preference parameter to smp_sufficient_security() with two possible values (enum used instead of bool for readability).
--- net/bluetooth/l2cap_core.c | 3 ++- net/bluetooth/smp.c | 20 +++++++++++--------- net/bluetooth/smp.h | 9 ++++++++- 3 files changed, 21 insertions(+), 11 deletions(-)
net/bluetooth/l2cap_core.c +2 -1
@@ -5391,7 +5391,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,mutex_lock (&conn->chan_lock);l2cap_chan_lock (pchan); -if (!smp_sufficient_security (conn->hcon, pchan->sec_level)) { +if (!smp_sufficient_security (conn->hcon, pchan->sec_level, +SMP_ALLOW_STK )) { result =L2CAP_CR_AUTHENTICATION ; chan =NULL ; goto response_unlock;
net/bluetooth/smp.c +11 -9
@@ -1122,18 +1122,20 @@ static bool smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)return true; } -bool smp_sufficient_security (struct hci_conn *hcon,u8 sec_level) +bool smp_sufficient_security (struct hci_conn *hcon,u8 sec_level, +enum smp_key_pref key_pref) {if (sec_level ==BT_SECURITY_LOW )return true; -/* If we're encrypted with an STK always claim insufficient -* security. This way we allow the connection to be re-encrypted -* with an LTK, even if the LTK provides the same level of -* security. Only exception is if we don't have an LTK (e.g. -* because of key distribution bits). +/* If we're encrypted with an STK but the caller prefers using +* LTK claim insufficient security. This way we allow the +* connection to be re-encrypted with an LTK, even if the LTK +* provides the same level of security. Only exception is if we +* don't have an LTK (e.g. because of key distribution bits). */ -if (test_bit (HCI_CONN_STK_ENCRYPT , &hcon->flags) && +if (key_pref ==SMP_USE_LTK && +test_bit (HCI_CONN_STK_ENCRYPT , &hcon->flags) &&hci_find_ltk_by_addr (hcon->hdev, &hcon->dst, hcon->dst_type, hcon->role))return false;
@@ -1167,7 +1169,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)else sec_level =authreq_to_seclevel (auth); -if (smp_sufficient_security (hcon, sec_level)) +if (smp_sufficient_security (hcon, sec_level,SMP_USE_LTK ))return 0 ;if (sec_level > hcon->pending_sec_level)
@@ -1217,7 +1219,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)if (!test_bit (HCI_LE_ENABLED , &hcon->hdev->dev_flags))return 1 ; -if (smp_sufficient_security (hcon, sec_level)) +if (smp_sufficient_security (hcon, sec_level,SMP_USE_LTK ))return 1 ;if (sec_level > hcon->pending_sec_level)
net/bluetooth/smp.h +8 -1
@@ -133,8 +133,15 @@ static inline u8 smp_ltk_sec_level(struct smp_ltk *key)return BT_SECURITY_MEDIUM ; } +/* Key preferences for smp_sufficient security */ +enum smp_key_pref { +SMP_ALLOW_STK , +SMP_USE_LTK , +}; +/* SMP Commands */ -bool smp_sufficient_security (struct hci_conn *hcon,u8 sec_level); +bool smp_sufficient_security (struct hci_conn *hcon,u8 sec_level, +enum smp_key_pref key_pref);int smp_conn_security (struct hci_conn *hcon,__u8 sec_level);int smp_user_confirm_reply (struct hci_conn *conn,u16 mgmt_op,__le32 passkey);
Signature · 1 line
2.1.0
PATCH v2 3/3 Bluetooth: Trigger SMP for the appropriate LE CoC errors
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
The insufficient authentication/encryption errors indicate to the L2CAP client that it should try to elevate the security level. Since there really isn't any exception to this rule it makes sense to fully handle it on the kernel side instead of pushing the responsibility to user space.
This patch adds special handling of these two error codes and calls smp_conn_security() with the elevated security level if necessary.
--- net/bluetooth/l2cap_core.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +22 -1
@@ -5218,9 +5218,10 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn, u8 *data) {struct l2cap_le_conn_rsp *rsp = (struct l2cap_le_conn_rsp *) data; +struct hci_conn *hcon = conn->hcon;u16 dcid, mtu, mps, credits, result;struct l2cap_chan *chan; -int err; +int err, sec_level;if (cmd_len <sizeof (*rsp))return -EPROTO ;
@@ -5259,6 +5260,26 @@ static int l2cap_le_connect_rsp(struct l2cap_conn *conn,l2cap_chan_ready (chan);break ; +case L2CAP_CR_AUTHENTICATION : +case L2CAP_CR_ENCRYPTION : +/* If we already have MITM protection we can't do +* anything. +*/ +if (hcon->sec_level >BT_SECURITY_MEDIUM ) { +l2cap_chan_del (chan,ECONNREFUSED ); +break ; + } + + sec_level = hcon->sec_level +1 ; +if (chan->sec_level < sec_level) + chan->sec_level = sec_level; + +/* We'll need to send a new Connect Request */ +clear_bit (FLAG_LE_CONN_REQ_SENT , &chan->flags); + +smp_conn_security (hcon, chan->sec_level); +break ; +default :l2cap_chan_del (chan,ECONNREFUSED );break ;
Signature · 1 line
2.1.0
Marcel Holtmann
maintainerHi Johan,
Quoted 17 lines
Here's v2 of this patch set, now without the
l2cap_chanlocking hack thanks to the nesting level patches that were already applied.From the original cover letter:
This patch set contains various fixes for LE CoC. The biggest functional change is in the last patch proper reaction to the insufficient authentication/encryption connection responses is implemented.
Johan
----------------------------------------------------------------
Johan Hedberg (3):
Bluetooth: Fix sending incorrect LE CoC PDU inBT_CONNECT2state
Bluetooth: Add key preference parameter tosmp_sufficient_security
Bluetooth: Trigger SMP for the appropriate LE CoC errors
Quoted 4 lines
net/bluetooth/l2cap_core.c | 29 ++++++++++++++++++++++++++--- net/bluetooth/smp.c | 20 +++++++++++--------- net/bluetooth/smp.h | 9 ++++++++- 3 files changed, 45 insertions(+), 13 deletions(-)
all 3 patches have been applied to bluetooth-next tree.
Regards
Marcel