]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.281/i2c-dev-zero-out-array-used-for-i2c-reads-from-userspace.patch
6.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.281 / i2c-dev-zero-out-array-used-for-i2c-reads-from-userspace.patch
1 From 86ff25ed6cd8240d18df58930bd8848b19fce308 Mon Sep 17 00:00:00 2001
2 From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
3 Date: Thu, 29 Jul 2021 16:35:32 +0200
4 Subject: i2c: dev: zero out array used for i2c reads from userspace
5
6 From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
7
8 commit 86ff25ed6cd8240d18df58930bd8848b19fce308 upstream.
9
10 If an i2c driver happens to not provide the full amount of data that a
11 user asks for, it is possible that some uninitialized data could be sent
12 to userspace. While all in-kernel drivers look to be safe, just be sure
13 by initializing the buffer to zero before it is passed to the i2c driver
14 so that any future drivers will not have this issue.
15
16 Also properly copy the amount of data recvieved to the userspace buffer,
17 as pointed out by Dan Carpenter.
18
19 Reported-by: Eric Dumazet <edumazet@google.com>
20 Cc: stable@vger.kernel.org
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 Signed-off-by: Wolfram Sang <wsa@kernel.org>
23 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 ---
25 drivers/i2c/i2c-dev.c | 5 +++--
26 1 file changed, 3 insertions(+), 2 deletions(-)
27
28 --- a/drivers/i2c/i2c-dev.c
29 +++ b/drivers/i2c/i2c-dev.c
30 @@ -148,7 +148,7 @@ static ssize_t i2cdev_read(struct file *
31 if (count > 8192)
32 count = 8192;
33
34 - tmp = kmalloc(count, GFP_KERNEL);
35 + tmp = kzalloc(count, GFP_KERNEL);
36 if (tmp == NULL)
37 return -ENOMEM;
38
39 @@ -157,7 +157,8 @@ static ssize_t i2cdev_read(struct file *
40
41 ret = i2c_master_recv(client, tmp, count);
42 if (ret >= 0)
43 - ret = copy_to_user(buf, tmp, count) ? -EFAULT : ret;
44 + if (copy_to_user(buf, tmp, ret))
45 + ret = -EFAULT;
46 kfree(tmp);
47 return ret;
48 }