staging: android: ashmem: Fix a race condition in pin ioctls
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. Cc: stable@vger.kernel.org Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
02b7b2844c
commit
ce8a3a9e76
@ -702,30 +702,32 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
|
|||||||
size_t pgstart, pgend;
|
size_t pgstart, pgend;
|
||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
if (unlikely(!asma->file))
|
mutex_lock(&ashmem_mutex);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
if (unlikely(copy_from_user(&pin, p, sizeof(pin))))
|
if (unlikely(!asma->file))
|
||||||
return -EFAULT;
|
goto out_unlock;
|
||||||
|
|
||||||
|
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" */
|
/* per custom, you can pass zero for len to mean "everything onward" */
|
||||||
if (!pin.len)
|
if (!pin.len)
|
||||||
pin.len = PAGE_ALIGN(asma->size) - pin.offset;
|
pin.len = PAGE_ALIGN(asma->size) - pin.offset;
|
||||||
|
|
||||||
if (unlikely((pin.offset | pin.len) & ~PAGE_MASK))
|
if (unlikely((pin.offset | pin.len) & ~PAGE_MASK))
|
||||||
return -EINVAL;
|
goto out_unlock;
|
||||||
|
|
||||||
if (unlikely(((__u32)-1) - pin.offset < pin.len))
|
if (unlikely(((__u32)-1) - pin.offset < pin.len))
|
||||||
return -EINVAL;
|
goto out_unlock;
|
||||||
|
|
||||||
if (unlikely(PAGE_ALIGN(asma->size) < pin.offset + pin.len))
|
if (unlikely(PAGE_ALIGN(asma->size) < pin.offset + pin.len))
|
||||||
return -EINVAL;
|
goto out_unlock;
|
||||||
|
|
||||||
pgstart = pin.offset / PAGE_SIZE;
|
pgstart = pin.offset / PAGE_SIZE;
|
||||||
pgend = pgstart + (pin.len / PAGE_SIZE) - 1;
|
pgend = pgstart + (pin.len / PAGE_SIZE) - 1;
|
||||||
|
|
||||||
mutex_lock(&ashmem_mutex);
|
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case ASHMEM_PIN:
|
case ASHMEM_PIN:
|
||||||
ret = ashmem_pin(asma, pgstart, pgend);
|
ret = ashmem_pin(asma, pgstart, pgend);
|
||||||
@ -738,6 +740,7 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_unlock:
|
||||||
mutex_unlock(&ashmem_mutex);
|
mutex_unlock(&ashmem_mutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user