From: "Shengzhuo Wei" <me@cherr.cc>
To: "Tomasz Pakuła" <tomasz.pakula.oficjalny@gmail.com>,
"Oleg Makarenko" <oleg@makarenk.ooo>,
"Jiri Kosina" <jikos@kernel.org>,
"Benjamin Tissoires" <bentiss@kernel.org>
Cc: <linux-input@vger.kernel.org>, <linux-usb@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>,
"Shengzhuo Wei" <me@cherr.cc>
Subject: [PATCH] HID: pidff: fix undefined shift for infinite duration
Date: Wed, 28 Oct 2026 18:55:02 +0800 [thread overview]
Message-ID: <20261028-b4-pidff-duration-shift-v1-1-65028c6b4a37@cherr.cc> (raw)
pidff_set_duration() computes the infinite duration as
(1U << report_size) - 1, but report_size comes from the device's
report descriptor and can be 32 or greater. This causes an undefined
shift. A UHID test on x86-64 triggers UBSAN and programs a 32-bit
duration field as zero instead of 0xffffffff.
For report sizes of 32 or more, store -1 in the s32 field value to
set all 32 bits without shifting. Keep the existing calculation for
smaller fields.
Fixes: 1a575044d516 ("HID: pidff: Compute INFINITE value instead of using hardcoded 0xffff")
Cc: stable@vger.kernel.org
Signed-off-by: Shengzhuo Wei <me@cherr.cc>
---
HID: pidff: fix undefined shift for infinite duration
---
drivers/hid/usbhid/hid-pidff.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
index 22951b7ecd17..25b82e7d0b9e 100644
--- a/drivers/hid/usbhid/hid-pidff.c
+++ b/drivers/hid/usbhid/hid-pidff.c
@@ -394,7 +394,11 @@ static void pidff_set_duration(struct pidff_usage *usage, u16 duration)
{
/* PID defines INFINITE as the max possible value for duration field */
if (pidff_is_duration_infinite(duration)) {
- usage->value[0] = (1U << usage->field->report_size) - 1;
+ if (usage->field->report_size >= 32)
+ usage->value[0] = -1;
+ else
+ usage->value[0] =
+ (1U << usage->field->report_size) - 1;
return;
}
---
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
change-id: 20261028-b4-pidff-duration-shift-8df4f6451448
Best regards,
--
Shengzhuo Wei <me@cherr.cc>
next reply other threads:[~2026-10-28 10:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 10:55 Shengzhuo Wei [this message]
2026-11-02 12:36 ` Tomasz Pakuła
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=20261028-b4-pidff-duration-shift-v1-1-65028c6b4a37@cherr.cc \
--to=me@cherr.cc \
--cc=bentiss@kernel.org \
--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=stable@vger.kernel.org \
--cc=tomasz.pakula.oficjalny@gmail.com \
/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®