Linux Input/HID development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Daniel Schaefer via B4 Relay <devnull+dhs.frame.work@kernel.org>
Cc: dhs@frame.work, "Jiri Kosina" <jikos@kernel.org>,
	"Srinivas Pandruvada" <srinivas.pandruvada@linux.intel.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"srinivas pandruvada" <srinivas.pandruvada@intel.com>,
	linux-input@vger.kernel.org, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Sven Vainküla" <sven@xn--vainkla-r2a.ee>
Subject: Re: [PATCH] iio: light: hid-sensor-als: Don't read past the end of short fields
Date: Sun, 1 Nov 2026 03:37:37 +0000	[thread overview]
Message-ID: <20261101033737.6c613263@jic23-hlaptop> (raw)
In-Reply-To: <20261027-iio-als-overread-v1-1-e47e2706368b@frame.work>

On Tue, 27 Oct 2026 18:58:39 +0800
Daniel Schaefer via B4 Relay <devnull+dhs.frame.work@kernel.org> wrote:

> From: Daniel Schaefer <dhs@frame.work>
> 
> Reports are not guaranteed to be 4 bytes.
> On color ALS sensors there are fields that can be shorter than 4 bytes:
> 16-bit illuminance, color temperature and chromaticity x/y.
> 
> I don't have such a sensor right now, but I have emulated one in
> firmware. With this patch, no garbage data is read from the next report:
> 
>   before: 05dc02bc 05dc02bc 190005dc 0ce41900 00000ce4
>   after:  000002bc 000002bc 000005dc 00001900 00000ce4
> 
> Same fix as commit ad02ca57e44e ("iio: hid-sensor-prox: Add support for
> 16-bit report size").
> 
> Fixes: ed5514c925a0 ("iio: hid-sensors: Added ALS")
> Signed-off-by: Daniel Schaefer <dhs@frame.work>
Hi Daniel,

Seems in line with the referenced commit and to make sense to me.
So I'll pick this up now - however still time for more reviews as
I'll need to rebase on rc1 anyway in the next few days.

Applied to the fixes-togreg branch of iio.git

Thanks,

Jonathan

> ---
> Tested on an emulated sensor with 2 byte reports that is correctly recognized
> by Windows.
> 
> Cc: Sven Vainküla <sven@xn--vainkla-r2a.ee>
> ---
>  drivers/iio/light/hid-sensor-als.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
> index 929343e42d83..00dfc2037c19 100644
> --- a/drivers/iio/light/hid-sensor-als.c
> +++ b/drivers/iio/light/hid-sensor-als.c
> @@ -267,7 +267,21 @@ static int als_capture_sample(struct hid_sensor_hub_device *hsdev,
>  	struct iio_dev *indio_dev = platform_get_drvdata(priv);
>  	struct als_state *als_state = iio_priv(indio_dev);
>  	int ret = -EINVAL;
> -	u32 sample_data = *(u32 *)raw_data;
> +	u32 sample_data;
> +
> +	switch (raw_len) {
> +	case 1:
> +		sample_data = *(u8 *)raw_data;
> +		break;
> +	case 2:
> +		sample_data = *(u16 *)raw_data;
> +		break;
> +	default:
> +		if (raw_len < sizeof(u32))
> +			return -EINVAL;
> +		sample_data = *(u32 *)raw_data;
> +		break;
> +	}
>  
>  	switch (usage_id) {
>  	case HID_USAGE_SENSOR_LIGHT_ILLUM:
> 
> ---
> base-commit: 09f742b49cb2728086d78be2b0b35e4d1d71fc85
> change-id: 20261027-iio-als-overread-c9e538fa61fa
> 
> Best regards,


      reply	other threads:[~2026-11-01  3:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 10:58 [PATCH] iio: light: hid-sensor-als: Don't read past the end of short fields Daniel Schaefer via B4 Relay
2026-11-01  3:37 ` Jonathan Cameron [this message]

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=20261101033737.6c613263@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=devnull+dhs.frame.work@kernel.org \
    --cc=dhs@frame.work \
    --cc=dlechner@baylibre.com \
    --cc=jikos@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=srinivas.pandruvada@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=sven@xn--vainkla-r2a.ee \
    /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