]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: backend: fix uninitialized data in debugfs
authorDan Carpenter <error27@gmail.com>
Mon, 25 May 2026 07:16:11 +0000 (10:16 +0300)
committerJonathan Cameron <jic23@kernel.org>
Tue, 26 May 2026 18:22:57 +0000 (19:22 +0100)
If the *ppos value is non-zero then simple_write_to_buffer() will not
initialize the start of the buf[] buffer.  Non-zero ppos values aren't
going to work at all.  Check for that at the start of the function and
return -ENOSPC.

Fixes: cdf01e0809a4 ("iio: backend: add debugFs interface")
Signed-off-by: Dan Carpenter <error27@gmail.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/industrialio-backend.c

index 10e689f494419b99a47364c258c42a979a332176..cd697fbeae47b23e537100aa47eaed488657d237 100644 (file)
@@ -156,7 +156,7 @@ static ssize_t iio_backend_debugfs_write_reg(struct file *file,
        ssize_t rc;
        int ret;
 
-       if (count >= sizeof(buf))
+       if (*ppos != 0 || count >= sizeof(buf))
                return -ENOSPC;
 
        rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, count);