iio: buffer: Ensure bounce buffer used for unaligned case is zeroed.
Jonathan Cameron
maintainerPATCH 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.
---
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
@@ -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
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_ZEROfor thedevm_krealloc()to ensure any extra space is cleared.
Quoted 5 lines
Fixes 95ec3fdf2b79 ("iio: core: Introduce iio_push_to_buffers_with_ts_unaligned()")Reported-by Sashiko <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>---
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@@ -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;
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_ZEROfor thedevm_krealloc()to ensure any extra space is cleared.
Quoted 5 lines
Fixes 95ec3fdf2b79 ("iio: core: Introduce iio_push_to_buffers_with_ts_unaligned()")Reported-by Sashiko <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>---
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
Jonathan Cameron
maintainerQuoted 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_ZEROfor thedevm_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()")Reported-by Sashiko <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>---
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 Joshua Crofts <[email protected]>
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_ZEROfor thedevm_krealloc()to ensure any extra space is cleared.
Signature · 2 lines
With Best Regards, Andy Shevchenko
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_ZEROfor thedevm_krealloc()to ensure any extra space is cleared.Reviewed-by Andy Shevchenko <[email protected]>
Applied to the fixes-togreg branch of iio.git and marked for stable.
Usual stuff about rebasing on rc1 etc apply
J