* [PATCH] HID: nintendo: fix rumble worker null pointer deref
@ 2022-07-13 20:20 Daniel J. Ogorchock
2022-07-14 19:26 ` Silvan Jegen
0 siblings, 1 reply; 2+ messages in thread
From: Daniel J. Ogorchock @ 2022-07-13 20:20 UTC (permalink / raw)
To: linux-input; +Cc: Daniel J. Ogorchock
We can dereference a null pointer trying to queue work to a destroyed
workqueue.
If the device is disconnected, nintendo_hid_remove is called, in which
the rumble_queue is destroyed. Avoid using that queue to defer rumble
work once the controller state is set to JOYCON_CTLR_STATE_REMOVED.
This eliminates the null pointer dereference.
Signed-off-by: Daniel J. Ogorchock <djogorchock@gmail.com>
---
drivers/hid/hid-nintendo.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index 2204de889739f..98551a3087c3b 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
@@ -1222,6 +1222,7 @@ static void joycon_parse_report(struct joycon_ctlr *ctlr,
spin_lock_irqsave(&ctlr->lock, flags);
if (IS_ENABLED(CONFIG_NINTENDO_FF) && rep->vibrator_report &&
+ ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED &&
(msecs - ctlr->rumble_msecs) >= JC_RUMBLE_PERIOD_MS &&
(ctlr->rumble_queue_head != ctlr->rumble_queue_tail ||
ctlr->rumble_zero_countdown > 0)) {
@@ -1546,12 +1547,13 @@ static int joycon_set_rumble(struct joycon_ctlr *ctlr, u16 amp_r, u16 amp_l,
ctlr->rumble_queue_head = 0;
memcpy(ctlr->rumble_data[ctlr->rumble_queue_head], data,
JC_RUMBLE_DATA_SIZE);
- spin_unlock_irqrestore(&ctlr->lock, flags);
/* don't wait for the periodic send (reduces latency) */
- if (schedule_now)
+ if (schedule_now && ctlr->ctlr_state != JOYCON_CTLR_STATE_REMOVED)
queue_work(ctlr->rumble_queue, &ctlr->rumble_worker);
+ spin_unlock_irqrestore(&ctlr->lock, flags);
+
return 0;
}
--
2.37.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] HID: nintendo: fix rumble worker null pointer deref
2022-07-13 20:20 [PATCH] HID: nintendo: fix rumble worker null pointer deref Daniel J. Ogorchock
@ 2022-07-14 19:26 ` Silvan Jegen
0 siblings, 0 replies; 2+ messages in thread
From: Silvan Jegen @ 2022-07-14 19:26 UTC (permalink / raw)
To: Daniel J. Ogorchock; +Cc: linux-input
"Daniel J. Ogorchock" <djogorchock@gmail.com> wrote:
> We can dereference a null pointer trying to queue work to a destroyed
> workqueue.
>
> If the device is disconnected, nintendo_hid_remove is called, in which
> the rumble_queue is destroyed. Avoid using that queue to defer rumble
> work once the controller state is set to JOYCON_CTLR_STATE_REMOVED.
>
> This eliminates the null pointer dereference.
>
> Signed-off-by: Daniel J. Ogorchock <djogorchock@gmail.com>
> ---
> drivers/hid/hid-nintendo.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
Reviewed-by: Silvan Jegen <s.jegen@gmail.com>
Cheers,
Silvan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-14 19:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-13 20:20 [PATCH] HID: nintendo: fix rumble worker null pointer deref Daniel J. Ogorchock
2022-07-14 19:26 ` Silvan Jegen
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).