Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v1] Bluetooth: btintel_pcie: Fix RX hdev publication race
@ 2026-11-24  0:59 Kiran K
  2026-11-24  7:00 ` [v1] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Kiran K @ 2026-11-24  0:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: chethan.tumkur.narayan, chandrashekar.devegowda, Kiran K

hci_register_dev() queues hci_power_on without waiting for
hdev->setup(), so setup can run before btintel_pcie_setup_hdev()
returns and publishes data->hdev. Publish data->hdev at the start of
hdev->setup(), when the hdev is fully registered, so the command/event
exchange finds it. Publishing before registration would expose a
partially initialised hdev to RX and the dump workers.

The race is seen as a NULL pointer dereference in the RX work while
hdev->setup() is still running:

  Oops: general protection fault, kernel NULL pointer dereference 0xc28: 0000 [#1] SMP NOPTI
  CPU: 0 UID: 0 PID: 904 Comm: kworker/u35:1 Tainted: G C OE 7.3.0-nvl-ww44-2bkc #2 PREEMPT(lazy)
  Hardware name: Intel Corporation Nova Lake Client Platform/NVL UPH/UL LP5X T3 MEMSKT RVP5, BIOS NVLPFWR1.R00.3414.D22.2610141025 10/14/2026
  Workqueue: btintel_pcie btintel_pcie_rx_work [btintel_pcie]
  RIP: 0010:btintel_pcie_recv_frame.isra.0+0xc8/0x3c0 [btintel_pcie]
  Call Trace:
   <TASK>
   btintel_pcie_rx_work+0x24/0x40 [btintel_pcie]
   process_one_work+0x1dc/0x3f0
   worker_thread+0x1b8/0x360
   kthread+0xf9/0x130
   ret_from_fork+0x2c3/0x380
   ret_from_fork_asm+0x1a/0x30
   </TASK>

Drop received frames when data->hdev is unavailable to avoid NULL
dereferences.

Fixes: 6e65a09f9275 ("Bluetooth: btintel_pcie: Add *setup* function to download firmware")
Assisted-by: Copilot:claude-sonnet-5.5
Signed-off-by: Kiran K <kiran.k@intel.com>
---
 drivers/bluetooth/btintel_pcie.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/bluetooth/btintel_pcie.c b/drivers/bluetooth/btintel_pcie.c
index 3b2c8bbb36e9..4aff83ba1bbd 100644
--- a/drivers/bluetooth/btintel_pcie.c
+++ b/drivers/bluetooth/btintel_pcie.c
@@ -2533,7 +2533,15 @@ static int btintel_pcie_recv_frame(struct btintel_pcie_data *data,
 	u32 plen;
 	u32 pcie_pkt_type;
 	void *pdata;
-	struct hci_dev *hdev = data->hdev;
+	struct hci_dev *hdev = READ_ONCE(data->hdev);
+
+	/* RX can start before hdev is published (see btintel_pcie_setup()).
+	 * No command can be pending yet, so drop the frame.
+	 */
+	if (!hdev) {
+		kfree_skb(skb);
+		return -ENODEV;
+	}
 
 	spin_lock(&data->hci_rx_lock);
 
@@ -2953,10 +2961,11 @@ static void btintel_pcie_coredump_worker(struct work_struct *work)
 	struct btintel_pcie_data *data = container_of(work,
 					struct btintel_pcie_data, coredump_work);
 
-	/* hdev is NULL until setup_hdev() succeeds, and is cleared on
+	/* hdev is NULL until it is registered and published by
+	 * btintel_pcie_setup() or btintel_pcie_setup_hdev(), and is cleared on
 	 * teardown after disable_work_sync() drains us; bail in that case.
 	 */
-	if (!data->hdev)
+	if (!READ_ONCE(data->hdev))
 		goto out;
 
 	/* When firmware routes debug traces to the WiFi DBGC, no host
@@ -4273,6 +4282,12 @@ static int btintel_pcie_setup(struct hci_dev *hdev)
 	struct btintel_pcie_data *data = hci_get_drvdata(hdev);
 	bool fips_crc_failed;
 
+	/* hci_register_dev() only queues setup(), so it can run before
+	 * setup_hdev() returns. hdev is registered by now; publish it so RX
+	 * and the dump workers can use it.
+	 */
+	WRITE_ONCE(data->hdev, hdev);
+
 	btintel_pcie_fatal_err_load(data);
 
 	while ((err = btintel_pcie_setup_internal(hdev, &fips_crc_failed)) &&
@@ -4846,11 +4861,8 @@ static int btintel_pcie_setup_hdev(struct btintel_pcie_data *data)
 		return err;
 	}
 
-	/* Publish hdev only after successful registration; the coredump
-	 * worker bails on !data->hdev, so it never observes a half-set-up
-	 * device.
-	 */
-	data->hdev = hdev;
+	/* Idempotent: setup() may already have published hdev. */
+	WRITE_ONCE(data->hdev, hdev);
 	data->dmp_hdr.driver_name = KBUILD_MODNAME;
 	return 0;
 }
-- 
2.54.0


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

end of thread, other threads:[~2026-11-24  7:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  0:59 [PATCH v1] Bluetooth: btintel_pcie: Fix RX hdev publication race Kiran K
2026-11-24  7:00 ` [v1] " bluez.test.bot

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