diff options
author | Viktor Slavkovic <viktors@google.com> | 2017-10-02 10:26:45 -0700 |
---|---|---|
committer | Tao Huang <huangtao@rock-chips.com> | 2018-01-09 15:40:58 +0800 |
commit | f689b67a368756e599291660e4b13692ec0553f8 (patch) | |
tree | b5390c1eb349e03ab5426d7720a5f73132606a04 | |
parent | 0e7d55e6f07c8fe8fe4190e55cff5406f9699fc2 (diff) |
staging: android: ashmem: fix a race condition in ASHMEM_SET_SIZE ioctl
A lock-unlock is missing in ASHMEM_SET_SIZE ioctl which can result in a
race condition when mmap is called. After the !asma->file check, before
setting asma->size, asma->file can be set in mmap. That would result in
having different asma->size than the mapped memory size. Combined with
ASHMEM_UNPIN ioctl and shrinker invocation, this can result in memory
corruption.
Bug: 66954097
Signed-off-by: Viktor Slavkovic <viktors@google.com>
Change-Id: I268225133f96fde0fadd1ec621aafef27d392d65
-rw-r--r-- | drivers/staging/android/ashmem.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index e4530ac6d5d4..28c9afe538ca 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -753,10 +753,12 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg) break; case ASHMEM_SET_SIZE: ret = -EINVAL; + mutex_lock(&ashmem_mutex); if (!asma->file) { ret = 0; asma->size = (size_t)arg; } + mutex_unlock(&ashmem_mutex); break; case ASHMEM_GET_SIZE: ret = asma->size; |