From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Ginger <ginger.jzllee@gmail.com>
Cc: linux-input@vger.kernel.org
Subject: Re: [bug report] Potential order bug in 'drivers/input/misc', particularly 'ati_remote2.c', 'cm109.c', 'keyspan_remote.c'
Date: Tue, 28 Apr 2026 08:01:27 -0700 [thread overview]
Message-ID: <afA2VUnd1GxWs055@google.com> (raw)
In-Reply-To: <CAGp+u1aFTivN-EC5QQaQ=j21GaGHktunHEzWQ9e2uASsE40svQ@mail.gmail.com>
Hi Ginger,
On Tue, Apr 28, 2026 at 12:18:46PM +0800, Ginger wrote:
> Dear Linux kernel maintainers,
>
> My research-based static analyzer found a potential order bug within
> the ' drivers/input/misc' subsystem. I will use the potential bug
> found in 'drivers/input/misc/ati_remote2.c' as the typical example.
> The similar potential bug patterns are also observed in 'cm109.c' and
> 'keyspan_remote.c'.
>
> Kernel version: long-term kernel v6.18.9
>
> Potential issue:
> T0:
> ati_remote2_disconnect
> --> ar2 = usb_get_intfdata(interface);
> --> usb_set_intfdata(interface, NULL);
> --> input_unregister_device(ar2->idev);
> --> usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
> --> kfree(ar2)
>
> T1:
> ati_remote2_store_channel_mask (registered as the device attribute
> function and exposed via the sysfs)
> --> struct ati_remote2 *ar2 = usb_get_intfdata(intf);
> --> ar2->mode_mask = mask;
>
> In T0, the interface is nullified before its get deregistered. Thus,
> it is possible for T1 to still get the usb dev and access it via the
> interface, which, however, has been already nullified or even freed.
> This similar pattern is also observed in 'cm109_usb_disconnect()' of
> file 'cm109.c' and 'keyspan_disconnect()' of file 'keyspan_remote.c'.
Driver core is supposed to remove sysfs attributes before calling
remove() or disconnect() (see drivers/base/dd.c::device_remove()) and
sysfs ensures that all threads leave sysfs show() and store() methods
before the call to delete the attributes returns.
Thanks.
--
Dmitry
prev parent reply other threads:[~2026-04-28 15:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 4:18 [bug report] Potential order bug in 'drivers/input/misc', particularly 'ati_remote2.c', 'cm109.c', 'keyspan_remote.c' Ginger
2026-04-28 15:01 ` Dmitry Torokhov [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=afA2VUnd1GxWs055@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=ginger.jzllee@gmail.com \
--cc=linux-input@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