Skip to content

Commit 7c782d8

Browse files
pskrgagsmb49
authored andcommitted
Bluetooth: hci_serdev: call init_rwsem() before p->open()
BugLink: https://bugs.launchpad.net/bugs/1971497 [ Upstream commit 9d7cbe2 ] kvartet reported, that hci_uart_tx_wakeup() uses uninitialized rwsem. The problem was in wrong place for percpu_init_rwsem() call. hci_uart_proto::open() may register a timer whose callback may call hci_uart_tx_wakeup(). There is a chance, that hci_uart_register_device() thread won't be fast enough to call percpu_init_rwsem(). Fix it my moving percpu_init_rwsem() call before p->open(). INFO: trying to register non-static key. The code is fine but needs lockdep annotation, or maybe you didn't initialize this object before use? turning off the locking correctness validator. CPU: 2 PID: 18524 Comm: syz-executor.5 Not tainted 5.16.0-rc6 #9 ... Call Trace: <IRQ> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 assign_lock_key kernel/locking/lockdep.c:951 [inline] register_lock_class+0x148d/0x1950 kernel/locking/lockdep.c:1263 __lock_acquire+0x106/0x57e0 kernel/locking/lockdep.c:4906 lock_acquire kernel/locking/lockdep.c:5637 [inline] lock_acquire+0x1ab/0x520 kernel/locking/lockdep.c:5602 percpu_down_read_trylock include/linux/percpu-rwsem.h:92 [inline] hci_uart_tx_wakeup+0x12e/0x490 drivers/bluetooth/hci_ldisc.c:124 h5_timed_event+0x32f/0x6a0 drivers/bluetooth/hci_h5.c:188 call_timer_fn+0x1a5/0x6b0 kernel/time/timer.c:1421 Fixes: d73e172 ("Bluetooth: hci_serdev: Init hci_uart proto_lock to avoid oops") Reported-by: Yiru Xu <[email protected]> Signed-off-by: Pavel Skripkin <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent a67b291 commit 7c782d8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/bluetooth/hci_serdev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ int hci_uart_register_device(struct hci_uart *hu,
279279
if (err)
280280
return err;
281281

282+
percpu_init_rwsem(&hu->proto_lock);
283+
282284
err = p->open(hu);
283285
if (err)
284286
goto err_open;
@@ -301,7 +303,6 @@ int hci_uart_register_device(struct hci_uart *hu,
301303

302304
INIT_WORK(&hu->init_ready, hci_uart_init_work);
303305
INIT_WORK(&hu->write_work, hci_uart_write_work);
304-
percpu_init_rwsem(&hu->proto_lock);
305306

306307
/* Only when vendor specific setup callback is provided, consider
307308
* the manufacturer information valid. This avoids filling in the

0 commit comments

Comments
 (0)