Devicetree
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: joseph@telaak.dev
Cc: "Pavel Machek" <pavel@kernel.org>,
	"Griffin Kroah-Hartman" <griffin@kroah.com>,
	"Kees Cook" <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"André Apitzsch" <git@apitzsch.eu>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org, devicetree@vger.kernel.org,
	linux-doc@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 02/11] leds: rgb: ktd202x: Fix an out-of-bounds read with unused channels
Date: Thu, 19 Nov 2026 10:22:46 +0000	[thread overview]
Message-ID: <20261119102246.GO98456@joneslee-macbookpro.roam.internal> (raw)
In-Reply-To: <20261109-ktd202x-et6326-v2-2-56e97c226658@telaak.dev>

On Mon, 09 Nov 2026, Joseph Telaak via B4 Relay wrote:

> From: Joseph Telaak <joseph@telaak.dev>
> 
> The LED array is allocated for the number of child nodes, but
> ktd202x_chip_in_use() walks it up to num_leds, the number of channels of
> the chip. With fewer LEDs in the device tree than channels, for example
> two LEDs on a KTD2026, it reads past the end of the allocation and the
> __counted_by() annotation hides that from the bounds checkers.
> 
> Allocate one entry per channel.
> 
> Fixes: 0ebdb7210943 ("leds: Add ktd202x driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Joseph Telaak <joseph@telaak.dev>
> ---
>  drivers/leds/rgb/leds-ktd202x.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/leds/rgb/leds-ktd202x.c b/drivers/leds/rgb/leds-ktd202x.c
> index 539cf425cdb7..482af28e8370 100644
> --- a/drivers/leds/rgb/leds-ktd202x.c
> +++ b/drivers/leds/rgb/leds-ktd202x.c
> @@ -537,6 +537,7 @@ static int ktd202x_probe(struct i2c_client *client)
>  {
>  	struct device *dev = &client->dev;
>  	struct ktd202x *chip;
> +	unsigned long num_leds;
>  	int count;
>  	int ret;
>  
> @@ -544,10 +545,13 @@ static int ktd202x_probe(struct i2c_client *client)
>  	if (!count || count > KTD202X_MAX_LEDS)
>  		return dev_err_probe(dev, -EINVAL, "Incorrect number of leds (%d)", count);
>  
> -	chip = devm_kzalloc(dev, struct_size(chip, leds, count), GFP_KERNEL);
> +	/* Loops over the LEDs go up to the number of channels, not of child nodes */
> +	num_leds = (unsigned long)i2c_get_match_data(client);

Nit: Too squishy - '\n'

> +	chip = devm_kzalloc(dev, struct_size(chip, leds, num_leds), GFP_KERNEL);
>  	if (!chip)
>  		return -ENOMEM;
>  
> +	chip->num_leds = num_leds;
>  	chip->dev = dev;
>  	i2c_set_clientdata(client, chip);
>  
> @@ -562,8 +566,6 @@ static int ktd202x_probe(struct i2c_client *client)
>  	if (ret)
>  		return ret;
>  
> -	chip->num_leds = (unsigned long)i2c_get_match_data(client);
> -
>  	chip->regulators[0].supply = "vin";
>  	chip->regulators[1].supply = "vio";
>  	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(chip->regulators), chip->regulators);
> 
> -- 
> Git-155)
> 
> 

-- 
Lee Jones

  reply	other threads:[~2026-11-19 10:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 19:03 [PATCH v2 00/11] leds: ktd202x: Add Etek ET6326, hardware breathing and fixes Joseph Telaak via B4 Relay
2026-11-09 19:03 ` [PATCH v2 01/11] leds: rgb: ktd202x: Fix the flash period of short blinks on 32 bit Joseph Telaak via B4 Relay
2026-11-09 19:03 ` [PATCH v2 02/11] leds: rgb: ktd202x: Fix an out-of-bounds read with unused channels Joseph Telaak via B4 Relay
2026-11-19 10:22   ` Lee Jones [this message]
2026-11-09 19:03 ` [PATCH v2 03/11] leds: rgb: ktd202x: Never program an on time of zero Joseph Telaak via B4 Relay
2026-11-09 19:03 ` [PATCH v2 04/11] leds: rgb: ktd202x: Fix a division by zero with long blinks Joseph Telaak via B4 Relay
2026-11-09 19:03 ` [PATCH v2 05/11] leds: rgb: ktd202x: Keep the unlit colors of a blinking LED off Joseph Telaak via B4 Relay
2026-11-19 10:37   ` Lee Jones
2026-11-09 19:03 ` [PATCH v2 06/11] dt-bindings: leds: kinetic,ktd202x: Add Etek ET6326 Joseph Telaak via B4 Relay
2026-11-09 19:03 ` [PATCH v2 07/11] leds: rgb: ktd202x: Add Etek ET6326 support Joseph Telaak via B4 Relay
2026-11-19 12:33   ` Lee Jones
2026-11-09 19:03 ` [PATCH v2 08/11] leds: rgb: ktd202x: Add hardware pattern support Joseph Telaak via B4 Relay
2026-11-19 10:20   ` Lee Jones
2026-11-09 19:03 ` [PATCH v2 09/11] leds: rgb: ktd202x: Limit the LED current to led-max-microamp Joseph Telaak via B4 Relay
2026-11-09 19:03 ` [PATCH v2 10/11] leds: rgb: ktd202x: Fail the probe when the chip does not answer Joseph Telaak via B4 Relay
2026-11-09 19:03 ` [PATCH v2 11/11] leds: rgb: ktd202x: Don't let a blinking LED retime another one Joseph Telaak via B4 Relay
2026-11-09 19:27   ` sashiko-bot
2026-11-19 10:10     ` Lee Jones

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=20261119102246.GO98456@joneslee-macbookpro.roam.internal \
    --to=lee@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=git@apitzsch.eu \
    --cc=griffin@kroah.com \
    --cc=gustavoars@kernel.org \
    --cc=joseph@telaak.dev \
    --cc=kees@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=stable@vger.kernel.org \
    /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