Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christopher Hoover" <ch@murgatroid.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 1/2] iio: temperature: hid-sensor-temperature: Use per-instance callbacks
Date: Wed, 07 Oct 2026 07:44:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-162723@kernel.org> (raw)
In-Reply-To: <20261007072329.27806-2-ch@murgatroid.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] iio: hid-sensor-temperature: Use-After-Free of callback struct on unbind
--

commit c0e839b50a28c72b4e45a4af57921da5a4656f96
Author: Christopher Hoover <ch@murgatroid.com>

iio: temperature: hid-sensor-temperature: Use per-instance callbacks

This patch moves the hid_sensor_hub_callbacks structure from a static
global variable to the dynamically allocated temperature_state structure
to fix an issue where platform devices are overwritten in a multi-sensor
setup.

Cc: stable@vger.kernel.org

> diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c
> index 5e3262e461f46..35b8643305b9f 100644
> --- a/drivers/iio/temperature/hid-sensor-temperature.c
> +++ b/drivers/iio/temperature/hid-sensor-temperature.c
[ ... ]
> @@ -237,9 +233,11 @@ static int hid_temperature_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, indio_dev);
>  
> -	temperature_callbacks.pdev = pdev;
> +	temp_st->callbacks.send_event = temperature_proc_event;
> +	temp_st->callbacks.capture_sample = temperature_capture_sample;
> +	temp_st->callbacks.pdev = pdev;
>  	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TEMPERATURE,
> -					   &temperature_callbacks);
> +					   &temp_st->callbacks);

[Severity: High]
Could this change introduce a use-after-free during driver unbind?

Since temp_st is allocated using devm_iio_device_alloc(), its lifetime is now
tied to the driver bind lifecycle and it will be freed automatically after
the remove callback returns.

During unbind, hid_temperature_remove() calls sensor_hub_remove_callback().
This removes the callback from dyn_callback_list, but does not synchronize
with a concurrently executing sensor_hub_raw_event() on another CPU:

drivers/hid/hid-sensor-hub.c:sensor_hub_raw_event() {
    ...
    if (callback->capture_sample) {
        if (report->field[i]->logical)
            callback->capture_sample(hsdev, ...);
    ...
}

If sensor_hub_remove_callback() finishes and devres frees temp_st while
sensor_hub_raw_event() is still running, could the raw event path
dereference the freed callback function pointers?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261007072329.27806-1-ch@murgatroid.com?part=1

  reply	other threads:[~2026-10-07  7:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07  7:23 [PATCH 0/2] iio: hid-sensors: fix shared callbacks in temperature and humidity Christopher Hoover
2026-10-07  7:23 ` [PATCH 1/2] iio: temperature: hid-sensor-temperature: Use per-instance callbacks Christopher Hoover
2026-10-07  7:44   ` sashiko-bot [this message]
2026-10-07  7:23 ` [PATCH 2/2] iio: humidity: hid-sensor-humidity: " Christopher Hoover
2026-10-07 18:44 ` [PATCH v2 0/3] iio: hid-sensors: fix shared callbacks in temperature and humidity Christopher Hoover
2026-10-07 18:44   ` [PATCH v2 1/3] HID: hid-sensor-hub: Synchronize callback removal with raw events Christopher Hoover
2026-10-07 18:44   ` [PATCH v2 2/3] iio: temperature: hid-sensor-temperature: Use per-instance callbacks Christopher Hoover
2026-10-07 18:44   ` [PATCH v2 3/3] iio: humidity: hid-sensor-humidity: " Christopher Hoover
2026-10-08  7:54   ` [PATCH v2 0/3] iio: hid-sensors: fix shared callbacks in temperature and humidity Joshua Crofts
2026-10-08  7:55   ` Joshua Crofts

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=sashiko-outbox-162723@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ch@murgatroid.com \
    --cc=dmitry.torokhov@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox