Skip to content

Commit 16285a0

Browse files
Markus Burrijic23
authored andcommitted
iio: fix potential out-of-bound write
The buffer is set to 20 characters. If a caller write more characters, count is truncated to the max available space in "simple_write_to_buffer". To protect from OoB access, check that the input size fit into buffer and add a zero terminator after copy to the end of the copied data. Fixes: 6d5dd48 iio: core: make use of simple_write_to_buffer() Signed-off-by: Markus Burri <markus.burri@mt.com> Link: https://patch.msgid.link/20250508130612.82270-4-markus.burri@mt.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent da93748 commit 16285a0

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/iio/industrialio-core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,15 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
411411
char buf[80];
412412
int ret;
413413

414+
if (count >= sizeof(buf))
415+
return -EINVAL;
416+
414417
ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf,
415418
count);
416419
if (ret < 0)
417420
return ret;
418421

419-
buf[count] = '\0';
422+
buf[ret] = '\0';
420423

421424
ret = sscanf(buf, "%i %i", &reg, &val);
422425

0 commit comments

Comments
 (0)