Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH bluetooth v1] Bluetooth: hci_core: Initialize link key before publication
@ 2026-10-19  8:17 Binbin Deng
  2026-10-19 14:41 ` [v1] " bluez.test.bot
  2026-10-20 18:20 ` [PATCH bluetooth v1] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Binbin Deng @ 2026-10-19  8:17 UTC (permalink / raw)
  To: marcel, luiz.dentz, johan.hedberg
  Cc: linux-bluetooth, linux-kernel, Binbin Deng

hci_add_link_key() allocates a new link key with kzalloc(), inserts it into
hdev->link_keys with list_add_rcu(), and only then initializes its address,
value, type, and PIN length.  RCU readers such as hci_find_link_key()
and the debugfs link_keys_show() do not take hci_dev_lock, so they can
traverse the new entry during that initialization window and observe
a zero or partially initialized key.

This can be triggered by racing a link-key update with another CPU looking
up or dumping keys.  In particular, userspace can issue
MGMT_OP_LOAD_LINK_KEYS while another process reads the corresponding
debugfs file.

Complete all fields of a newly allocated key before publishing it with
list_add_rcu().  Existing keys remain visible and keep their current
in-place update behavior.

Found during a static-analysis-assisted audit: candidate sites were
surfaced by a Coccinelle rule, and the reader/writer paths were
confirmed by LLM-assisted (GLM-5.3) code inspection.  The issue was
not observed at runtime; it is identified by code inspection only.

Fixes: 0378b5977013 ("Bluetooth: Convert link keys list to use RCU")
Signed-off-by: Binbin Deng <18983559317@163.com>
---
 net/bluetooth/hci_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d183efaf9063..06313211f48e 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1252,7 +1252,6 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
 		key = kzalloc_obj(*key);
 		if (!key)
 			return NULL;
-		list_add_rcu(&key->list, &hdev->link_keys);
 	}
 
 	BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type);
@@ -1276,6 +1275,9 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
 	else
 		key->type = type;
 
+	if (!old_key)
+		list_add_rcu(&key->list, &hdev->link_keys);
+
 	if (persistent)
 		*persistent = hci_persistent_key(hdev, conn, type,
 						 old_key_type);
-- 
2.43.0


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

* RE: [v1] Bluetooth: hci_core: Initialize link key before publication
  2026-10-19  8:17 [PATCH bluetooth v1] Bluetooth: hci_core: Initialize link key before publication Binbin Deng
@ 2026-10-19 14:41 ` bluez.test.bot
  2026-10-20 18:20 ` [PATCH bluetooth v1] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-10-19 14:41 UTC (permalink / raw)
  To: linux-bluetooth, 18983559317

[-- Attachment #1: Type: text/plain, Size: 1605 bytes --]

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/series/1188682/

---Test result---

Test Summary:
CheckPatch                    PASS      0.77 seconds
VerifyFixes                   PASS      0.13 seconds
VerifySignedoff               PASS      0.13 seconds
GitLint                       PASS      0.36 seconds
SubjectPrefix                 PASS      0.12 seconds
BuildKernel                   PASS      29.24 seconds
CheckAllWarning               PASS      33.50 seconds
CheckSparse                   PASS      38.88 seconds
BuildKernel32                 PASS      29.36 seconds
CheckKernelLLVM               PASS      35.32 seconds
TestRunnerSetup               PASS      700.43 seconds
TestRunner_l2cap-tester       PASS      12.55 seconds
TestRunner_iso-tester         PASS      10.64 seconds
TestRunner_bnep-tester        PASS      3.13 seconds
TestRunner_mgmt-tester        PASS      87.35 seconds
TestRunner_rfcomm-tester      PASS      4.48 seconds
TestRunner_sco-tester         PASS      5.61 seconds
TestRunner_ioctl-tester       PASS      4.64 seconds
TestRunner_mesh-tester        PASS      5.50 seconds
TestRunner_smp-tester         PASS      4.34 seconds
TestRunner_userchan-tester    PASS      3.21 seconds
TestRunner_6lowpan-tester     PASS      4.45 seconds
IncrementalBuild              PASS      28.11 seconds



https://github.com/bluez/bluetooth-next/pull/963

---
Regards,
Linux Bluetooth


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

* Re: [PATCH bluetooth v1] Bluetooth: hci_core: Initialize link key before publication
  2026-10-19  8:17 [PATCH bluetooth v1] Bluetooth: hci_core: Initialize link key before publication Binbin Deng
  2026-10-19 14:41 ` [v1] " bluez.test.bot
@ 2026-10-20 18:20 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-10-20 18:20 UTC (permalink / raw)
  To: Binbin Deng
  Cc: marcel, luiz.dentz, johan.hedberg, linux-bluetooth, linux-kernel

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 19 Oct 2026 16:17:11 +0800 you wrote:
> hci_add_link_key() allocates a new link key with kzalloc(), inserts it into
> hdev->link_keys with list_add_rcu(), and only then initializes its address,
> value, type, and PIN length.  RCU readers such as hci_find_link_key()
> and the debugfs link_keys_show() do not take hci_dev_lock, so they can
> traverse the new entry during that initialization window and observe
> a zero or partially initialized key.
> 
> [...]

Here is the summary with links:
  - [v1] Bluetooth: hci_core: Initialize link key before publication
    https://git.kernel.org/bluetooth/bluetooth-next/c/153c30aec42d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-10-20 18:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19  8:17 [PATCH bluetooth v1] Bluetooth: hci_core: Initialize link key before publication Binbin Deng
2026-10-19 14:41 ` [v1] " bluez.test.bot
2026-10-20 18:20 ` [PATCH bluetooth v1] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox