From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org,
syzbot <syzbot+243b7d89777f90f7613b@syzkaller.appspotmail.com>,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Subject: [PATCH 6.0 17/17] Bluetooth: use hdev->workqueue when queuing hdev->{cmd,ncmd}_timer works
Date: Mon, 10 Oct 2022 09:04:40 +0200 [thread overview]
Message-ID: <20221010070330.725277419@linuxfoundation.org> (raw)
In-Reply-To: <20221010070330.159911806@linuxfoundation.org>
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
commit deee93d13d385103205879a8a0915036ecd83261 upstream.
syzbot is reporting attempt to schedule hdev->cmd_work work from system_wq
WQ into hdev->workqueue WQ which is under draining operation [1], for
commit c8efcc2589464ac7 ("workqueue: allow chained queueing during
destruction") does not allow such operation.
The check introduced by commit 877afadad2dce8aa ("Bluetooth: When HCI work
queue is drained, only queue chained work") was incomplete.
Use hdev->workqueue WQ when queuing hdev->{cmd,ncmd}_timer works because
hci_{cmd,ncmd}_timeout() calls queue_work(hdev->workqueue). Also, protect
the queuing operation with RCU read lock in order to avoid calling
queue_delayed_work() after cancel_delayed_work() completed.
Link: https://syzkaller.appspot.com/bug?extid=243b7d89777f90f7613b [1]
Reported-by: syzbot <syzbot+243b7d89777f90f7613b@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 877afadad2dce8aa ("Bluetooth: When HCI work queue is drained, only queue chained work")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
net/bluetooth/hci_core.c | 15 +++++++++++++--
net/bluetooth/hci_event.c | 6 ++++--
2 files changed, 17 insertions(+), 4 deletions(-)
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -597,6 +597,15 @@ static int hci_dev_do_reset(struct hci_d
/* Cancel these to avoid queueing non-chained pending work */
hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);
+ /* Wait for
+ *
+ * if (!hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE))
+ * queue_delayed_work(&hdev->{cmd,ncmd}_timer)
+ *
+ * inside RCU section to see the flag or complete scheduling.
+ */
+ synchronize_rcu();
+ /* Explicitly cancel works in case scheduled after setting the flag. */
cancel_delayed_work(&hdev->cmd_timer);
cancel_delayed_work(&hdev->ncmd_timer);
@@ -4056,12 +4065,14 @@ static void hci_cmd_work(struct work_str
if (res < 0)
__hci_cmd_sync_cancel(hdev, -res);
+ rcu_read_lock();
if (test_bit(HCI_RESET, &hdev->flags) ||
hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE))
cancel_delayed_work(&hdev->cmd_timer);
else
- schedule_delayed_work(&hdev->cmd_timer,
- HCI_CMD_TIMEOUT);
+ queue_delayed_work(hdev->workqueue, &hdev->cmd_timer,
+ HCI_CMD_TIMEOUT);
+ rcu_read_unlock();
} else {
skb_queue_head(&hdev->cmd_q, skb);
queue_work(hdev->workqueue, &hdev->cmd_work);
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3766,16 +3766,18 @@ static inline void handle_cmd_cnt_and_ti
{
cancel_delayed_work(&hdev->cmd_timer);
+ rcu_read_lock();
if (!test_bit(HCI_RESET, &hdev->flags)) {
if (ncmd) {
cancel_delayed_work(&hdev->ncmd_timer);
atomic_set(&hdev->cmd_cnt, 1);
} else {
if (!hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE))
- schedule_delayed_work(&hdev->ncmd_timer,
- HCI_NCMD_TIMEOUT);
+ queue_delayed_work(hdev->workqueue, &hdev->ncmd_timer,
+ HCI_NCMD_TIMEOUT);
}
}
+ rcu_read_unlock();
}
static u8 hci_cc_le_read_buffer_size_v2(struct hci_dev *hdev, void *data,
next prev parent reply other threads:[~2022-10-10 7:05 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 7:04 [PATCH 6.0 00/17] 6.0.1-rc1 review Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 01/17] xsk: Inherit need_wakeup flag for shared sockets Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 02/17] fs: fix UAF/GPF bug in nilfs_mdt_destroy Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 03/17] [brown paperbag] fix coredump breakage Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 04/17] sparc: Unbreak the build Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 05/17] Makefile.extrawarn: Move -Wcast-function-type-strict to W=1 Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 06/17] hardening: Remove Clangs enable flag for -ftrivial-auto-var-init=zero Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 07/17] docs: update mediator information in CoC docs Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 08/17] hwmon: (aquacomputer_d5next) Fix Quadro fan speed offsets Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 09/17] usb: mon: make mmapped memory read only Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 10/17] USB: serial: ftdi_sio: fix 300 bps rate for SIO Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 11/17] gpiolib: acpi: Add support to ignore programming an interrupt Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 12/17] gpiolib: acpi: Add a quirk for Asus UM325UAZ Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 13/17] RISC-V: Print SSTC in canonical order Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 14/17] bpf: Gate dynptr API behind CAP_BPF Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 15/17] net: ethernet: mtk_eth_soc: fix state in __mtk_foe_entry_clear Greg Kroah-Hartman
2022-10-10 7:04 ` [PATCH 6.0 16/17] bpf: Fix resetting logic for unreferenced kptrs Greg Kroah-Hartman
2022-10-10 7:04 ` Greg Kroah-Hartman [this message]
2022-10-10 7:43 ` [PATCH 6.0 00/17] 6.0.1-rc1 review Luna Jernberg
2022-10-12 9:04 ` Pavel Machek
2022-10-12 9:13 ` Luna Jernberg
2022-10-10 14:03 ` Fenil Jain
2022-10-10 15:41 ` Naresh Kamboju
2022-10-10 17:07 ` Justin Forbes
2022-10-10 19:13 ` Florian Fainelli
2022-10-10 21:26 ` Shuah Khan
2022-10-11 0:59 ` Zan Aziz
2022-10-11 2:43 ` Slade Watkins
2022-10-11 3:18 ` Guenter Roeck
2022-10-11 8:10 ` Rudi Heitbaum
2022-10-11 8:58 ` Bagas Sanjaya
2022-10-11 16:12 ` Jon Hunter
2022-10-11 20:35 ` Sudip Mukherjee (Codethink)
2022-10-12 0:25 ` Ron Economos
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=20221010070330.725277419@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.von.dentz@intel.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=stable@vger.kernel.org \
--cc=syzbot+243b7d89777f90f7613b@syzkaller.appspotmail.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;
as well as URLs for NNTP newsgroup(s).