linux/drivers/staging/android
Shankar Brahadeeswaran e5834d620d staging: android: ashmem: get_name,set_name not to hold ashmem_mutex
Problem:
There exists a path in ashmem driver that could lead to acquistion
of mm->mmap_sem, ashmem_mutex in reverse order. This could lead
to deadlock in the system.
For Example, assume that mmap is called on a ashmem region
in the context of a thread say T1.
 sys_mmap_pgoff (1. acquires mm->mmap_sem)
  |
   --> mmap_region
 	|
         ----> ashmem_mmap (2. acquires asmem_mutex)
 Now if there is a context switch after 1 and before 2,
 and if another thread T2 (that shares the mm struct) invokes an
 ioctl say ASHMEM_GET_NAME, this can lead to the following path

ashmem_ioctl
  |
  -->get_name (3. acquires ashmem_mutex)
	|
	---> copy_to_user (4. acquires the mm->mmap_sem)
Note that the copy_to_user could lead to a valid fault if no
physical page is allocated yet for the user address passed.
Now T1 has mmap_sem and is waiting for ashmem_mutex.
and T2 has the ashmem_mutex and is waiting for mmap_sem
Thus leading to deadlock.

Solution:
Do not call copy_to_user or copy_from_user while holding the
ahsmem_mutex. Instead copy this to a local buffer that lives
in the stack while holding this lock. This will maintain data
integrity as well never reverse the lock order.

Testing:
Created a unit test case to reproduce the problem.
Used the same to test this fix on kernel version 3.4.0
Ported the same patch to 3.8

Signed-off-by: Shankar Brahadeeswaran <shankoo77@gmail.com>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-03-05 16:35:22 +08:00
..
trace staging: sync: Add tracepoint support 2013-03-04 17:46:55 +08:00
alarm-dev.c staging: alarm-dev: Implement compat_ioctl support 2013-01-18 12:37:11 -08:00
android_alarm.h staging: alarm-dev: Implement compat_ioctl support 2013-01-18 12:37:11 -08:00
ashmem.c staging: android: ashmem: get_name,set_name not to hold ashmem_mutex 2013-03-05 16:35:22 +08:00
ashmem.h ashmem: Anonymous shared memory subsystem 2011-12-21 13:38:28 -08:00
binder_trace.h Staging: android: binder: Add some tracepoints 2012-10-22 13:04:29 -07:00
binder.c hlist: drop the node parameter from iterators 2013-02-27 19:10:24 -08:00
binder.h Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial 2013-02-21 17:40:58 -08:00
Kconfig staging: sw_sync: Add cpu based sync driver 2013-03-04 17:40:08 +08:00
logger.c Staging: Android: logger: module_exit implementation 2012-11-26 16:01:30 -08:00
logger.h staging: android: logger.h: Complete documentation of logger_entry 2012-08-13 19:04:25 -07:00
lowmemorykiller.c mm, oom: change type of oom_score_adj to short 2012-12-11 17:22:27 -08:00
Makefile staging: sw_sync: Add cpu based sync driver 2013-03-04 17:40:08 +08:00
ram_console.h staging: android: ram_console: pass in a boot info string 2011-11-30 21:23:37 +09:00
sw_sync.c staging: sw_sync: Convert to use new value_str debug ops 2013-03-04 17:46:55 +08:00
sw_sync.h staging: sw_sync: Add cpu based sync driver 2013-03-04 17:40:08 +08:00
sync.c staging: sync: Fix timeout = 0 wait behavior 2013-03-04 17:46:55 +08:00
sync.h staging: sync: Refactor sync debug printing 2013-03-04 17:46:55 +08:00
timed_gpio.c staging/android: use module_platform_driver 2012-08-13 19:04:25 -07:00
timed_gpio.h Staging: android: timed_gpio: Removed spaces before tabs 2012-02-29 15:52:52 -08:00
timed_output.c staging: Android: Fix some checkpatch warnings 2012-06-12 11:20:17 -07:00
timed_output.h
TODO drivers:staging:android Typos: fix some comments that have typos in them. 2012-02-08 16:47:50 -08:00