staging: android: vsoc: fix copy_from_user overrun
PATCH 1/1 staging: android: vsoc: fix copy_from_user overrun
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.
--- drivers/staging/android/vsoc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/android/vsoc.c +2 -1
@@ -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 ;
Signature · 1 line
2.20.1
Quoted 16 lines · Vincent Stehlé
The
np->permission' structure is smaller than thenp' structure butsizeof(*np)worth of data is copied in there. Fix the size passed tocopy_from_user()to avoid overrun.Fixes 3d2ec9dcd5539d42 ("staging: Android: Add 'vsoc' driver for cuttlefish.")Signed-off-by Vincent Stehlé <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/staging/android/vsoc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/staging/android/vsoc.c +0
-0
drivers/staging/android/vsoc.c do_create_fd_scoped_permission(struct vsoc_device_region *region_p, · line 263
Quoted 6 lines
drivers/staging/android/vsoc.c +2
-1@@ -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
Dan Carpenter
Reviewed-byQuoted 20 lines · Dan Carpenter
Quoted 19 lines · Vincent Stehlé
The
np->permission' structure is smaller than thenp' structure butsizeof(*np)worth of data is copied in there. Fix the size passed tocopy_from_user()to avoid overrun.Fixes 3d2ec9dcd5539d42 ("staging: Android: Add 'vsoc' driver for cuttlefish.")Signed-off-by Vincent Stehlé <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/staging/android/vsoc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/staging/android/vsoc.c +0
-0@@ -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;
Quoted 8 lines
drivers/staging/android/vsoc.c do_create_fd_scoped_permission(struct vsoc_device_region *region_p, · line 263
Quoted 3 lines
drivers/staging/android/vsoc.c +2
-1- 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.
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