From: Jiri Slaby <jirislaby@kernel.org>
To: Qasim Ijaz <qasdev00@gmail.com>, jikos@kernel.org, bentiss@kernel.org
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] HID: multitouch: fix integer overflow in set_abs()
Date: Thu, 24 Jul 2025 08:58:40 +0200 [thread overview]
Message-ID: <914ff45b-2260-42c0-9ccf-a3efd667d4f5@kernel.org> (raw)
In-Reply-To: <20250723173659.59327-1-qasdev00@gmail.com>
On 23. 07. 25, 19:36, Qasim Ijaz wrote:
> It is possible for a malicious HID device to trigger a signed integer
> overflow (undefined behaviour) in set_abs() in the following expression
> by supplying bogus logical maximum and minimum values:
>
> int fuzz = snratio ? (fmax - fmin) / snratio : 0;
>
> For example, if the logical_maximum is INT_MAX and logical_minimum is -1
> then (fmax - fmin) resolves to INT_MAX + 1, which does not fit in a 32-bit
> signed int, so the subtraction overflows.
The question is if it matters with -fwrapv?
> Fix this by computing the
> difference in a 64 bit context.
>
> Fixes: 5519cab477b6 ("HID: hid-multitouch: support for PixCir-based panels")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
> ---
> drivers/hid/hid-multitouch.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
> index 22c6314a8843..687638ed6d0f 100644
> --- a/drivers/hid/hid-multitouch.c
> +++ b/drivers/hid/hid-multitouch.c
> @@ -540,7 +540,8 @@ static void set_abs(struct input_dev *input, unsigned int code,
> {
> int fmin = field->logical_minimum;
> int fmax = field->logical_maximum;
> - int fuzz = snratio ? (fmax - fmin) / snratio : 0;
> + s64 diff = (s64)fmax - (s64)fmin;
> + int fuzz = snratio ? (int)div_s64(diff, snratio) : 0;
> input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
> input_abs_set_res(input, code, hidinput_calc_abs_res(field, code));
> }
--
js
suse labs
next prev parent reply other threads:[~2025-07-24 6:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-23 17:36 [PATCH] HID: multitouch: fix integer overflow in set_abs() Qasim Ijaz
2025-07-24 6:58 ` Jiri Slaby [this message]
2025-07-24 15:56 ` Qasim Ijaz
2025-07-31 7:43 ` Jiri Slaby
2025-08-10 17:31 ` Qasim Ijaz
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=914ff45b-2260-42c0-9ccf-a3efd667d4f5@kernel.org \
--to=jirislaby@kernel.org \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qasdev00@gmail.com \
--cc=stable@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