From: "René Onier" <f3nr1l@me.com>
To: Benjamin Tissoires <bentiss@kernel.org>, Jiri Kosina <jikos@kernel.org>
Cc: "René Onier" <f3nr1l@me.com>,
"Ivan Gorinov" <linux-kernel@altimeter.info>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Subject: [PATCH 1/2] HID: winwing: fix use-after-free of the rumble work
Date: Wed, 30 Sep 2026 15:37:50 -0400 [thread overview]
Message-ID: <2c34f174fc3c0e63b411cda5dce2d49a8799d4b0.1790795726.git.f3nr1l@me.com> (raw)
In-Reply-To: <cover.1790795726.git.f3nr1l@me.com>
winwing_remove() cancels the rumble work before it tears the device
down:
if (data)
cancel_work_sync(&data->rumble_work);
hid_hw_close(hdev);
hid_hw_stop(hdev);
Nothing keeps the work from being queued again after that cancel.
hid_hw_stop() unregisters the input device, and evdev_cleanup() flushes
it while it is still open: input_flush_device() -> input_ff_flush() ->
erase_effect() -> ff->playback(dev, id, 0). On a memoryless device that
is ml_ff_playback(), which marks a playing effect as aborting and calls
ml_play_effects(), handing the driver the combined - now zeroed -
effect. That is winwing_play_effect(), and it ends with
return schedule_work(&data->rumble_work);
Unbinding, rmmod'ing or unplugging the device while an effect is playing
therefore queues the work again, after cancel_work_sync() has run.
The driver data is devm-allocated, and hid_device_remove() releases the
driver's devres group as soon as winwing_remove() returns. The pending
work then runs on freed memory: both the work_struct itself and the
report buffer winwing_haptic_rumble() writes into live in that
allocation.
Cancel the work once the device has been stopped instead. After
hid_hw_stop() has returned the input device is gone and no further
effect can be played, so a single cancel_work_sync() is enough. The
driver data is still valid at that point, since devres only runs after
winwing_remove() has returned, so a work item that is still running
while the transport goes down touches valid memory only; its
hid_hw_output_report() call simply fails once the low-level driver has
torn its endpoints down.
Fixes: 42d020b54edc ("HID: winwing: Enable rumble effects")
Signed-off-by: René Onier <f3nr1l@me.com>
---
drivers/hid/hid-winwing.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/hid/hid-winwing.c b/drivers/hid/hid-winwing.c
index 19b92c2c65..e8030fdc14 100644
--- a/drivers/hid/hid-winwing.c
+++ b/drivers/hid/hid-winwing.c
@@ -391,11 +391,16 @@ static void winwing_remove(struct hid_device *hdev)
data = (struct winwing_drv_data *) hid_get_drvdata(hdev);
- if (data)
- cancel_work_sync(&data->rumble_work);
-
hid_hw_close(hdev);
hid_hw_stop(hdev);
+
+ /*
+ * Only cancel the work once the input device is gone: stopping the
+ * device flushes the force feedback effects, which plays them one
+ * last time and queues the work again.
+ */
+ if (data)
+ cancel_work_sync(&data->rumble_work);
}
static int winwing_input_configured(struct hid_device *hdev,
--
2.55.0
next prev parent reply other threads:[~2026-09-30 19:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 19:37 [PATCH 0/2] HID: winwing: two teardown fixes René Onier
2026-09-30 19:37 ` René Onier [this message]
2026-09-30 19:37 ` [PATCH 2/2] HID: winwing: initialize the lights_lock mutex René Onier
2026-09-30 19:55 ` [PATCH 0/4] HID: winwing: add WinWing URSA MINOR sticks René Onier
2026-09-30 19:55 ` [PATCH 1/4] HID: winwing: factor out vendor SET_LEDX report builder René Onier
2026-09-30 19:55 ` [PATCH 2/4] HID: winwing: make the LED set and lighting controller model-dependent René Onier
2026-09-30 19:55 ` [PATCH 3/4] HID: winwing: add URSA MINOR sticks René Onier
2026-09-30 19:56 ` [PATCH 4/4] HID: winwing: drive the URSA MINOR rumble motor René Onier
2026-09-30 19:58 ` [PATCH 0/2] HID: winwing: two teardown fixes René Onier
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=2c34f174fc3c0e63b411cda5dce2d49a8799d4b0.1790795726.git.f3nr1l@me.com \
--to=f3nr1l@me.com \
--cc=bentiss@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@altimeter.info \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®