linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: Fix a null pointer dereference in pac1934_acpi_parse_channel_config
@ 2025-09-01  6:45 Charles Han
  2025-09-01 16:49 ` Jonathan Cameron
  2025-09-01 16:49 ` David Lechner
  0 siblings, 2 replies; 3+ messages in thread
From: Charles Han @ 2025-09-01  6:45 UTC (permalink / raw)
  To: marius.cristea, jic23, dlechner, nuno.sa, andy
  Cc: linux-iio, linux-kernel, Charles Han

Add check for the return value of devm_kmemdup()
to prevent potential null pointer dereference.

Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/iio/adc/pac1934.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
index 2e442e46f679..95c9d14b5529 100644
--- a/drivers/iio/adc/pac1934.c
+++ b/drivers/iio/adc/pac1934.c
@@ -1108,6 +1108,9 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
 			devm_kmemdup(dev, rez->package.elements[i].string.pointer,
 				     (size_t)rez->package.elements[i].string.length + 1,
 				     GFP_KERNEL);
+		if (!info->labels[idx])
+			return -ENOMEM;
+
 		info->labels[idx][rez->package.elements[i].string.length] = '\0';
 		info->shunts[idx] = rez->package.elements[i + 1].integer.value * 1000;
 		info->active_channels[idx] = (info->shunts[idx] != 0);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: Fix a null pointer dereference in pac1934_acpi_parse_channel_config
  2025-09-01  6:45 [PATCH] iio: adc: Fix a null pointer dereference in pac1934_acpi_parse_channel_config Charles Han
@ 2025-09-01 16:49 ` Jonathan Cameron
  2025-09-01 16:49 ` David Lechner
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2025-09-01 16:49 UTC (permalink / raw)
  To: Charles Han
  Cc: marius.cristea, dlechner, nuno.sa, andy, linux-iio, linux-kernel

On Mon, 1 Sep 2025 14:45:11 +0800
Charles Han <hanchunchao@inspur.com> wrote:

> Add check for the return value of devm_kmemdup()
> to prevent potential null pointer dereference.
> 
> Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
Good catch, but not that simple. This just leaked an ACPI resource that was
held over the loop this is in. See the ACPI_FREE() that follows it.

Jonathan

> ---
>  drivers/iio/adc/pac1934.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
> index 2e442e46f679..95c9d14b5529 100644
> --- a/drivers/iio/adc/pac1934.c
> +++ b/drivers/iio/adc/pac1934.c
> @@ -1108,6 +1108,9 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
>  			devm_kmemdup(dev, rez->package.elements[i].string.pointer,
>  				     (size_t)rez->package.elements[i].string.length + 1,
>  				     GFP_KERNEL);
> +		if (!info->labels[idx])
> +			return -ENOMEM;
> +
>  		info->labels[idx][rez->package.elements[i].string.length] = '\0';
>  		info->shunts[idx] = rez->package.elements[i + 1].integer.value * 1000;
>  		info->active_channels[idx] = (info->shunts[idx] != 0);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: Fix a null pointer dereference in pac1934_acpi_parse_channel_config
  2025-09-01  6:45 [PATCH] iio: adc: Fix a null pointer dereference in pac1934_acpi_parse_channel_config Charles Han
  2025-09-01 16:49 ` Jonathan Cameron
@ 2025-09-01 16:49 ` David Lechner
  1 sibling, 0 replies; 3+ messages in thread
From: David Lechner @ 2025-09-01 16:49 UTC (permalink / raw)
  To: Charles Han, marius.cristea, jic23, nuno.sa, andy; +Cc: linux-iio, linux-kernel

On 9/1/25 1:45 AM, Charles Han wrote:
> Add check for the return value of devm_kmemdup()
> to prevent potential null pointer dereference.
> 
> Fixes: 0fb528c8255b ("iio: adc: adding support for PAC193x")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
Reviewed-by: David Lechner <dlechner@baylibre.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-01 16:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01  6:45 [PATCH] iio: adc: Fix a null pointer dereference in pac1934_acpi_parse_channel_config Charles Han
2025-09-01 16:49 ` Jonathan Cameron
2025-09-01 16:49 ` David Lechner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).