mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhao Li <enderaoelyther@gmail.com>
To: Michael McAllister <me@michaelmcallister.org>
Cc: Marcel Holtmann <marcel@holtmann.org>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	brgl@kernel.org, linux-bluetooth@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	quic_bgodavar@quicinc.com, lumag@kernel.org, mka@chromium.org,
	markus.probst@posteo.de, shuai.zhang@oss.qualcomm.com
Subject: Re: [PATCH v2 2/4] Bluetooth: qca: Power off after unregistering the HCI device
Date: Mon, 16 Nov 2026 16:38:46 +0800	[thread overview]
Message-ID: <20261116083846.85334-1-enderaoelyther@gmail.com> (raw)
In-Reply-To: <179468159400.2456.12381703314197227930.wcn3950-poweroff-v2-2@michaelmcallister.org>

Hi Michael,

On Sat, Nov 14, 2026 at 06:39:54PM +0000, Michael McAllister wrote:
> +	/* Drain HCI setup before clearing protocol readiness. */
> +	if (test_bit(HCI_UART_REGISTERED, &hu->flags))
> +		hci_unregister_dev(hdev);
> +

Moving hci_unregister_dev() ahead of the hu->tx_skb cleanup also closes
an existing race for every hci_serdev protocol, not only QCA. Since
21139b3ac62a ("Bluetooth: hci_serdev: Fix use-after-free in
hci_uart_unregister_device()"), unregister frees hu->tx_skb before
hci_unregister_dev(), so a concurrent HCI close or reset already inside
hci_uart_flush() can use or free the same partial frame. Calling
hci_unregister_dev() first waits for that path via hdev->req_lock, which
hci_dev_do_close() holds across the close.

What the series leaves open is the same flush-vs-TX race on an ordinary
close. Your HCI_UNREGISTER early returns keep hci_uart_flush() away from
hu->tx_skb while unbinding, but HCIDEVDOWN and HCIDEVRESET both reach
that free through hci_dev_close_sync() with the flag still clear, and
hci_uart_flush() does not stop write_work first, so it can free a
partial frame that hci_uart_write_work() is still sending. With your
series applied, a test hook that keeps a partial frame in hu->tx_skb
across a close reproduces it under KASAN: a slab-use-after-free read in
hci_uart_write_work() and a double free from the close path. The device
reopens and transmits afterwards, so this is the live path rather than
teardown.

I have sent a fix for hci_uart_flush() that stops write_work there:

https://lore.kernel.org/r/20261116080538.66575-1-enderaoelyther@gmail.com

It is based on bluetooth-next without your series; your HCI_UNREGISTER
check in hci_uart_flush() goes above its new lines. With it on top of
your series the same test is clean and the device still transmits after
a reopen. I will drop my narrower unregister patch in favour of yours.

Would you consider splitting the hci_serdev.c part of this patch into
its own commit with Fixes: 21139b3ac62a, so it can reach stable without
the QCA power changes?

Thanks,
Zhao

  reply	other threads:[~2026-11-16  8:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 22:34 [PATCH 0/4] Bluetooth: qca: Fix WCN3950 power-off Michael McAllister
2026-10-28 22:34 ` [PATCH 2/4] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
2026-11-12 18:56   ` Markus Probst
2026-11-14 16:15     ` [PATCH 0/1] Bluetooth: hci_mrvl: Fix duplicate serdev open/close Michael McAllister
2026-11-14 16:15       ` [PATCH 1/1] Bluetooth: hci_mrvl: Leave the serdev port lifetime to hci_serdev Michael McAllister
2026-11-14 17:06       ` [PATCH 0/1] Bluetooth: hci_mrvl: Fix duplicate serdev open/close Markus Probst
2026-10-28 22:34 ` [PATCH 3/4] Bluetooth: qca: Power off after unregistering the HCI device Michael McAllister
2026-10-28 22:34 ` [PATCH 1/4] Bluetooth: qca: Restore flow control after a failed power pulse Michael McAllister
2026-10-28 22:34 ` [PATCH 4/4] Bluetooth: qca: Power off WCN3950 Michael McAllister
2026-11-14 18:39 ` [PATCH v2 0/4] " Michael McAllister
2026-11-14 18:39   ` [PATCH v2 1/4] Bluetooth: hci_serdev: Track whether the serial port is open Michael McAllister
2026-11-14 18:39   ` [PATCH v2 3/4] Bluetooth: qca: Handle failed power-pulse writes Michael McAllister
2026-11-14 18:39   ` [PATCH v2 2/4] Bluetooth: qca: Power off after unregistering the HCI device Michael McAllister
2026-11-16  8:38     ` Zhao Li [this message]
2026-11-14 18:39   ` [PATCH v2 4/4] Bluetooth: qca: Power off WCN3950 Michael McAllister

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=20261116083846.85334-1-enderaoelyther@gmail.com \
    --to=enderaoelyther@gmail.com \
    --cc=brgl@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=lumag@kernel.org \
    --cc=marcel@holtmann.org \
    --cc=markus.probst@posteo.de \
    --cc=me@michaelmcallister.org \
    --cc=mka@chromium.org \
    --cc=quic_bgodavar@quicinc.com \
    --cc=shuai.zhang@oss.qualcomm.com \
    /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

all inboxes | Powered by JetHome®