staging: android: ashmem: Fix possible deadlock in ashmem_ioctl
authorYisheng Xie <xieyisheng1@huawei.com>
Wed, 28 Feb 2018 06:59:22 +0000 (14:59 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 6 Mar 2018 15:21:10 +0000 (07:21 -0800)
commitdda48fc2f1d6b2c27e03cbe4c7e8080efa1b9912
tree98249dca5eb2862055a4102d2ca8526bc4359c17
parent6f6b449a5fc137eab7cb6de0f5a7ee2639ee2a2e
staging: android: ashmem: Fix possible deadlock in ashmem_ioctl

ashmem_mutex may create a chain of dependencies like:

CPU0                                    CPU1
 mmap syscall                           ioctl syscall
 -> mmap_sem (acquired)                 -> ashmem_ioctl
 -> ashmem_mmap                            -> ashmem_mutex (acquired)
    -> ashmem_mutex (try to acquire)       -> copy_from_user
                                              -> mmap_sem (try to acquire)

There is a lock odering problem between mmap_sem and ashmem_mutex causing
a lockdep splat[1] during a syzcaller test. This patch fixes the problem
by move copy_from_user out of ashmem_mutex.

[1] https://www.spinics.net/lists/kernel/msg2733200.html

Fixes: 66e2e985d531 (staging: android: ashmem: Fix a race condition in pin ioctls)
Reported-by: syzbot+d7a918a7a8e1c952bc36@syzkaller.appspotmail.com
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/android/ashmem.c