diff options
author | Roderick Colenbrander <roderick@gaikai.com> | 2019-08-02 18:50:19 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2019-08-06 06:46:15 -0400 |
commit | e0f6974a54d3f7f1b5fdf5a593bd43ce9206ec04 (patch) | |
tree | 2e217dec39f7f52d1cbfb53f883c683ce740f47c /drivers/hid/hid-sony.c | |
parent | 6d4472d7bec39917b54e4e80245784ea5d60ce49 (diff) |
HID: sony: Fix race condition between rumble and device remove.
Valve reported a kernel crash on Ubuntu 18.04 when disconnecting a DS4
gamepad while rumble is enabled. This issue is reproducible with a
frequency of 1 in 3 times in the game Borderlands 2 when using an
automatic weapon, which triggers many rumble operations.
We found the issue to be a race condition between sony_remove and the
final device destruction by the HID / input system. The problem was
that sony_remove didn't clean some of its work_item state in
"struct sony_sc". After sony_remove work, the corresponding evdev
node was around for sufficient time for applications to still queue
rumble work after "sony_remove".
On pre-4.19 kernels the race condition caused a kernel crash due to a
NULL-pointer dereference as "sc->output_report_dmabuf" got freed during
sony_remove. On newer kernels this crash doesn't happen due the buffer
now being allocated using devm_kzalloc. However we can still queue work,
while the driver is an undefined state.
This patch fixes the described problem, by guarding the work_item
"state_worker" with an initialized variable, which we are setting back
to 0 on cleanup.
Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
CC: stable@vger.kernel.org
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-sony.c')
-rw-r--r-- | drivers/hid/hid-sony.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 93942063b51b..49dd2d905c7f 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c | |||
@@ -585,10 +585,14 @@ static void sony_set_leds(struct sony_sc *sc); | |||
585 | static inline void sony_schedule_work(struct sony_sc *sc, | 585 | static inline void sony_schedule_work(struct sony_sc *sc, |
586 | enum sony_worker which) | 586 | enum sony_worker which) |
587 | { | 587 | { |
588 | unsigned long flags; | ||
589 | |||
588 | switch (which) { | 590 | switch (which) { |
589 | case SONY_WORKER_STATE: | 591 | case SONY_WORKER_STATE: |
590 | if (!sc->defer_initialization) | 592 | spin_lock_irqsave(&sc->lock, flags); |
593 | if (!sc->defer_initialization && sc->state_worker_initialized) | ||
591 | schedule_work(&sc->state_worker); | 594 | schedule_work(&sc->state_worker); |
595 | spin_unlock_irqrestore(&sc->lock, flags); | ||
592 | break; | 596 | break; |
593 | case SONY_WORKER_HOTPLUG: | 597 | case SONY_WORKER_HOTPLUG: |
594 | if (sc->hotplug_worker_initialized) | 598 | if (sc->hotplug_worker_initialized) |
@@ -2558,13 +2562,18 @@ static inline void sony_init_output_report(struct sony_sc *sc, | |||
2558 | 2562 | ||
2559 | static inline void sony_cancel_work_sync(struct sony_sc *sc) | 2563 | static inline void sony_cancel_work_sync(struct sony_sc *sc) |
2560 | { | 2564 | { |
2565 | unsigned long flags; | ||
2566 | |||
2561 | if (sc->hotplug_worker_initialized) | 2567 | if (sc->hotplug_worker_initialized) |
2562 | cancel_work_sync(&sc->hotplug_worker); | 2568 | cancel_work_sync(&sc->hotplug_worker); |
2563 | if (sc->state_worker_initialized) | 2569 | if (sc->state_worker_initialized) { |
2570 | spin_lock_irqsave(&sc->lock, flags); | ||
2571 | sc->state_worker_initialized = 0; | ||
2572 | spin_unlock_irqrestore(&sc->lock, flags); | ||
2564 | cancel_work_sync(&sc->state_worker); | 2573 | cancel_work_sync(&sc->state_worker); |
2574 | } | ||
2565 | } | 2575 | } |
2566 | 2576 | ||
2567 | |||
2568 | static int sony_input_configured(struct hid_device *hdev, | 2577 | static int sony_input_configured(struct hid_device *hdev, |
2569 | struct hid_input *hidinput) | 2578 | struct hid_input *hidinput) |
2570 | { | 2579 | { |