]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: qat - uninitialized variable in adf_hb_error_inject_write()
authorDan Carpenter <dan.carpenter@linaro.org>
Tue, 13 Feb 2024 18:09:41 +0000 (21:09 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 24 Feb 2024 00:41:20 +0000 (08:41 +0800)
There are a few issues in this code.  If *ppos is non-zero then the
first part of the buffer is not initialized.  We never initialize the
last character of the buffer.  The return is not checked so it's
possible that none of the buffer is initialized.

This is debugfs code which is root only and the impact of these bugs is
very small.  However, it's still worth fixing.  To fix this:
1) Check that *ppos is zero.
2) Use copy_from_user() instead of simple_write_to_buffer().
3) Explicitly add a NUL terminator.

Fixes: e2b67859ab6e ("crypto: qat - add heartbeat error simulator")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/intel/qat/qat_common/adf_heartbeat_dbgfs.c

index 5cd6c2d6f90ac5e3882fd7d60a63ab6c8c7ff745..cccdff24b48d61baf2c70165c0f0d6be254b18ad 100644 (file)
@@ -160,16 +160,17 @@ static ssize_t adf_hb_error_inject_write(struct file *file,
                                         size_t count, loff_t *ppos)
 {
        struct adf_accel_dev *accel_dev = file->private_data;
-       size_t written_chars;
        char buf[3];
        int ret;
 
        /* last byte left as string termination */
-       if (count != 2)
+       if (*ppos != 0 || count != 2)
                return -EINVAL;
 
-       written_chars = simple_write_to_buffer(buf, sizeof(buf) - 1,
-                                              ppos, user_buf, count);
+       if (copy_from_user(buf, user_buf, count))
+               return -EFAULT;
+       buf[count] = '\0';
+
        if (buf[0] != '1')
                return -EINVAL;
 
@@ -183,7 +184,7 @@ static ssize_t adf_hb_error_inject_write(struct file *file,
 
        dev_info(&GET_DEV(accel_dev), "Heartbeat error injection enabled\n");
 
-       return written_chars;
+       return count;
 }
 
 static const struct file_operations adf_hb_error_inject_fops = {