* [PATCH] staging: android: vsoc: fix copy_from_user overrun
@ 2019-04-14 15:37 Vincent Stehlé
2019-04-15 6:32 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Vincent Stehlé @ 2019-04-14 15:37 UTC (permalink / raw)
To: devel, linux-kernel; +Cc: Vincent Stehlé, Greg Kroah-Hartman
The `np->permission' structure is smaller than the `np' structure but
sizeof(*np) worth of data is copied in there. Fix the size passed to
copy_from_user() to avoid overrun.
Fixes: 3d2ec9dcd5539d42 ("staging: Android: Add 'vsoc' driver for cuttlefish.")
Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/staging/android/vsoc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/android/vsoc.c b/drivers/staging/android/vsoc.c
index 8a75bd27c4133..00a1ec7b91549 100644
--- a/drivers/staging/android/vsoc.c
+++ b/drivers/staging/android/vsoc.c
@@ -259,7 +259,8 @@ do_create_fd_scoped_permission(struct vsoc_device_region *region_p,
atomic_t *owner_ptr = NULL;
struct vsoc_device_region *managed_region_p;
- if (copy_from_user(&np->permission, &arg->perm, sizeof(*np)) ||
+ if (copy_from_user(&np->permission,
+ &arg->perm, sizeof(np->permission)) ||
copy_from_user(&managed_fd,
&arg->managed_region_fd, sizeof(managed_fd))) {
return -EFAULT;
--
2.20.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: android: vsoc: fix copy_from_user overrun
2019-04-14 15:37 [PATCH] staging: android: vsoc: fix copy_from_user overrun Vincent Stehlé
@ 2019-04-15 6:32 ` Dan Carpenter
2019-04-15 6:39 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2019-04-15 6:32 UTC (permalink / raw)
To: Vincent Stehlé; +Cc: devel, linux-kernel, Greg Kroah-Hartman
On Sun, Apr 14, 2019 at 05:37:26PM +0200, Vincent Stehlé wrote:
> The `np->permission' structure is smaller than the `np' structure but
> sizeof(*np) worth of data is copied in there. Fix the size passed to
> copy_from_user() to avoid overrun.
>
> Fixes: 3d2ec9dcd5539d42 ("staging: Android: Add 'vsoc' driver for cuttlefish.")
> Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
> drivers/staging/android/vsoc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/android/vsoc.c b/drivers/staging/android/vsoc.c
> index 8a75bd27c4133..00a1ec7b91549 100644
> --- a/drivers/staging/android/vsoc.c
> +++ b/drivers/staging/android/vsoc.c
> @@ -259,7 +259,8 @@ do_create_fd_scoped_permission(struct vsoc_device_region *region_p,
> atomic_t *owner_ptr = NULL;
> struct vsoc_device_region *managed_region_p;
>
> - if (copy_from_user(&np->permission, &arg->perm, sizeof(*np)) ||
> + if (copy_from_user(&np->permission,
> + &arg->perm, sizeof(np->permission)) ||
The original code was probably correct... This is a common thing where
people use "&p->first_struct_member" to represent the whole struct.
It seems like kind of a horrible thing to do and I can't explain why
people do it, but they do...
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: android: vsoc: fix copy_from_user overrun
2019-04-15 6:32 ` Dan Carpenter
@ 2019-04-15 6:39 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2019-04-15 6:39 UTC (permalink / raw)
To: Vincent Stehlé; +Cc: devel, linux-kernel, Greg Kroah-Hartman
On Mon, Apr 15, 2019 at 09:32:44AM +0300, Dan Carpenter wrote:
> On Sun, Apr 14, 2019 at 05:37:26PM +0200, Vincent Stehlé wrote:
> > The `np->permission' structure is smaller than the `np' structure but
> > sizeof(*np) worth of data is copied in there. Fix the size passed to
> > copy_from_user() to avoid overrun.
> >
> > Fixes: 3d2ec9dcd5539d42 ("staging: Android: Add 'vsoc' driver for cuttlefish.")
> > Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > ---
> > drivers/staging/android/vsoc.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/android/vsoc.c b/drivers/staging/android/vsoc.c
> > index 8a75bd27c4133..00a1ec7b91549 100644
> > --- a/drivers/staging/android/vsoc.c
> > +++ b/drivers/staging/android/vsoc.c
> > @@ -259,7 +259,8 @@ do_create_fd_scoped_permission(struct vsoc_device_region *region_p,
> > atomic_t *owner_ptr = NULL;
> > struct vsoc_device_region *managed_region_p;
> >
> > - if (copy_from_user(&np->permission, &arg->perm, sizeof(*np)) ||
> > + if (copy_from_user(&np->permission,
> > + &arg->perm, sizeof(np->permission)) ||
>
> The original code was probably correct... This is a common thing where
> people use "&p->first_struct_member" to represent the whole struct.
> It seems like kind of a horrible thing to do and I can't explain why
> people do it, but they do...
I have reviewed the code in a less totally lazy way and your patch is
correct.
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
The bug is harmless, though. We copy over the list pointers with user
data and then immediately write the correct data to it.
It should probably be a static checker warning when we copy to non
__user tagged pointers. I think someone was adding this to Sparse but I
should probably add it to Smatch as well.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-15 6:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-14 15:37 [PATCH] staging: android: vsoc: fix copy_from_user overrun Vincent Stehlé
2019-04-15 6:32 ` Dan Carpenter
2019-04-15 6:39 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®