From: sashiko-bot@kernel.org
To: "Yibo Tan" <lhfff@tju.edu.cn>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v1] HID: sensor-hub: synchronize multi-value read cancellation
Date: Thu, 10 Sep 2026 11:35:38 +0000 [thread overview]
Message-ID: <20260910113538.AE06E1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910112338.4171983-1-lhfff@tju.edu.cn>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The patch fixes a missing lock race condition in `sensor_hub_input_attr_read_values` but fails to apply the same fix to `sensor_hub_input_attr_get_raw_value`, leaving an identical race condition that causes memory leaks and completion queue corruption.
- [Critical] Unvalidated access to `report->field[i]->usage` in `sensor_hub_raw_event` causes an out-of-bounds read if a field defines zero usages.
- [Critical] Missing bounds check on `ptr` against the total received `size` in `sensor_hub_raw_event` allows an out-of-bounds read of kernel memory.
--
commit c2fc661d8850deb7960ddffa43fdc7a6bea63778
Author: Yibo Tan <lhfff@tju.edu.cn>
HID: sensor-hub: synchronize multi-value read cancellation
sensor_hub_input_attr_read_values() publishes a caller-owned buffer to the
raw-event path. If its interruptible wait times out or is interrupted, it
clears pending.status without taking data->lock and returns.
Link: https://lore.kernel.org/r/20260610083849.067A11F00893@smtp.kernel.org/
> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
> index 6470a290ebfc5..80f18aff6f1f8 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -335,7 +335,9 @@ int sensor_hub_input_attr_read_values(struct hid_sensor_hub_device *hsdev,
> else if (cycles < 0)
> ret = cycles;
>
> + spin_lock_irqsave(&data->lock, flags);
> hsdev->pending.status = false;
> + spin_unlock_irqrestore(&data->lock, flags);
> }
> mutex_unlock(hsdev->mutex_ptr);
[Severity: Critical]
This is a pre-existing issue, but doesn't the exact same race condition
fixed here also exist in sensor_hub_input_attr_get_raw_value() in
drivers/hid/hid-sensor-hub.c?
If the wait times out or is interrupted, the state is modified and memory
freed without holding data->lock:
drivers/hid/hid-sensor-hub.c:sensor_hub_input_attr_get_raw_value() {
[ ... ]
kfree(hsdev->pending.raw_data);
hsdev->pending.status = false;
[ ... ]
}
Concurrently, sensor_hub_raw_event() can observe status == true while holding
the lock, and perform an allocation:
drivers/hid/hid-sensor-hub.c:sensor_hub_raw_event() {
[ ... ]
hsdev->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
if (hsdev->pending.raw_data)
[ ... ]
complete(&hsdev->pending.ready);
[ ... ]
}
Can this cause a memory leak when the dynamically allocated buffer is
stranded, and waitqueue list corruption if the waiter has already exited
and reinitialized the completion queue for a new request?
[Severity: Critical]
This is a pre-existing issue, but could sensor_hub_raw_event() in
drivers/hid/hid-sensor-hub.c unconditionally access the usage array without
validating maxusage > 0?
drivers/hid/hid-sensor-hub.c:sensor_hub_raw_event() {
[ ... ]
for (i = 0; i < report->maxfield; ++i) {
hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n",
i, report->field[i]->usage->collection_index,
report->field[i]->usage->hid,
[ ... ]
report->field[i]->usage[0].collection_index,
[ ... ]
}
If a malicious USB device provides a crafted report descriptor defining a
field with zero usages, would this out-of-bounds array access to usage[0]
cause a kernel panic?
[Severity: Critical]
This is a pre-existing issue, but is it possible for sensor_hub_raw_event()
in drivers/hid/hid-sensor-hub.c to copy data from ptr without ensuring it
remains within the bounds of the total received report size?
drivers/hid/hid-sensor-hub.c:sensor_hub_raw_event() {
[ ... ]
memcpy(hsdev->pending.raw_data + hsdev->pending.index,
ptr, copy_size);
[ ... ]
hsdev->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
[ ... ]
}
If a malicious device supplies a report descriptor defining large fields but
sends a truncated input report with a small size, could this read beyond the
end of the raw_data buffer and leak adjacent kernel memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910112338.4171983-1-lhfff@tju.edu.cn?part=1
next prev parent reply other threads:[~2026-09-10 11:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 11:23 [PATCH v1] HID: sensor-hub: synchronize multi-value read cancellation Yibo Tan
2026-09-10 11:35 ` sashiko-bot [this message]
2026-09-10 15:32 ` Andy Shevchenko
2026-09-10 18:28 ` srinivas pandruvada
2026-09-11 5:16 ` Zhang, Lixu
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=20260910113538.AE06E1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=lhfff@tju.edu.cn \
--cc=linux-input@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.