linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Bluetooth: Add flag to track STK encryption
@ 2014-07-01 16:02 johan.hedberg
  2014-07-01 16:02 ` [PATCH 2/2] Bluetooth: Allow re-encryption with LTK when STK is in use johan.hedberg
  2014-07-01 16:09 ` [PATCH 1/2] Bluetooth: Add flag to track STK encryption Marcel Holtmann
  0 siblings, 2 replies; 3+ messages in thread
From: johan.hedberg @ 2014-07-01 16:02 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

There are certain subtle differences in behavior when we're encrypted
with the STK, such as allowing re-encryption even though the security
level stays the same. Because of this, add a flag to track whether we're
encrypted with an STK or not.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h | 1 +
 net/bluetooth/hci_event.c        | 3 +++
 net/bluetooth/smp.c              | 4 ++++
 3 files changed, 8 insertions(+)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index eb0add396595..9078da681f16 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -536,6 +536,7 @@ enum {
 	HCI_CONN_AUTH,
 	HCI_CONN_SECURE,
 	HCI_CONN_FIPS,
+	HCI_CONN_STK_ENCRYPT,
 };
 
 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8097559ebb48..b0b760dd66a3 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4365,8 +4365,11 @@ static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	 * using a distributed LTK.
 	 */
 	if (ltk->type == SMP_STK) {
+		set_bit(HCI_CONN_STK_ENCRYPT, &conn->flags);
 		list_del(&ltk->list);
 		kfree(ltk);
+	} else {
+		clear_bit(HCI_CONN_STK_ENCRYPT, &conn->flags);
 	}
 
 	hci_dev_unlock(hdev);
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 6ce7785a2708..de29ad74e571 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -538,6 +538,7 @@ static u8 smp_random(struct smp_chan *smp)
 
 		hci_le_start_enc(hcon, ediv, rand, stk);
 		hcon->enc_key_size = smp->enc_key_size;
+		set_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags);
 	} else {
 		u8 stk[16], auth;
 		__le64 rand = 0;
@@ -856,6 +857,9 @@ static bool smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
 	hci_le_start_enc(hcon, key->ediv, key->rand, key->val);
 	hcon->enc_key_size = key->enc_size;
 
+	/* We never store STKs for central, so clear this flag */
+	clear_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags);
+
 	return true;
 }
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Bluetooth: Allow re-encryption with LTK when STK is in use
  2014-07-01 16:02 [PATCH 1/2] Bluetooth: Add flag to track STK encryption johan.hedberg
@ 2014-07-01 16:02 ` johan.hedberg
  2014-07-01 16:09 ` [PATCH 1/2] Bluetooth: Add flag to track STK encryption Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: johan.hedberg @ 2014-07-01 16:02 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

If we're encrypted with the STK we should allow re-encryption with an
LTK even though the acheived security level is the same. This patch adds
the necessary logic to the smp_sufficient_security function which is
used to determine whether to proceed with encryption or not.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index de29ad74e571..6407b22c1a00 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -868,6 +868,14 @@ bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level)
 	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.
+	 */
+	if (test_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags))
+		return false;
+
 	if (hcon->sec_level >= sec_level)
 		return true;
 
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Bluetooth: Add flag to track STK encryption
  2014-07-01 16:02 [PATCH 1/2] Bluetooth: Add flag to track STK encryption johan.hedberg
  2014-07-01 16:02 ` [PATCH 2/2] Bluetooth: Allow re-encryption with LTK when STK is in use johan.hedberg
@ 2014-07-01 16:09 ` Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2014-07-01 16:09 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> There are certain subtle differences in behavior when we're encrypted
> with the STK, such as allowing re-encryption even though the security
> level stays the same. Because of this, add a flag to track whether we're
> encrypted with an STK or not.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> include/net/bluetooth/hci_core.h | 1 +
> net/bluetooth/hci_event.c        | 3 +++
> net/bluetooth/smp.c              | 4 ++++
> 3 files changed, 8 insertions(+)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index eb0add396595..9078da681f16 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -536,6 +536,7 @@ enum {
> 	HCI_CONN_AUTH,
> 	HCI_CONN_SECURE,
> 	HCI_CONN_FIPS,
> +	HCI_CONN_STK_ENCRYPT,
> };
> 
> static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 8097559ebb48..b0b760dd66a3 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -4365,8 +4365,11 @@ static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
> 	 * using a distributed LTK.
> 	 */
> 	if (ltk->type == SMP_STK) {
> +		set_bit(HCI_CONN_STK_ENCRYPT, &conn->flags);
> 		list_del(&ltk->list);
> 		kfree(ltk);
> +	} else {
> +		clear_bit(HCI_CONN_STK_ENCRYPT, &conn->flags);
> 	}
> 
> 	hci_dev_unlock(hdev);
> diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
> index 6ce7785a2708..de29ad74e571 100644
> --- a/net/bluetooth/smp.c
> +++ b/net/bluetooth/smp.c
> @@ -538,6 +538,7 @@ static u8 smp_random(struct smp_chan *smp)
> 
> 		hci_le_start_enc(hcon, ediv, rand, stk);
> 		hcon->enc_key_size = smp->enc_key_size;
> +		set_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags);
> 	} else {
> 		u8 stk[16], auth;
> 		__le64 rand = 0;
> @@ -856,6 +857,9 @@ static bool smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
> 	hci_le_start_enc(hcon, key->ediv, key->rand, key->val);
> 	hcon->enc_key_size = key->enc_size;
> 
> +	/* We never store STKs for central, so clear this flag */

this might better say master here.

> +	clear_bit(HCI_CONN_STK_ENCRYPT, &hcon->flags);
> +

Regards

Marcel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-01 16:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-01 16:02 [PATCH 1/2] Bluetooth: Add flag to track STK encryption johan.hedberg
2014-07-01 16:02 ` [PATCH 2/2] Bluetooth: Allow re-encryption with LTK when STK is in use johan.hedberg
2014-07-01 16:09 ` [PATCH 1/2] Bluetooth: Add flag to track STK encryption Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).