[PATCH 09/11] iio: dummy: iio_simply_dummy_buffer: fix information leak in triggered buffer

Javier Carrasco posted 11 patches 1 year, 2 months ago
There is a newer version of this series
[PATCH 09/11] iio: dummy: iio_simply_dummy_buffer: fix information leak in triggered buffer
Posted by Javier Carrasco 1 year, 2 months ago
The 'data' array is allocated via kmalloc() and it is used to push data
to user space from a triggered buffer, but it does not set values for
inactive channels, as it only uses iio_for_each_active_channel()
to assign new values.

Use kzalloc for the memory allocation to avoid pushing uninitialized
information to userspace.

Cc: stable@vger.kernel.org
Fixes: 415f79244757 ("iio: Move IIO Dummy Driver out of staging")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/iio/dummy/iio_simple_dummy_buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/dummy/iio_simple_dummy_buffer.c b/drivers/iio/dummy/iio_simple_dummy_buffer.c
index 4ca3f1aaff99..288880346707 100644
--- a/drivers/iio/dummy/iio_simple_dummy_buffer.c
+++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c
@@ -48,7 +48,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 	int i = 0, j;
 	u16 *data;
 
-	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
+	data = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (!data)
 		goto done;
 

-- 
2.43.0
Re: [PATCH 09/11] iio: dummy: iio_simply_dummy_buffer: fix information leak in triggered buffer
Posted by Jonathan Cameron 1 year, 2 months ago
On Mon, 25 Nov 2024 22:16:17 +0100
Javier Carrasco <javier.carrasco.cruz@gmail.com> wrote:

> The 'data' array is allocated via kmalloc() and it is used to push data
> to user space from a triggered buffer, but it does not set values for
> inactive channels, as it only uses iio_for_each_active_channel()
> to assign new values.
> 
> Use kzalloc for the memory allocation to avoid pushing uninitialized
> information to userspace.
> 
> Cc: stable@vger.kernel.org
> Fixes: 415f79244757 ("iio: Move IIO Dummy Driver out of staging")
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Oops. Got it wrong even in the example driver.

Applied to the fixes-togreg branch of iio.git.

Thanks,

Jonathan

> ---
>  drivers/iio/dummy/iio_simple_dummy_buffer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/dummy/iio_simple_dummy_buffer.c b/drivers/iio/dummy/iio_simple_dummy_buffer.c
> index 4ca3f1aaff99..288880346707 100644
> --- a/drivers/iio/dummy/iio_simple_dummy_buffer.c
> +++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c
> @@ -48,7 +48,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
>  	int i = 0, j;
>  	u16 *data;
>  
> -	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
> +	data = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
>  	if (!data)
>  		goto done;
>  
>