From: "Tomasz Pakuła" <tomasz.pakula.oficjalny@gmail.com>
To: Yifan Zhang <yfzhang23@stu.pku.edu.cn>,
Oleg Makarenko <oleg@makarenk.ooo>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
linux-input@vger.kernel.org
Cc: Dmitry Torokhov <dtor@mail.ru>,
Anssi Hannula <anssi.hannula@gmail.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] HID: pidff: validate effect type usage indexes
Date: Tue, 03 Nov 2026 10:23:48 +0100 [thread overview]
Message-ID: <8f4bdf112918e848fa236877b41f8142194db69e.camel@gmail.com> (raw)
In-Reply-To: <179362071771.29269.11607321878213733518@stu.pku.edu.cn>
On Mon, 2026-11-02 at 19:58 +0800, Yifan Zhang wrote:
> pidff_find_special_keys() records usage positions as one-based values, but
> pidff_find_effects() uses those values directly as array indexes. The
> Create New Effect and Set Effect fields are independently allocated and
> need not have the same number of usages, so a malformed descriptor can
> make the lookup leave the Set Effect usage array.
>
> KASAN reports:
>
> BUG: KASAN: slab-out-of-bounds in hid_pidff_init_with_quirks
> Read of size 4
> hid_pidff_init_with_quirks
> universal_pidff_probe
> hid_device_probe
> uhid_device_add_worker
>
> Convert the stored position back to a zero-based index and validate it
> against both fields before comparing the usages.
>
> The reproducer is rejected without a KASAN report with this change.
>
> Fixes: 224ee88fe395 ("Input: add force feedback driver for PID devices")
> Signed-off-by: Yifan Zhang <yfzhang23@stu.pku.edu.cn>
> ---
> drivers/hid/usbhid/hid-pidff.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
> index 22951b7ecd174..5e4a937237d55 100644
> --- a/drivers/hid/usbhid/hid-pidff.c
> +++ b/drivers/hid/usbhid/hid-pidff.c
> @@ -1373,9 +1373,16 @@ static int pidff_find_effects(struct pidff_device *pidff,
>
> for (i = 0; i < ARRAY_SIZE(pidff_effect_types); i++) {
> int pidff_type = pidff->type_id[i];
> + int usage_index;
>
> - if (pidff->set_effect_type->usage[pidff_type].hid !=
> - pidff->create_new_effect_type->usage[pidff_type].hid) {
> + if (!pidff_type)
> + continue;
> +
> + usage_index = pidff_type - 1;
> + if (usage_index >= pidff->set_effect_type->maxusage ||
> + usage_index >= pidff->create_new_effect_type->maxusage ||
> + pidff->set_effect_type->usage[usage_index].hid !=
> + pidff->create_new_effect_type->usage[usage_index].hid) {
> hid_err(pidff->hid,
> "effect type number %d is invalid\n", i);
> return -1;
Thanks very much! Now that I look at it, find_effects was never
overhauled and I don't quite like how it does things here so I'll redo
the function + include a fix for this issue.
prev parent reply other threads:[~2026-11-03 9:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 11:58 Yifan Zhang
2026-11-02 11:58 ` Yifan Zhang
2026-11-03 9:23 ` Tomasz Pakuła [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=8f4bdf112918e848fa236877b41f8142194db69e.camel@gmail.com \
--to=tomasz.pakula.oficjalny@gmail.com \
--cc=anssi.hannula@gmail.com \
--cc=bentiss@kernel.org \
--cc=dtor@mail.ru \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=oleg@makarenk.ooo \
--cc=yfzhang23@stu.pku.edu.cn \
/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®