Skip to content

Commit bcc06e1

Browse files
Dan Carpenterherbertx
authored andcommitted
crypto: qat - uninitialized variable in adf_hb_error_inject_write()
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: e2b6785 ("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>
1 parent 14af865 commit bcc06e1

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

drivers/crypto/intel/qat/qat_common/adf_heartbeat_dbgfs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,17 @@ static ssize_t adf_hb_error_inject_write(struct file *file,
160160
size_t count, loff_t *ppos)
161161
{
162162
struct adf_accel_dev *accel_dev = file->private_data;
163-
size_t written_chars;
164163
char buf[3];
165164
int ret;
166165

167166
/* last byte left as string termination */
168-
if (count != 2)
167+
if (*ppos != 0 || count != 2)
169168
return -EINVAL;
170169

171-
written_chars = simple_write_to_buffer(buf, sizeof(buf) - 1,
172-
ppos, user_buf, count);
170+
if (copy_from_user(buf, user_buf, count))
171+
return -EFAULT;
172+
buf[count] = '\0';
173+
173174
if (buf[0] != '1')
174175
return -EINVAL;
175176

@@ -183,7 +184,7 @@ static ssize_t adf_hb_error_inject_write(struct file *file,
183184

184185
dev_info(&GET_DEV(accel_dev), "Heartbeat error injection enabled\n");
185186

186-
return written_chars;
187+
return count;
187188
}
188189

189190
static const struct file_operations adf_hb_error_inject_fops = {

0 commit comments

Comments
 (0)