Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sanjay Chitroda" <sanjayembeddedse@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 05/11] iio: humidity: hid-sensor-humidity: use common device for devres
Date: Tue, 16 Jun 2026 11:27:38 +0000	[thread overview]
Message-ID: <20260616112738.D11A41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260616-15-jun-hid-iio-alignment-v1-5-0cd544286575@gmail.com>

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

New issues:
- [High] Changing the devm allocation parent from the IIO device to the platform device creates a dangling pointer, as the IIO device can outlive the platform device.

Pre-existing issues:
- [High] The driver shares a single static global `struct hid_sensor_hub_callbacks humidity_callbacks` which is overwritten by each probed device, causing data corruption and Use-After-Free.
--

commit ba18caab7a04132bf9ca0d7432b6f7dcfedfbc00
Author: Sanjay Chitroda <sanjayembeddedse@gmail.com>

iio: humidity: hid-sensor-humidity: use common device for devres

This patch changes the devres allocation parent for the humidity channels
array. It moves the ownership from the IIO device to the HID platform
device to consolidate the devres ownership tree.

> diff --git a/drivers/iio/humidity/hid-sensor-humidity.c b/drivers/iio/humidity/hid-sensor-humidity.c
> index 6fed019f4099f..73120b87d641d 100644
> --- a/drivers/iio/humidity/hid-sensor-humidity.c
> +++ b/drivers/iio/humidity/hid-sensor-humidity.c
> @@ -215,7 +215,7 @@ static int hid_humidity_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	humid_chans = devm_kmemdup(&indio_dev->dev, humidity_channels,
> +	humid_chans = devm_kmemdup(&pdev->dev, humidity_channels,
>  				   sizeof(humidity_channels), GFP_KERNEL);

[Severity: High]
Does changing the devm allocation parent to the platform device create a
dangling pointer here?

In the IIO subsystem, the iio_dev object is reference-counted and can outlive
the platform device if userspace holds open file descriptors (for example,
/dev/iio:deviceX). Devres resources attached to pdev->dev are freed
unconditionally when the driver unbinds, but resources attached to
indio_dev->dev live until the iio_dev reference count drops to zero.

By moving the allocation of humidity_channels to pdev->dev, won't
indio_dev->channels point to freed memory immediately after unbind, leading
to a use-after-free if the IIO core or userspace continues to interact with
the still-alive iio_dev?

>  	if (!humid_chans)
>  		return -ENOMEM;

[ ... ]

While looking at hid_humidity_probe(), I noticed another detail:

drivers/iio/humidity/hid-sensor-humidity.c:hid_humidity_probe() {
	...
	humidity_callbacks.pdev = pdev;
	ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_HUMIDITY,
					   &humidity_callbacks);
	...
}

[Severity: High]
This is a pre-existing issue, but does assigning the local platform device to
the globally shared humidity_callbacks structure cause state corruption?

If a system has multiple humidity sensors probed, it appears the pdev of the
last probed sensor overwrites the pointer for all previous instances.

When sensor_hub_raw_event() dispatches an event for an earlier sensor, it
calls callback->capture_sample() with the overwritten pdev. Could this
corrupt the state of the newer sensor, or cause a use-after-free if the
newer sensor is unbound while the older one remains active?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260616-15-jun-hid-iio-alignment-v1-0-0cd544286575@gmail.com?part=5

  reply	other threads:[~2026-06-16 11:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-16 10:26 [PATCH 00/11] HID: iio: warning clean up and prefer kernel coding style Sanjay Chitroda
2026-06-16 10:26 ` [PATCH 01/11] iio: hid-sensors: add missing blank line after declarations Sanjay Chitroda
2026-06-16 11:22   ` sashiko-bot
2026-06-16 10:26 ` [PATCH 02/11] iio: humidity: hid-sensor-humidity: align parenthesis for readability Sanjay Chitroda
2026-06-16 10:57   ` Andy Shevchenko
2026-06-16 11:22   ` sashiko-bot
2026-06-16 10:26 ` [PATCH 03/11] iio: gyro: hid-sensor-gyro-3d: " Sanjay Chitroda
2026-06-16 10:56   ` Andy Shevchenko
2026-06-16 10:26 ` [PATCH 04/11] iio: magnetometer: hid-sensor-magn-3d: " Sanjay Chitroda
2026-06-16 11:19   ` sashiko-bot
2026-06-16 10:26 ` [PATCH 05/11] iio: humidity: hid-sensor-humidity: use common device for devres Sanjay Chitroda
2026-06-16 11:27   ` sashiko-bot [this message]
2026-06-16 10:26 ` [PATCH 06/11] iio: position: hid-sensor-custom-intel-hinge: " Sanjay Chitroda
2026-06-16 10:26 ` [PATCH 07/11] iio: temperature: hid-sensor-temperature: " Sanjay Chitroda
2026-06-16 11:27   ` sashiko-bot
2026-06-16 10:26 ` [PATCH 08/11] iio: hid-sensor-magn-3d: use ! instead of explicit NULL check Sanjay Chitroda
2026-06-16 11:01   ` Joshua Crofts
2026-06-16 10:26 ` [PATCH 09/11] iio: hid-sensor-rotation: " Sanjay Chitroda
2026-06-16 10:26 ` [PATCH 10/11] iio: hid-sensor-incl-3d: " Sanjay Chitroda
2026-06-16 11:11 ` [PATCH 11/11] iio: hid-sensor-accel-3d: " Sanjay Chitroda

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=20260616112738.D11A41F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sanjayembeddedse@gmail.com \
    --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