From: zhangchen200426@163.com
To: luiz.dentz@gmail.com
Cc: linux-bluetooth@vger.kernel.org, luiz.von.dentz@intel.com,
pav@iki.fi, zhangchen01@kylinos.cn, zhangchen200426@163.com
Subject: [PATCH v2] Bluetooth: hci_sock: Reject raw operations while powering down
Date: Tue, 1 Sep 2026 10:00:08 +0800 [thread overview]
Message-ID: <20260901020008.3846265-1-zhangchen200426@163.com> (raw)
In-Reply-To: <CABBYNZKH6c7oxcvrTomzL84dy6sMXXNRb6MoHPZr_oKG-bO_5Q@mail.gmail.com>
From: Chen Zhang <zhangchen01@kylinos.cn>
When an adapter is powered off with devices still connected, the
shutdown sequence issues an HCI reset which returns Command Complete
while the controller firmware is still rebooting. A command sent
concurrently through a raw socket during this window (e.g. hciconfig
queries triggered by the Bluetooth status change) can leave the
firmware in a stuck state where it stops answering any HCI command.
The subsequent power on then fails with 'Opcode 0x0c03 failed: -110'
and the adapter is lost until reboot or re-enumeration.
Unlike the ioctl paths (HCIDEVUP/HCIDEVDOWN/HCIDEVRESET) which are
already serialized by hci_req_sync_lock against the power off
sequence, raw socket command transmission goes directly to the
transport through hdev->send() without taking the lock, so it has to
be rejected explicitly:
- hci_sock_sendmsg(): reject with -ENETDOWN while HCI_POWERING_DOWN
is set, extending the existing HCI_UP check
- hci_sock_bind(): fail early with -EBUSY while HCI_POWERING_DOWN is
set, avoiding HCI_USER_CHANNEL to be toggled (and the controller
to be opened as user channel) right after power off
Changes in v2:
- Drop the HCI_POWERING_DOWN checks in hci_dev_open()/hci_dev_close()/
hci_dev_reset() (hci_core.c): those paths are already serialized by
hci_req_sync_lock against the power off sequence, checking the flag
outside the lock is redundant (as pointed out in review).
Signed-off-by: Chen Zhang <zhangchen01@kylinos.cn>
---
net/bluetooth/hci_sock.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 070ca388f9ac..897596614939 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -1296,6 +1296,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr_unsized *addr,
if (test_bit(HCI_INIT, &hdev->flags) ||
hci_dev_test_flag(hdev, HCI_SETUP) ||
hci_dev_test_flag(hdev, HCI_CONFIG) ||
+ hci_dev_test_flag(hdev, HCI_POWERING_DOWN) ||
(!hci_dev_test_flag(hdev, HCI_AUTO_OFF) &&
test_bit(HCI_UP, &hdev->flags))) {
err = -EBUSY;
@@ -1850,7 +1851,8 @@ static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg,
goto drop;
}
- if (!test_bit(HCI_UP, &hdev->flags)) {
+ if (!test_bit(HCI_UP, &hdev->flags) ||
+ hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) {
err = -ENETDOWN;
goto drop;
}
--
2.25.1
next prev parent reply other threads:[~2026-09-01 2:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 8:43 [PATCH] Bluetooth: Reject controller operations while powering down zhangchen200426
2026-08-31 12:45 ` bluez.test.bot
2026-08-31 15:54 ` [PATCH] " Luiz Augusto von Dentz
2026-09-01 2:00 ` zhangchen200426 [this message]
2026-09-01 7:27 ` [v2] Bluetooth: hci_sock: Reject raw " bluez.test.bot
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=20260901020008.3846265-1-zhangchen200426@163.com \
--to=zhangchen200426@163.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=luiz.von.dentz@intel.com \
--cc=pav@iki.fi \
--cc=zhangchen01@kylinos.cn \
/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