Skip to content

[PW_SID:1154463] [v2] Bluetooth: hci_core: Fix IRK lookup lifetime races - #674

Open
BluezTestBot wants to merge 6 commits into
workflowfrom
1154463
Open

[PW_SID:1154463] [v2] Bluetooth: hci_core: Fix IRK lookup lifetime races#674
BluezTestBot wants to merge 6 commits into
workflowfrom
1154463

Conversation

@BluezTestBot

Copy link
Copy Markdown

The IRK lookup helpers traverse the identity resolving key list under
RCU, but return a raw pointer after leaving the read-side critical
section. A concurrent management unpair or key reload can unlink and
free that entry while SMP key distribution still updates its value and
RPA through hci_add_irk().

RCU also does not serialize list mutations. SMP cleanup and key
distribution can update the IRK list without the hdev mutex while
management paths update it with that mutex held, allowing concurrent
list_add_rcu() and list_del_rcu() operations on the same list.

Give each IRK a list-owned reference and return caller-owned references
from lookup and add helpers. Keep the SMP context reference until pairing
teardown, and drop the list reference only once when an entry is
unlinked. Add a dedicated spinlock for IRK list and payload updates, and
copy payload snapshots under that lock so readers do not race updates.
Initialize new entries completely before publishing them. Unlink an IRK
added during unpair before dropping the SMP context reference.

Make RPA lookup and caching linearizable with duplicate-key updates.
After a cryptographic match outside the lock, revalidate the matched IRK
value while acquiring the reference, updating the cache, and taking the
payload snapshot under the lock. Perform cached-RPA matching and
reference acquisition under that lock as well. This prevents an old-key
match from caching its RPA in a replacement-key object and makes blocked
key filtering use the payload that was actually matched.

Add a CONFIG_BT_SELFTEST regression that models the exact stale-match
state and verifies that it neither acquires a reference nor changes the
replacement key's cached RPA. It also covers successful current-key cache
updates and cached lookup reference balancing.

Fixes: a7ec733 ("Bluetooth: Fix removing any IRKs when unpairing devices")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5
Signed-off-by: Kazuki Hanai hnkz.64@gmail.com

Changes in v2:

  • Use the required AGENT_NAME:MODEL_VERSION format for the Assisted-by
    trailer reported by CI.
  • Revalidate the cryptographically matched IRK under irk_lock before
    caching the RPA and acquiring the caller reference. Also make cached
    lookup, reference acquisition, and payload snapshot one locked step.
  • Add a CONFIG_BT_SELFTEST regression for an old-key lookup racing a
    replacement key update, including rejected-path reference accounting.
  • Rebuild the Bluetooth subtrees with W=1 and boot the new selftest.
    Fresh matched baseline/patched runs passed mgmt-tester IRK (6/6),
    mgmt-tester Privacy (30/30), and smp-tester (8/8) on both kernels.
  • The v1 CI failures in unrelated experimental-feature and mesh-cancel
    tests were previously reproduced on the v1 base and patched kernels;
    the handlers involved are unchanged here.

v1: https://lore.kernel.org/linux-bluetooth/20260828022549.1721170-1-hnkz.64@gmail.com/

include/net/bluetooth/hci_core.h | 19 +-
net/bluetooth/hci_conn.c | 34 +++-
net/bluetooth/hci_core.c | 311 +++++++++++++++++++++++++++----
net/bluetooth/hci_debugfs.c | 6 +-
net/bluetooth/hci_event.c | 16 +-
net/bluetooth/hci_sync.c | 16 +-
net/bluetooth/iso.c | 18 +-
net/bluetooth/mgmt.c | 12 +-
net/bluetooth/selftest.c | 4 +
net/bluetooth/selftest.h | 2 +
net/bluetooth/smp.c | 20 +-
11 files changed, 389 insertions(+), 69 deletions(-)

tedd-an and others added 6 commits August 28, 2026 00:40
This patch adds workflow files for ci:

[sync.yml]
 - The workflow file for scheduled work
 - Sync the repo with upstream repo and rebase the workflow branch
 - Review the patches in the patchwork and creates the PR if needed

[ci.yml]
 - The workflow file for CI tasks
 - Run CI tests when PR is created

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
This replaces the bzcafe action with bluez/action-ci so we can maintain
everything in the github bluez organization

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This attempts to sync every 5 minutes instead of 30.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
bluez/action-ci uses master as default branch for workflow which is
incorrect for kernel

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
The CI action now creates individual GitHub Check Runs per test, which
requires 'checks: write' permission on the GITHUB_TOKEN. Also make the
pull_request trigger types explicit to include 'reopened', allowing CI
to be retriggered by closing and reopening a PR.
The IRK lookup helpers traverse the identity resolving key list under
RCU, but return a raw pointer after leaving the read-side critical
section. A concurrent management unpair or key reload can unlink and
free that entry while SMP key distribution still updates its value and
RPA through hci_add_irk().

RCU also does not serialize list mutations. SMP cleanup and key
distribution can update the IRK list without the hdev mutex while
management paths update it with that mutex held, allowing concurrent
list_add_rcu() and list_del_rcu() operations on the same list.

Give each IRK a list-owned reference and return caller-owned references
from lookup and add helpers. Keep the SMP context reference until pairing
teardown, and drop the list reference only once when an entry is
unlinked. Add a dedicated spinlock for IRK list and payload updates, and
copy payload snapshots under that lock so readers do not race updates.
Initialize new entries completely before publishing them. Unlink an IRK
added during unpair before dropping the SMP context reference.

Make RPA lookup and caching linearizable with duplicate-key updates.
After a cryptographic match outside the lock, revalidate the matched IRK
value while acquiring the reference, updating the cache, and taking the
payload snapshot under the lock. Perform cached-RPA matching and
reference acquisition under that lock as well. This prevents an old-key
match from caching its RPA in a replacement-key object and makes blocked
key filtering use the payload that was actually matched.

Add a CONFIG_BT_SELFTEST regression that models the exact stale-match
state and verifies that it neither acquires a reference nor changes the
replacement key's cached RPA. It also covers successful current-key cache
updates and cached lookup reference balancing.

Fixes: a7ec733 ("Bluetooth: Fix removing any IRKs when unpairing devices")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5
Signed-off-by: Kazuki Hanai <hnkz.64@gmail.com>
@github-actions

Copy link
Copy Markdown

CheckPatch
Desc: Run checkpatch.pl script
Duration: 3.16 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

VerifyFixes
Desc: Verify Fixes tag format and validity
Duration: 0.09 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

VerifySignedoff
Desc: Verify Signed-off-by chain
Duration: 0.09 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

GitLint
Desc: Run gitlint
Duration: 0.25 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

SubjectPrefix
Desc: Check subject contains "Bluetooth" prefix
Duration: 0.09 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

BuildKernel
Desc: Build Kernel for Bluetooth
Duration: 29.10 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

CheckAllWarning
Desc: Run linux kernel with all warning enabled
Duration: 31.35 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

CheckSparse
Desc: Run sparse tool with linux kernel
Duration: 29.14 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

BuildKernel32
Desc: Build 32bit Kernel for Bluetooth
Duration: 28.58 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

CheckKernelLLVM
Desc: Build kernel with LLVM + context analysis
Duration: 0.00 seconds
Result: SKIP
Output:

Clang not found

@github-actions

Copy link
Copy Markdown

TestRunnerSetup
Desc: Setup kernel and bluez for test-runner
Duration: 520.73 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_l2cap-tester
Desc: Run l2cap-tester with test-runner
Duration: 64.88 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_iso-tester
Desc: Run iso-tester with test-runner
Duration: 107.44 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_bnep-tester
Desc: Run bnep-tester with test-runner
Duration: 19.44 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_mgmt-tester
Desc: Run mgmt-tester with test-runner
Duration: 229.89 seconds
Result: FAIL
Output:

Total: 501, Passed: 494 (98.6%), Failed: 3, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.258 seconds
LL Privacy - Unpair 1                                Timed out    1.858 seconds
LL Privacy - Unpair 2 (Remove from AL)               Timed out    5.003 seconds

@github-actions

Copy link
Copy Markdown

TestRunner_rfcomm-tester
Desc: Run rfcomm-tester with test-runner
Duration: 26.41 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_sco-tester
Desc: Run sco-tester with test-runner
Duration: 32.59 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_ioctl-tester
Desc: Run ioctl-tester with test-runner
Duration: 27.71 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_mesh-tester
Desc: Run mesh-tester with test-runner
Duration: 27.18 seconds
Result: FAIL
Output:

Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    2.268 seconds
Mesh - Send cancel - 2                               Timed out    1.976 seconds

@github-actions

Copy link
Copy Markdown

TestRunner_smp-tester
Desc: Run smp-tester with test-runner
Duration: 25.17 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_userchan-tester
Desc: Run userchan-tester with test-runner
Duration: 21.31 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_6lowpan-tester
Desc: Run 6lowpan-tester with test-runner
Duration: 24.87 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

IncrementalBuild
Desc: Incremental build with the patches in the series
Duration: 28.46 seconds
Result: PASS

@github-actions
github-actions Bot force-pushed the workflow branch 5 times, most recently from 5de3a3b to 45ffbf1 Compare September 3, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants