Linux IIO development
 help / color / mirror / Atom feed
* [PATCH v2] iio: buffer: Ensure bounce buffer used for unaligned case is zeroed.
@ 2026-08-03  1:22 Jonathan Cameron
  2026-08-03  9:05 ` Nuno Sá
  2026-08-03  9:26 ` Joshua Crofts
  0 siblings, 2 replies; 9+ messages in thread
From: Jonathan Cameron @ 2026-08-03  1:22 UTC (permalink / raw)
  To: linux-iio
  Cc: Jinseob Kim, Joshua Crofts, Sanjay Chitroda, David Lechner,
	Nuno Sá, Andy Shevchenko, sashiko-bot, Jonathan Cameron,
	Jonathan Cameron

From: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>

iio_push_to_buffers_with_ts_unaligned() leaks uninitialized heap memory
to userspace if the data passed in is not a multiple of 8 bytes and the
timestamp is enabled. Specify __GFP_ZERO for the devm_krealloc()
to ensure any extra space is cleared.

Fixes: 95ec3fdf2b79 ("iio: core: Introduce iio_push_to_buffers_with_ts_unaligned()")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260529121005.1470-1-kimjinseob88%40gmail.com
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
---

v1: https://patchwork.kernel.org/project/linux-iio/patch/20260604084307.640053-1-jic23@kernel.org/

Drop the memset in favour of __GFP_ZERO.  (Andy)
Thanks to Nuno who pointed out there is a self test to ensure this
behaves as expected.

 drivers/iio/industrialio-buffer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 531fc4ccc15d..4960c8377932 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -2464,7 +2464,8 @@ int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev,
 
 		bb = devm_krealloc(&indio_dev->dev,
 				   iio_dev_opaque->bounce_buffer,
-				   indio_dev->scan_bytes, GFP_KERNEL);
+				   indio_dev->scan_bytes,
+				   GFP_KERNEL | __GFP_ZERO);
 		if (!bb)
 			return -ENOMEM;
 		iio_dev_opaque->bounce_buffer = bb;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [PATCH v2] iio: buffer: Ensure bounce buffer used for unaligned case is zeroed.
@ 2026-06-04  8:43 Jonathan Cameron
  2026-06-04  9:10 ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2026-06-04  8:43 UTC (permalink / raw)
  To: linux-iio, Jinseob Kim, Joshua Crofts
  Cc: Sanjay Chitroda, David Lechner, Nuno Sá, Andy Shevchenko,
	sashiko-bot, Jonathan Cameron

iio_push_to_buffers_with_ts_unaligned() leaks uninitialized heap memory
to userspace if the data passed in is not a multiple of 8 bytes and the
timestamp is enabled.  Use memset() to zero it after resizing.

Fixes: 95ec3fdf2b79 ("iio: core: Introduce iio_push_to_buffers_with_ts_unaligned()")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260529121005.1470-1-kimjinseob88%40gmail.com
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
v2: Zero the new buffer not the old one (which might not exist)
    Drop bonus Reported-by:
---
 drivers/iio/industrialio-buffer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 5c3df993bea2..157b0415091a 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -2445,6 +2445,7 @@ int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev,
 				   indio_dev->scan_bytes, GFP_KERNEL);
 		if (!bb)
 			return -ENOMEM;
+		memset(bb, 0, indio_dev->scan_bytes);
 		iio_dev_opaque->bounce_buffer = bb;
 		iio_dev_opaque->bounce_buffer_size = indio_dev->scan_bytes;
 	}
-- 
2.54.0


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

end of thread, other threads:[~2026-08-03  9:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03  1:22 [PATCH v2] iio: buffer: Ensure bounce buffer used for unaligned case is zeroed Jonathan Cameron
2026-08-03  9:05 ` Nuno Sá
2026-08-03  9:26 ` Joshua Crofts
  -- strict thread matches above, loose matches on Subject: below --
2026-06-04  8:43 Jonathan Cameron
2026-06-04  9:10 ` Andy Shevchenko
2026-06-05 13:50   ` Jonathan Cameron
2026-06-05 19:18     ` Andy Shevchenko
2026-06-08 20:00       ` Nuno Sá
2026-06-14 19:52         ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox