All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: btrsi: Move set_bt_context after successful HCI registration
@ 2026-07-22  8:31 Chen Changcheng
  2026-07-22 10:02 ` bluez.test.bot
  2026-07-24 19:00 ` [PATCH] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Chen Changcheng @ 2026-07-22  8:31 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: linux-bluetooth, linux-kernel, ccc194101, Chen Changcheng

In rsi_hci_attach(), ops->set_bt_context() stores the newly allocated
h_adapter into common->bt_adapter before hci_alloc_dev() and
hci_register_dev() are called. If either of these fails, h_adapter
is freed but common->bt_adapter remains a non-NULL dangling pointer.

This causes a deterministically reachable use-after-free when the
device operates in a BT+WiFi coexistence mode and CONFIG_RSI_COEX
is enabled. The following software-only trigger paths exist:

  1. SDIO driver .remove  (rsi_disconnect)
  2. USB  driver .disconnect (rsi_disconnect)
  3. SDIO driver .shutdown (rsi_shutdown)
  4. Hibernation .freeze  (rsi_freeze)

All four paths check:
    if (IS_ENABLED(CONFIG_RSI_COEX) && coex_mode > 1 && bt_adapter)
        rsi_bt_ops.detach(bt_adapter);  // use-after-free

coex_mode is set during rsi_91x_init(), before rsi_hci_attach() is
called, and is not cleared on attach failure. Since set_bt_context()
already wrote bt_adapter before the failure, the deinit paths see a
non-NULL dangling pointer and proceed to detach it.

Fix this by moving set_bt_context() after hci_register_dev() succeeds.
On failure paths bt_adapter stays NULL, and the deinit callers correctly
skip the detach call.

Signed-off-by: Chen Changcheng <chenchangcheng@kylinos.cn>
---
 drivers/bluetooth/btrsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/btrsi.c b/drivers/bluetooth/btrsi.c
index 59ad0b9b14c3..3f802b7c83f7 100644
--- a/drivers/bluetooth/btrsi.c
+++ b/drivers/bluetooth/btrsi.c
@@ -107,7 +107,6 @@ static int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops)
 		return -ENOMEM;
 
 	h_adapter->priv = priv;
-	ops->set_bt_context(priv, h_adapter);
 	h_adapter->proto_ops = ops;
 
 	hdev = hci_alloc_dev();
@@ -136,6 +135,8 @@ static int rsi_hci_attach(void *priv, struct rsi_proto_ops *ops)
 		goto err;
 	}
 
+	ops->set_bt_context(priv, h_adapter);
+
 	return 0;
 err:
 	h_adapter->hdev = NULL;
-- 
2.25.1


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

* RE: Bluetooth: btrsi: Move set_bt_context after successful HCI registration
  2026-07-22  8:31 [PATCH] Bluetooth: btrsi: Move set_bt_context after successful HCI registration Chen Changcheng
@ 2026-07-22 10:02 ` bluez.test.bot
  2026-07-24 19:00 ` [PATCH] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-07-22 10:02 UTC (permalink / raw)
  To: linux-bluetooth, chenchangcheng

[-- Attachment #1: Type: text/plain, Size: 1181 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/project/bluetooth/list/?series=1132252

---Test result---

Test Summary:
CheckPatch                    PASS      0.76 seconds
VerifyFixes                   PASS      0.14 seconds
VerifySignedoff               PASS      0.14 seconds
GitLint                       PASS      0.34 seconds
SubjectPrefix                 PASS      0.13 seconds
BuildKernel                   PASS      28.01 seconds
CheckAllWarning               PASS      30.86 seconds
CheckSparse                   PASS      29.46 seconds
BuildKernel32                 PASS      27.13 seconds
CheckKernelLLVM               SKIP      0.00 seconds
TestRunnerSetup               PASS      512.27 seconds
IncrementalBuild              PASS      26.81 seconds

Details
##############################
Test: CheckKernelLLVM - SKIP
Desc: Build kernel with LLVM + context analysis
Output:
Clang not found


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

---
Regards,
Linux Bluetooth


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

* Re: [PATCH] Bluetooth: btrsi: Move set_bt_context after successful HCI registration
  2026-07-22  8:31 [PATCH] Bluetooth: btrsi: Move set_bt_context after successful HCI registration Chen Changcheng
  2026-07-22 10:02 ` bluez.test.bot
@ 2026-07-24 19:00 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-07-24 19:00 UTC (permalink / raw)
  To: Chen Changcheng
  Cc: marcel, luiz.dentz, linux-bluetooth, linux-kernel, ccc194101

Hello:

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

On Wed, 22 Jul 2026 16:31:36 +0800 you wrote:
> In rsi_hci_attach(), ops->set_bt_context() stores the newly allocated
> h_adapter into common->bt_adapter before hci_alloc_dev() and
> hci_register_dev() are called. If either of these fails, h_adapter
> is freed but common->bt_adapter remains a non-NULL dangling pointer.
> 
> This causes a deterministically reachable use-after-free when the
> device operates in a BT+WiFi coexistence mode and CONFIG_RSI_COEX
> is enabled. The following software-only trigger paths exist:
> 
> [...]

Here is the summary with links:
  - Bluetooth: btrsi: Move set_bt_context after successful HCI registration
    https://git.kernel.org/bluetooth/bluetooth-next/c/17abcfc57c8a

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-07-24 19:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22  8:31 [PATCH] Bluetooth: btrsi: Move set_bt_context after successful HCI registration Chen Changcheng
2026-07-22 10:02 ` bluez.test.bot
2026-07-24 19:00 ` [PATCH] " patchwork-bot+bluetooth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.