All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] i2c: dev: zero out array used for i2c reads from userspace
@ 2021-07-29 14:35 Greg Kroah-Hartman
  2021-08-10 20:55 ` Wolfram Sang
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-07-29 14:35 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: linux-kernel, Greg Kroah-Hartman, Eric Dumazet, Dan Carpenter, stable

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 <edumazet@google.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
v2: Add copy_to_user() change as pointed out by Dan

 drivers/i2c/i2c-dev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index cb64fe649390..77f576e51652 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -141,7 +141,7 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
 	if (count > 8192)
 		count = 8192;
 
-	tmp = kmalloc(count, GFP_KERNEL);
+	tmp = kzalloc(count, GFP_KERNEL);
 	if (tmp == NULL)
 		return -ENOMEM;
 
@@ -150,7 +150,8 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
 
 	ret = i2c_master_recv(client, tmp, count);
 	if (ret >= 0)
-		ret = copy_to_user(buf, tmp, count) ? -EFAULT : ret;
+		if (copy_to_user(buf, tmp, ret))
+			ret = -EFAULT;
 	kfree(tmp);
 	return ret;
 }
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] i2c: dev: zero out array used for i2c reads from userspace
  2021-07-29 14:35 [PATCH v2] i2c: dev: zero out array used for i2c reads from userspace Greg Kroah-Hartman
@ 2021-08-10 20:55 ` Wolfram Sang
  2021-08-11  7:29   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfram Sang @ 2021-08-10 20:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-i2c, linux-kernel, Eric Dumazet, Dan Carpenter, stable

[-- Attachment #1: Type: text/plain, Size: 931 bytes --]

On Thu, Jul 29, 2021 at 04:35:32PM +0200, Greg Kroah-Hartman wrote:
> 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 <edumazet@google.com>
> Cc: Dan Carpenter <dan.carpenter@oracle.com>
> Cc: stable <stable@vger.kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Fixed checkpatch warning "WARNING: Invalid email format for stable:
'stable <stable@vger.kernel.org>', prefer 'stable@vger.kernel.org' " and
applied to for-current, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] i2c: dev: zero out array used for i2c reads from userspace
  2021-08-10 20:55 ` Wolfram Sang
@ 2021-08-11  7:29   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-08-11  7:29 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c, linux-kernel, Eric Dumazet,
	Dan Carpenter, stable

On Tue, Aug 10, 2021 at 10:55:11PM +0200, Wolfram Sang wrote:
> On Thu, Jul 29, 2021 at 04:35:32PM +0200, Greg Kroah-Hartman wrote:
> > 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 <edumazet@google.com>
> > Cc: Dan Carpenter <dan.carpenter@oracle.com>
> > Cc: stable <stable@vger.kernel.org>
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Fixed checkpatch warning "WARNING: Invalid email format for stable:
> 'stable <stable@vger.kernel.org>', prefer 'stable@vger.kernel.org' " and
> applied to for-current, thanks!

That is a crazy warning, never even knew it was there.  But as the
stable maintainer, it does not look correct as both are just fine...

Anyway, thanks for taking the patch!

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-11  7:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 14:35 [PATCH v2] i2c: dev: zero out array used for i2c reads from userspace Greg Kroah-Hartman
2021-08-10 20:55 ` Wolfram Sang
2021-08-11  7:29   ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.