Patch "staging: android: ashmem: Fix a race condition in pin ioctls" has been added to the 4.9-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
staging: android: ashmem: Fix a race condition in pin ioctls
to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
staging-android-ashmem-fix-a-race-condition-in-pin-ioctls.patch
and it can be found in the queue-4.9 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
ce8a3a9e76d0193e2e8d74a06d275b3c324ca652Mon Sep 17 00:00:00 2001
From: Ben Hutchings <[email protected]>
Date: Sun, 4 Feb 2018 02:06:27 +0000
Subject: staging: android: ashmem: Fix a race condition in pin ioctls
From: Ben Hutchings <[email protected]>
commit ce8a3a9e76d0193e2e8d74a06d275b3c324ca652 upstream.
ashmem_pin_unpin() reads asma->file and asma->size before taking the ashmem_mutex, so it can race with other operations that modify them.
Build-tested only.
--- drivers/staging/android/ashmem.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
drivers/staging/android/ashmem.c +11 -8
@@ -719,30 +719,32 @@ static int ashmem_pin_unpin(struct ashmesize_t pgstart, pgend;int ret = -EINVAL ; +mutex_lock (&ashmem_mutex); +if (unlikely (!asma->file)) -return -EINVAL ; + goto out_unlock; -if (unlikely (copy_from_user (&pin, p,sizeof (pin)))) -return -EFAULT ; +if (unlikely (copy_from_user (&pin, p,sizeof (pin)))) { + ret = -EFAULT ; + goto out_unlock; + }/* per custom, you can pass zero for len to mean "everything onward" */ if (!pin.len) pin.len =PAGE_ALIGN (asma->size) - pin.offset;if (unlikely ((pin.offset | pin.len) & ~PAGE_MASK )) -return -EINVAL ; + goto out_unlock;if (unlikely (((__u32)-1 ) - pin.offset < pin.len)) -return -EINVAL ; + goto out_unlock;if (unlikely (PAGE_ALIGN (asma->size) < pin.offset + pin.len)) -return -EINVAL ; + goto out_unlock; pgstart = pin.offset /PAGE_SIZE ; pgend = pgstart + (pin.len /PAGE_SIZE ) -1 ; -mutex_lock (&ashmem_mutex); -switch (cmd) {case ASHMEM_PIN : ret =ashmem_pin (asma, pgstart, pgend);
@@ -755,6 +757,7 @@ static int ashmem_pin_unpin(struct ashmebreak ; } +out_unlock:mutex_unlock (&ashmem_mutex);return ret;
Patches currently in stable-queue which might be from [email protected] are
queue-4.9/staging-android-ashmem-fix-a-race-condition-in-pin-ioctls.patch