From: sashiko-bot@kernel.org
To: "Myeonghun Pak" <mhun512@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH] HID: magicmouse: disable the multitouch work on removal
Date: Tue, 10 Nov 2026 04:49:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-206244@kernel.org> (raw)
In-Reply-To: <20261110043001.56615-1-mhun512@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: magicmouse: UAF on msc in magicmouse_reset_resume()
during unbind
--
commit 6b44c69f3cb297be7e3753fa8262ad83f2724078
Author: Myeonghun Pak <mhun512@gmail.com>
HID: magicmouse: disable the multitouch work on removal
This commit replaces cancel_delayed_work_sync() with
disable_delayed_work_sync() in magicmouse_remove() to prevent
magicmouse_reset_resume() from queueing msc->work during unbind.
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index a01e84a18dede..525ffc64a2f02 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -1032,7 +1032,7 @@ static void magicmouse_remove(struct hid_device *hdev)
> struct magicmouse_sc *msc = hid_get_drvdata(hdev);
>
> if (msc) {
> - cancel_delayed_work_sync(&msc->work);
> + disable_delayed_work_sync(&msc->work);
> if (is_usb_magicmouse2(hdev->vendor, hdev->product) ||
> is_usb_magictrackpad2(hdev->vendor, hdev->product))
> timer_delete_sync(&msc->battery_timer);
[Severity: Medium]
Can magicmouse_reset_resume() still cause a use-after-free on msc after
magicmouse_remove() returns?
disable_delayed_work_sync() records the disabled state in
msc->work.work.data, which lives inside the devm-allocated msc. In
hid_device_remove(), devres_release_group() frees msc right after
hdrv->remove() returns, before hdev->driver or driver_data is cleared:
drivers/hid/hid-core.c:hid_device_remove() {
...
if (hdrv->remove)
hdrv->remove(hdev);
else /* default remove */
hid_hw_stop(hdev);
/* Release all devres resources allocated by the driver */
devres_release_group(&hdev->dev, hdev->devres_group_id);
hid_close_report(hdev);
hdev->driver = NULL;
...
}
Because hid_driver_reset_resume() does not serialize against
hid_device_remove(), a concurrent reset-resume can still touch msc->work
after msc is freed:
CPU0 CPU1
hid_device_remove()
magicmouse_remove()
disable_delayed_work_sync(&msc->work)
hid_driver_reset_resume()
magicmouse_reset_resume()
msc = hid_get_drvdata(hdev)
devres_release_group() -> frees msc
schedule_delayed_work(&msc->work, ...)
<-- use-after-free on msc->work
queue_delayed_work_on() performs atomic bit operations on
msc->work.work.data to test and clear the pending bit when disabled,
modifying freed or reallocated slab memory (or queueing the work if
reallocation cleared the disable count).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261110043001.56615-1-mhun512@gmail.com?part=1
prev parent reply other threads:[~2026-11-10 4:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 4:30 [PATCH] HID: magicmouse: disable the multitouch work on removal Myeonghun Pak
2026-11-10 4:49 ` sashiko-bot [this message]
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=sashiko-outbox-206244@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=mhun512@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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