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.

Signed-off-by: Viktor Slavkovic <viktors@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Viktor Slavkovic and committed by Greg Kroah-Hartman 443064cb 30a7acd5

+2
+2
drivers/staging/android/ashmem.c
··· 765 765 break; 766 766 case ASHMEM_SET_SIZE: 767 767 ret = -EINVAL; 768 + mutex_lock(&ashmem_mutex); 768 769 if (!asma->file) { 769 770 ret = 0; 770 771 asma->size = (size_t)arg; 771 772 } 773 + mutex_unlock(&ashmem_mutex); 772 774 break; 773 775 case ASHMEM_GET_SIZE: 774 776 ret = asma->size;