Linux bluetooth development
 help / color / mirror / Atom feed
From: Kiran K <kiran.k@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: chethan.tumkur.narayan@intel.com,
	chandrashekar.devegowda@intel.com, Kiran K <kiran.k@intel.com>
Subject: [PATCH v2] Bluetooth: btintel_pcie: Fix RX hdev publication race
Date: Mon, 30 Nov 2026 19:59:44 +0530	[thread overview]
Message-ID: <20261130142944.251379-1-kiran.k@intel.com> (raw)

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 in a stress reboot test 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: f70f7f2512c6 ("Bluetooth: btintel_pcie: Separate coredump work from RX work")
Assisted-by: Copilot:claude-sonnet-5.5
Signed-off-by: Kiran K <kiran.k@intel.com>
---
changes in v2:
Fix: https://sashiko.dev/#/patchset/20261124005939.2981368-1-kiran.k%40intel.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.56.1


                 reply	other threads:[~2026-11-30 14:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130142944.251379-1-kiran.k@intel.com \
    --to=kiran.k@intel.com \
    --cc=chandrashekar.devegowda@intel.com \
    --cc=chethan.tumkur.narayan@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox