iio: dac: ad3552r-hs: fix uninitialized data ni ad3552r_hs_write_data_source()
Subsystems (3)
PATCH 1/1 iio: dac: ad3552r-hs: fix uninitialized data ni ad3552r_hs_write_data_source()
If the *ppos value is non-zero then the simple_write_to_buffer() function won't initialized the start of the buf[] buffer. Non-zero values for *ppos won't work here generally, so just test for them and return -EINVAL at the start of the function.
--- drivers/iio/dac/ad3552r-hs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/dac/ad3552r-hs.c +1 -1
@@ -549,7 +549,7 @@ static ssize_t ad3552r_hs_write_data_source(struct file *f,guard (mutex)(&st->lock); -if (count >=sizeof (buf)) +if (*ppos !=0 || count >=sizeof (buf))return -ENOSPC ; ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
Signature · 1 line
2.53.0
Hi Dan,
Quoted 16 lines · Dan Carpenter
If the *ppos value is non-zero then the
simple_write_to_buffer()function won't initialized the start of the buf[] buffer. Non-zero values for *ppos won't work here generally, so just test for them and return-EINVALat the start of the function.Fixes b1c5d68ea66e ("iio: dac: ad3552r-hs: add support for internal ramp")Signed-off-by Dan Carpenter <[email protected]>--- drivers/iio/dac/ad3552r-hs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/dac/ad3552r-hs.c +0
-0
drivers/iio/dac/ad3552r-hs.c static ssize_t ad3552r_hs_write_data_source(struct file *f,
Quoted 9 lines
drivers/iio/dac/ad3552r-hs.c +1
-2@@ -549,7 +549,7 @@ static ssize_t ad3552r_hs_write_data_source(struct file *f,guard (mutex)(&st->lock); -if (count >=sizeof (buf)) +if (*ppos !=0 || count >=sizeof (buf))return -ENOSPC ; ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, --
thanks for the fix,
it looks like this may fix an additional overflow in case ppos is near the end of buf[].
But i am actually missing the use case when ppos is non zero, can this happen from shell "echo" ? Or some fseek/dd is needed to trigger it ?
Thanks,
regards,
angelo
Quoted 2 lines
2.53.0
Quoted 31 lines · Angelo Dureghello
Hi Dan,
Quoted 16 lines · Dan Carpenter
If the *ppos value is non-zero then the
simple_write_to_buffer()function won't initialized the start of the buf[] buffer. Non-zero values for *ppos won't work here generally, so just test for them and return-EINVALat the start of the function.Fixes b1c5d68ea66e ("iio: dac: ad3552r-hs: add support for internal ramp")Signed-off-by Dan Carpenter <[email protected]>--- drivers/iio/dac/ad3552r-hs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/dac/ad3552r-hs.c +0
-0drivers/iio/dac/ad3552r-hs.c static ssize_t ad3552r_hs_write_data_source(struct file *f,
Quoted 9 lines
drivers/iio/dac/ad3552r-hs.c +1
-2@@ -549,7 +549,7 @@ static ssize_t ad3552r_hs_write_data_source(struct file *f,guard (mutex)(&st->lock); -if (count >=sizeof (buf)) +if (*ppos !=0 || count >=sizeof (buf))return -ENOSPC ; ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, --thanks for the fix,
Quoted 4 lines
Reviewed-by Angelo Dureghello <[email protected]>it looks like this may fix an additional overflow in case ppos is near the end of buf[].
simple_write_to_buffer() won't overflow. It takes ppos into consideration properly.
Quoted 2 lines
But i am actually missing the use case when ppos is non zero, can this happen from shell "echo" ? Or some fseek/dd is needed to trigger it ?
I've never actually tried to do this. I think lseek() or fseek() would work. But also the simple_write_to_buffer() function itself updates *ppos so multiple writes would do the trick as well.
regards,
dan carpenter
Hi Dan,
Quoted 6 lines · Dan Carpenter
If the *ppos value is non-zero then the
simple_write_to_buffer()function won't initialized the start of the buf[] buffer. Non-zero values for *ppos won't work here generally, so just test for them and return-EINVALat the start of the function.
Please see my other email, you're also returning -ENOSPC instead of -EINVAL here...
Quoted 12 lines
Fixes b1c5d68ea66e ("iio: dac: ad3552r-hs: add support for internal ramp")Signed-off-by Dan Carpenter <[email protected]>--- drivers/iio/dac/ad3552r-hs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/dac/ad3552r-hs.c +0
-0
drivers/iio/dac/ad3552r-hs.c static ssize_t ad3552r_hs_write_data_source(struct file *f, · line 554
Quoted 7 lines
drivers/iio/dac/ad3552r-hs.c +1
-1@@ -549,7 +549,7 @@ static ssize_t ad3552r_hs_write_data_source(struct file *f,guard (mutex)(&st->lock); -if (count >=sizeof (buf)) +if (*ppos !=0 || count >=sizeof (buf))return -ENOSPC ;
See above comment.
best regards,
max
Quoted 5 lines
drivers/iio/dac/ad3552r-hs.c +0
-1ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, --2.53.0
Quoted 4 lines · On Mon, 25 May 2026 08:21:51 -0500 Maxwell Doose <[email protected]> wrote:
Hi Dan,
Quoted 1 line · Dan Carpenter
Quoted 9 lines
Quoted 5 lines
If the *ppos value is non-zero then the
simple_write_to_buffer()function won't initialized the start of the buf[] buffer. Non-zero values for *ppos won't work here generally, so just test for them and return-EINVALat the start of the function.Please see my other email, you're also returning
-ENOSPCinstead of-EINVALhere...
Good spot. Tweaked whilst applying.
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks
Jonathan
Quoted 32 lines
Quoted 12 lines
Fixes b1c5d68ea66e ("iio: dac: ad3552r-hs: add support for internal ramp")Signed-off-by Dan Carpenter <[email protected]>--- drivers/iio/dac/ad3552r-hs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/dac/ad3552r-hs.c +0
-0drivers/iio/dac/ad3552r-hs.c static ssize_t ad3552r_hs_write_data_source(struct file *f, · line 554
Quoted 7 lines
drivers/iio/dac/ad3552r-hs.c +1
-1@@ -549,7 +549,7 @@ static ssize_t ad3552r_hs_write_data_source(struct file *f,guard (mutex)(&st->lock); -if (count >=sizeof (buf)) +if (*ppos !=0 || count >=sizeof (buf))return -ENOSPC ;See above comment.
best regards,
maxQuoted 5 lines
drivers/iio/dac/ad3552r-hs.c +0
-1ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, --2.53.0