diff mbox series

[v2,1/2] Bluetooth: SMP: Fail if remote and local public keys are identical

Message ID 20210310221309.894602-1-luiz.dentz@gmail.com
State Superseded
Headers show
Series [v2,1/2] Bluetooth: SMP: Fail if remote and local public keys are identical | expand

Commit Message

Luiz Augusto von Dentz March 10, 2021, 10:13 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This fails the pairing procedure when both remote and local non-debug
public keys are identical.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
v2: Use crypto_memneq instead of memcmp and add a patch converting the use of
BT_ERR/BT_DBG to bt_dev_err/bt_dev_dbg.

 net/bluetooth/smp.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Marcel Holtmann March 11, 2021, 10:46 a.m. UTC | #1
Hi Luiz,

> This fails the pairing procedure when both remote and local non-debug

> public keys are identical.

> 

> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

> ---

> v2: Use crypto_memneq instead of memcmp and add a patch converting the use of

> BT_ERR/BT_DBG to bt_dev_err/bt_dev_dbg.

> 

> net/bluetooth/smp.c | 9 +++++++++

> 1 file changed, 9 insertions(+)


patch has been applied to bluetooth-next tree.

Regards

Marcel
Marcel Holtmann March 11, 2021, 10:48 a.m. UTC | #2
Hi Luiz,

> This converts instances of BT_ERR and BT_DBG to bt_dev_err and

> bt_dev_dbg which can be enabled at runtime when BT_FEATURE_DEBUG is

> enabled.

> 

> Note: Not all instances could be converted as some are exercised by

> selftest.


so you added the note and then still converted the selftests ;)

Regards

Marcel
Luiz Augusto von Dentz March 11, 2021, 9:16 p.m. UTC | #3
Hi Marcel,

On Thu, Mar 11, 2021 at 2:48 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>

> Hi Luiz,

>

> > This converts instances of BT_ERR and BT_DBG to bt_dev_err and

> > bt_dev_dbg which can be enabled at runtime when BT_FEATURE_DEBUG is

> > enabled.

> >

> > Note: Not all instances could be converted as some are exercised by

> > selftest.

>

> so you added the note and then still converted the selftests ;)

>

> Regards

>

> Marcel


Looks like I missed a few looks like I didn't have BT_SELFTEST_SMP
enabled for some reason, I will send a v2 fixing the remaining
instances.

-- 
Luiz Augusto von Dentz
diff mbox series

Patch

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index b0c1ee110eff..e03cc284161c 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -2732,6 +2732,15 @@  static int smp_cmd_public_key(struct l2cap_conn *conn, struct sk_buff *skb)
 	if (skb->len < sizeof(*key))
 		return SMP_INVALID_PARAMS;
 
+	/* Check if remote and local public keys are the same and debug key is
+	 * not in use.
+	 */
+	if (!test_bit(SMP_FLAG_DEBUG_KEY, &smp->flags) &&
+	    !crypto_memneq(key, smp->local_pk, 64)) {
+		bt_dev_err(hdev, "Remote and local public keys are identical");
+		return SMP_UNSPECIFIED;
+	}
+
 	memcpy(smp->remote_pk, key, 64);
 
 	if (test_bit(SMP_FLAG_REMOTE_OOB, &smp->flags)) {