Skip to contentSkip to conversation

iio: buffer: Ensure bounce buffer used for unaligned case is zeroed.

PATCH In review Jonathan Cameron 4 participants 6 messages Aug 3 – Aug 21 IIO

lore
Share & tools
lore

Jonathan Cameron

author maintainer
#0 lore raw

PATCH v2 1/1 iio: buffer: Ensure bounce buffer used for unaligned case is zeroed.

From: Jonathan Cameron <[email protected]>

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()")

---

v1: https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/

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(-)
drivers/iio/industrialio-buffer.c +2 -1
index 531fc4ccc15d..4960c8377932 100644
@@ -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;
Signature · 1 line
2.55.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Jonathan Cameron

From: Jonathan Cameron <[email protected]>

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.

Quoted 5 lines
Fixes 95ec3fdf2b79 ("iio: core: Introduce iio_push_to_buffers_with_ts_unaligned()")

---

Quoted 24 lines

v1: https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/

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(-)
drivers/iio/industrialio-buffer.c +0 -0
index 531fc4ccc15d..4960c8377932 100644
@@ -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,

drivers/iio/industrialio-buffer.c +2 -1
-				   indio_dev->scan_bytes, GFP_KERNEL);
+				   indio_dev->scan_bytes,
+				   GFP_KERNEL | __GFP_ZERO);

  if (!bb)
  return -ENOMEM; iio_dev_opaque->bounce_buffer = bb;

Reviewed-by on v2 1/1
#2 lore raw
In reply to Jonathan Cameron
Quoted 7 lines · On Mon, 3 Aug 2026 02:22:24 +0100 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

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.

Quoted 5 lines
Fixes 95ec3fdf2b79 ("iio: core: Introduce iio_push_to_buffers_with_ts_unaligned()")

---

LGTM, but shouldn't this be a V3 as the previous patch was a V2? I got confused for a bit...

Signature · 2 lines
Kind regards,
Joshua Crofts
author maintainer
#3 lore raw
Quoted 10 lines · On Mon, 3 Aug 2026 11:26:37 +0200 Joshua Crofts <[email protected]>…
Quoted 7 lines · On Mon, 3 Aug 2026 02:22:24 +0100 Jonathan Cameron <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

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.

Quoted 8 lines
Quoted 5 lines
Fixes 95ec3fdf2b79 ("iio: core: Introduce iio_push_to_buffers_with_ts_unaligned()")

---

LGTM, but shouldn't this be a V3 as the previous patch was a V2? I got confused for a bit...

Oops. Indeed. Fat fingered.

Quoted 3 lines
Reviewed-by on v2 1/1
#4 lore raw
In reply to Jonathan Cameron
Quoted 4 lines · 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. Specify __GFP_ZERO for the devm_krealloc() to ensure any extra space is cleared.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer Applied
#5 lore raw
Quoted 9 lines · On Tue, 11 Aug 2026 13:32:44 +0300 Andy Shevchenko…
Quoted 4 lines · 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. Specify __GFP_ZERO for the devm_krealloc() to ensure any extra space is cleared.

Applied to the fixes-togreg branch of iio.git and marked for stable.

Usual stuff about rebasing on rc1 etc apply

J