Skip to contentSkip to conversation

Bluetooth: SMP: Fix not generating mackey and ltk when repairing

PATCH Superseded Luiz Augusto von Dentz 3 participants 5 messages Nov 17, 2025 – Nov 18, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: SMP: Fix not generating mackey and ltk when repairing

From: Luiz Augusto von Dentz <[email protected]>

The change eed467b517e8 ("Bluetooth: fix passkey uninitialized when used") introduced a goto that bypasses the creation of temporary mackey and ltk which are later used by the likes of DHKey Check step.

Later ffee202a78c2 ("Bluetooth: Always request for user confirmation for Just Works (LE SC)") which means confirm_hint is always set in case JUST_WORKS so the branch checking for an existing LTK becomes pointless as confirm_hint will always be set, so this just merge both cases of malicius or legimate devices to be confirmed before continuing with the pairing procedure.

Link github.com/bluez/bluez/issues/1622
Fixes eed467b517e8 ("Bluetooth: fix passkey uninitialized when used")
---
 net/bluetooth/smp.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)
net/bluetooth/smp.c +8 -22
index 45512b2ba951..08461ca06cde 100644
@@ -2136,7 +2136,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
 	struct smp_chan *smp = chan->data;
 	struct hci_conn *hcon = conn->hcon;
 	u8 *pkax, *pkbx, *na, *nb, confirm_hint;
-	u32 passkey;
+	u32 passkey = 0;
 	int err;
 
 	bt_dev_dbg(hcon->hdev, "conn %p", conn);
@@ -2188,24 +2188,6 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
 		smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd),
 			     smp->prnd);
 		SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK);
-
-		/* Only Just-Works pairing requires extra checks */
-		if (smp->method != JUST_WORKS)
-			goto mackey_and_ltk;
-
-		/* If there already exists long term key in local host, leave
-		 * the decision to user space since the remote device could
-		 * be legitimate or malicious.
-		 */
-		if (hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type,
-				 hcon->role)) {
-			/* Set passkey to 0. The value can be any number since
-			 * it'll be ignored anyway.
-			 */
-			passkey = 0;
-			confirm_hint = 1;
-			goto confirm;
-		}
 	}
 
 mackey_and_ltk:
@@ -2226,11 +2208,15 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
 	if (err)
 		return SMP_UNSPECIFIED;
 
-	confirm_hint = 0;
-
-confirm:
+	/* Always require user confirmation for Just-Works pairing to prevent
+	 * impersonation attacks, or in case of a legitimate device that is
+	 * repairing use the confimation to as and indication to proceed with
+	 * the creation of new keys.
+	 */
 	if (smp->method == JUST_WORKS)
 		confirm_hint = 1;
+	else
+		confirm_hint = 0;
 
 	err = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, hcon->type,
 					hcon->dst_type, passkey, confirm_hint);
Signature · 1 line
2.51.1
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1024463

---Test result---

Test Summary:

CheckPatch                    PENDING   0.43 seconds
GitLint                       PENDING   0.43 seconds
SubjectPrefix                 PASS      0.06 seconds
BuildKernel                   PASS      25.50 seconds
CheckAllWarning               PASS      27.77 seconds
CheckSparse                   PASS      31.76 seconds
BuildKernel32                 PASS      25.53 seconds
TestRunnerSetup               PASS      552.29 seconds
TestRunner_l2cap-tester       PASS      24.34 seconds
TestRunner_iso-tester         PASS      88.22 seconds
TestRunner_bnep-tester        PASS      6.13 seconds
TestRunner_mgmt-tester        FAIL      112.14 seconds
TestRunner_rfcomm-tester      PASS      9.30 seconds
TestRunner_sco-tester         PASS      14.44 seconds
TestRunner_ioctl-tester       PASS      9.91 seconds
TestRunner_mesh-tester        FAIL      11.54 seconds
TestRunner_smp-tester         PASS      8.49 seconds
TestRunner_userchan-tester    PASS      6.48 seconds
IncrementalBuild              PENDING   0.86 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 494, Passed: 488 (98.8%), Failed: 2, Not Run: 4

Failed Test Cases

Read Exp Feature - Success                           Failed       0.105 seconds
LL Privacy - Add Device 3 (AL is full)               Failed       0.182 seconds

##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases

Mesh - Send cancel - 1                               Timed out    1.966 seconds
Mesh - Send cancel - 2                               Timed out    1.997 seconds

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

Reviewed-by on v1 1/1
#2 lore raw
In reply to Luiz Augusto von Dentz

Dear Luiz,

Thank you for your patch.

Am 17.11.25 um 20:02 schrieb Luiz Augusto von Dentz:

Quoted 11 lines

From: Luiz Augusto von Dentz <[email protected]>

The change eed467b517e8 ("Bluetooth: fix passkey uninitialized when used") introduced a goto that bypasses the creation of temporary mackey and ltk which are later used by the likes of DHKey Check step.

Later ffee202a78c2 ("Bluetooth: Always request for user confirmation for Just Works (LE SC)") which means confirm_hint is always set in case JUST_WORKS so the branch checking for an existing LTK becomes pointless as confirm_hint will always be set, so this just merge both cases of malicius or legimate devices to be confirmed before continuing with the

malicious
legitimate

Quoted 3 lines

pairing procedure.

Link github.com/bluez/bluez/issues/1622

Add https://

Quoted 45 lines
Fixes eed467b517e8 ("Bluetooth: fix passkey uninitialized when used")
---
  net/bluetooth/smp.c | 30 ++++++++----------------------
  1 file changed, 8 insertions(+), 22 deletions(-)
net/bluetooth/smp.c +1 -19
index 45512b2ba951..08461ca06cde 100644
@@ -2136,7 +2136,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
  	struct smp_chan *smp = chan->data;
  	struct hci_conn *hcon = conn->hcon;
  	u8 *pkax, *pkbx, *na, *nb, confirm_hint;
-	u32 passkey;
+	u32 passkey = 0;
  	int err;
 
  	bt_dev_dbg(hcon->hdev, "conn %p", conn);
@@ -2188,24 +2188,6 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
  		smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd),
  			     smp->prnd);
  		SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK);
-
-		/* Only Just-Works pairing requires extra checks */
-		if (smp->method != JUST_WORKS)
-			goto mackey_and_ltk;
-
-		/* If there already exists long term key in local host, leave
-		 * the decision to user space since the remote device could
-		 * be legitimate or malicious.
-		 */
-		if (hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type,
-				 hcon->role)) {
-			/* Set passkey to 0. The value can be any number since
-			 * it'll be ignored anyway.
-			 */
-			passkey = 0;
-			confirm_hint = 1;
-			goto confirm;
-		}
  	}
 
  mackey_and_ltk:

net/bluetooth/smp.c static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) · line 2213

Quoted 9 lines
net/bluetooth/smp.c +3 -3
@@ -2226,11 +2208,15 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
  	if (err)
  		return SMP_UNSPECIFIED;
 
-	confirm_hint = 0;
-
-confirm:
+	/* Always require user confirmation for Just-Works pairing to prevent
+	 * impersonation attacks, or in case of a legitimate device that is
+	 * repairing use the confimation to as and indication to proceed with

confirmation

net/bluetooth/smp.c static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) · line 2219

Quoted 6 lines
net/bluetooth/smp.c +4 -0
+	 * the creation of new keys.
+	 */
  	if (smp->method == JUST_WORKS)
  		confirm_hint = 1;
+	else
+		confirm_hint = 0;

Use ternary operator?

net/bluetooth/smp.c static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) · line 2222

Quoted 3 lines
net/bluetooth/smp.c +0 -0
  	err = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, hcon->type,
  					hcon->dst_type, passkey, confirm_hint);

Kind regards,

Paul

author maintainer
#3 lore raw

Hi Paul,

Quoted 92 lines · Paul Menzel

Dear Luiz,

Thank you for your patch.

Am 17.11.25 um 20:02 schrieb Luiz Augusto von Dentz:

Quoted 11 lines

From: Luiz Augusto von Dentz <[email protected]>

The change eed467b517e8 ("Bluetooth: fix passkey uninitialized when used") introduced a goto that bypasses the creation of temporary mackey and ltk which are later used by the likes of DHKey Check step.

Later ffee202a78c2 ("Bluetooth: Always request for user confirmation for Just Works (LE SC)") which means confirm_hint is always set in case JUST_WORKS so the branch checking for an existing LTK becomes pointless as confirm_hint will always be set, so this just merge both cases of malicius or legimate devices to be confirmed before continuing with the

malicious
legitimate

Quoted 3 lines

pairing procedure.

Link github.com/bluez/bluez/issues/1622

Add https://

Quoted 45 lines
Fixes eed467b517e8 ("Bluetooth: fix passkey uninitialized when used")
---
  net/bluetooth/smp.c | 30 ++++++++----------------------
  1 file changed, 8 insertions(+), 22 deletions(-)
net/bluetooth/smp.c +1 -19
index 45512b2ba951..08461ca06cde 100644
@@ -2136,7 +2136,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
      struct smp_chan *smp = chan->data;
      struct hci_conn *hcon = conn->hcon;
      u8 *pkax, *pkbx, *na, *nb, confirm_hint;
-     u32 passkey;
+     u32 passkey = 0;
      int err;
 
      bt_dev_dbg(hcon->hdev, "conn %p", conn);
@@ -2188,24 +2188,6 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
              smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd),
                           smp->prnd);
              SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK);
-
-             /* Only Just-Works pairing requires extra checks */
-             if (smp->method != JUST_WORKS)
-                     goto mackey_and_ltk;
-
-             /* If there already exists long term key in local host, leave
-              * the decision to user space since the remote device could
-              * be legitimate or malicious.
-              */
-             if (hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type,
-                              hcon->role)) {
-                     /* Set passkey to 0. The value can be any number since
-                      * it'll be ignored anyway.
-                      */
-                     passkey = 0;
-                     confirm_hint = 1;
-                     goto confirm;
-             }
      }
 
  mackey_and_ltk:

net/bluetooth/smp.c static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) · line 2213

Quoted 9 lines
net/bluetooth/smp.c +3 -3
@@ -2226,11 +2208,15 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
      if (err)
              return SMP_UNSPECIFIED;
 
-     confirm_hint = 0;
-
-confirm:
+     /* Always require user confirmation for Just-Works pairing to prevent
+      * impersonation attacks, or in case of a legitimate device that is
+      * repairing use the confimation to as and indication to proceed with

confirmation

net/bluetooth/smp.c static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) · line 2219

Quoted 6 lines
net/bluetooth/smp.c +4 -0
+      * the creation of new keys.
+      */
      if (smp->method == JUST_WORKS)
              confirm_hint = 1;
+     else
+             confirm_hint = 0;
Quoted 7 lines

Use ternary operator?

net/bluetooth/smp.c static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) · line 2222

Quoted 3 lines
net/bluetooth/smp.c +0 -0
      err = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, hcon->type,
                                      hcon->dst_type, passkey, confirm_hint);

Will fix the comments above, thanks for the review.

Quoted 4 lines

Kind regards,

Paul

Signature · 1 line
Luiz Augusto von Dentz
author maintainer
#4 lore raw
In reply to Luiz Augusto von Dentz

Hi Howard, Sonny,

Quoted 7 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

The change eed467b517e8 ("Bluetooth: fix passkey uninitialized when used") introduced a goto that bypasses the creation of temporary mackey and ltk which are later used by the likes of DHKey Check step.

Quoted 6 lines

Later ffee202a78c2 ("Bluetooth: Always request for user confirmation for Just Works (LE SC)") which means confirm_hint is always set in case JUST_WORKS so the branch checking for an existing LTK becomes pointless as confirm_hint will always be set, so this just merge both cases of malicius or legimate devices to be confirmed before continuing with the pairing procedure.

Not sure if you guys still have any setup where to check if the following changes make sense.

Quoted 67 lines
Link github.com/bluez/bluez/issues/1622
Fixes eed467b517e8 ("Bluetooth: fix passkey uninitialized when used")
---
 net/bluetooth/smp.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)
net/bluetooth/smp.c +8 -23
index 45512b2ba951..08461ca06cde 100644
@@ -2136,7 +2136,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
        struct smp_chan *smp = chan->data;
        struct hci_conn *hcon = conn->hcon;
        u8 *pkax, *pkbx, *na, *nb, confirm_hint;
-       u32 passkey;
+       u32 passkey = 0;
        int err;
 
        bt_dev_dbg(hcon->hdev, "conn %p", conn);
@@ -2188,24 +2188,6 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
                smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd),
                             smp->prnd);
                SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK);
-
-               /* Only Just-Works pairing requires extra checks */
-               if (smp->method != JUST_WORKS)
-                       goto mackey_and_ltk;
-
-               /* If there already exists long term key in local host, leave
-                * the decision to user space since the remote device could
-                * be legitimate or malicious.
-                */
-               if (hci_find_ltk(hcon->hdev, &hcon->dst, hcon->dst_type,
-                                hcon->role)) {
-                       /* Set passkey to 0. The value can be any number since
-                        * it'll be ignored anyway.
-                        */
-                       passkey = 0;
-                       confirm_hint = 1;
-                       goto confirm;
-               }
        }
 
 mackey_and_ltk:
@@ -2226,11 +2208,15 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
        if (err)
                return SMP_UNSPECIFIED;
 
-       confirm_hint = 0;
-
-confirm:
+       /* Always require user confirmation for Just-Works pairing to prevent
+        * impersonation attacks, or in case of a legitimate device that is
+        * repairing use the confimation to as and indication to proceed with
+        * the creation of new keys.
+        */
        if (smp->method == JUST_WORKS)
                confirm_hint = 1;
+       else
+               confirm_hint = 0;
 
        err = mgmt_user_confirm_request(hcon->hdev, &hcon->dst, hcon->type,
                                        hcon->dst_type, passkey, confirm_hint);
--

2.51.1

Signature · 1 line
Luiz Augusto von Dentz