All of lore.kernel.org
 help / color / mirror / Atom feed
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 v2] HID: sensor-hub: Fail unfinished multi-value reads on removal
Date: Sat, 12 Sep 2026 05:16:29 +0000	[thread overview]
Message-ID: <20260912051630.6029A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260912050257.837340-1-lhfff@tju.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Missing spinlock synchronization when aborting synchronous reads on timeout or signal allows a concurrent HID report to overwrite a popped stack frame or leak heap memory.
--

commit d72580296b294439ca880b1a4de796414e3195a6
Author: Yibo Tan <lhfff@tju.edu.cn>

    HID: sensor-hub: Fail unfinished multi-value reads on removal
    
    sensor_hub_remove() completes pending reads after stopping the HID device,
    but does not record why they completed.  A successful completion wait
    therefore returns zero even if no complete input report was received.

Link: https://github.com/kimaiden1984-boop/linux-kernel-poc-collections/tree/main/cases/hid-sensor-quaternion-root-b-kaslr [1]

> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
> index 6470a290ebfc5..687f8defa2f0d 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -334,6 +334,8 @@ int sensor_hub_input_attr_read_values(struct hid_sensor_hub_device *hsdev,
>  			ret = -ETIMEDOUT;
>  		else if (cycles < 0)
>  			ret = cycles;
> +		else if (hsdev->pending.raw_size < 0)
> +			ret = hsdev->pending.raw_size;
>  
>  		hsdev->pending.status = false;

[Severity: Critical]
This is a pre-existing issue, but missing spinlock synchronization when aborting
synchronous reads on timeout or signal allows a concurrent HID report to
overwrite a popped stack frame.

Can a local unprivileged user trigger a stack buffer overflow here by reading
a multi-value IIO attribute, sleeping in
wait_for_completion_interruptible_timeout(), and then sending a signal to
their own process?

If the wait is aborted by a signal, this code locklessly clears
hsdev->pending.status.

If a hardware HID report interrupt arrives concurrently, it acquires
pdata->lock in sensor_hub_raw_event():

drivers/hid/hid-sensor-hub.c:sensor_hub_raw_event() {
    ...
    spin_lock_irqsave(&pdata->lock, flags);
    ...
    if (hsdev->pending.status && ...) {
        if (hsdev->pending.max_raw_size) {
            ...
            memcpy(hsdev->pending.raw_data + hsdev->pending.index,
                   ptr, copy_size);

Could the interrupt observe status as true and execute memcpy() copying
attacker-influenced HID data into hsdev->pending.raw_data, which now points to
a freed stack frame since sensor_hub_input_attr_read_values() already returned?

This same pattern also appears in sensor_hub_input_attr_get_raw_value():

drivers/hid/hid-sensor-hub.c:sensor_hub_input_attr_get_raw_value() {
    ...
    if (flag == SENSOR_HUB_SYNC) {
        wait_for_completion_interruptible_timeout(&hsdev->pending.ready, HZ*5);
        ...
        kfree(hsdev->pending.raw_data);
        hsdev->pending.status = false;
    }

If an interrupt arrives immediately after the wait is aborted and executes:

drivers/hid/hid-sensor-hub.c:sensor_hub_raw_event() {
    ...
    } else {
        hsdev->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
        ...
    }

Does this memory leak, since the kmemdup() allocates a buffer that the waiting
thread has already abandoned?

>  	}
>  	mutex_unlock(hsdev->mutex_ptr);
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260912050257.837340-1-lhfff@tju.edu.cn?part=1

  reply	other threads:[~2026-09-12  5:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11  9:20 [PATCH v1] HID: sensor-hub: Fail unfinished multi-value reads on removal Yibo Tan
2026-09-11  9:37 ` sashiko-bot
2026-09-11  9:42 ` Andy Shevchenko
2026-09-12  5:02   ` [PATCH v2] " Yibo Tan
2026-09-12  5:16     ` sashiko-bot [this message]
2026-09-13  3:54     ` [PATCH v2] HID: sensor-hub: Fail unfinished multi-value reads on remo Jonathan Cameron
2026-09-13  7:29       ` [PATCH v3] HID: sensor-hub: Fail unfinished multi-value reads on removal Yibo Tan
2026-09-13  7:45         ` sashiko-bot
2026-09-13 15:50         ` srinivas pandruvada
2026-09-13 17:21           ` Jonathan Cameron

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=20260912051630.6029A1F000FF@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.