Skip to content

Commit 86ff25e

Browse files
gregkhwsakernel
authored andcommitted
i2c: dev: zero out array used for i2c reads from userspace
If an i2c driver happens to not provide the full amount of data that a user asks for, it is possible that some uninitialized data could be sent to userspace. While all in-kernel drivers look to be safe, just be sure by initializing the buffer to zero before it is passed to the i2c driver so that any future drivers will not have this issue. Also properly copy the amount of data recvieved to the userspace buffer, as pointed out by Dan Carpenter. Reported-by: Eric Dumazet <[email protected]> Cc: [email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent bba676c commit 86ff25e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/i2c/i2c-dev.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
141141
if (count > 8192)
142142
count = 8192;
143143

144-
tmp = kmalloc(count, GFP_KERNEL);
144+
tmp = kzalloc(count, GFP_KERNEL);
145145
if (tmp == NULL)
146146
return -ENOMEM;
147147

@@ -150,7 +150,8 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
150150

151151
ret = i2c_master_recv(client, tmp, count);
152152
if (ret >= 0)
153-
ret = copy_to_user(buf, tmp, count) ? -EFAULT : ret;
153+
if (copy_to_user(buf, tmp, ret))
154+
ret = -EFAULT;
154155
kfree(tmp);
155156
return ret;
156157
}

0 commit comments

Comments
 (0)