Commit 1cc8a445 authored by Rob Clark's avatar Rob Clark Committed by Ben Hutchings

drm/msm: protect against faults from copy_from_user() in submit ioctl

commit d78d383a upstream.

An evil userspace could try to cause deadlock by passing an unfaulted-in
GEM bo as submit->bos (or submit->cmds) table.  Which will trigger
msm_gem_fault() while we already hold struct_mutex.  See:

https://github.com/freedreno/msmtest/blob/master/evilsubmittest.cSigned-off-by: default avatarRob Clark <robdclark@gmail.com>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent b7ba904b
...@@ -124,6 +124,12 @@ struct msm_drm_private { ...@@ -124,6 +124,12 @@ struct msm_drm_private {
*/ */
struct drm_mm mm; struct drm_mm mm;
} vram; } vram;
/* task holding struct_mutex.. currently only used in submit path
* to detect and reject faults from copy_from_user() for submit
* ioctl.
*/
struct task_struct *struct_mutex_task;
}; };
struct msm_format { struct msm_format {
......
...@@ -188,11 +188,20 @@ int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -188,11 +188,20 @@ int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
{ {
struct drm_gem_object *obj = vma->vm_private_data; struct drm_gem_object *obj = vma->vm_private_data;
struct drm_device *dev = obj->dev; struct drm_device *dev = obj->dev;
struct msm_drm_private *priv = dev->dev_private;
struct page **pages; struct page **pages;
unsigned long pfn; unsigned long pfn;
pgoff_t pgoff; pgoff_t pgoff;
int ret; int ret;
/* This should only happen if userspace tries to pass a mmap'd
* but unfaulted gem bo vaddr into submit ioctl, triggering
* a page fault while struct_mutex is already held. This is
* not a valid use-case so just bail.
*/
if (priv->struct_mutex_task == current)
return VM_FAULT_SIGBUS;
/* Make sure we don't parallel update on a fault, nor move or remove /* Make sure we don't parallel update on a fault, nor move or remove
* something from beneath our feet * something from beneath our feet
*/ */
......
...@@ -360,6 +360,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -360,6 +360,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
if (ret) if (ret)
return ret; return ret;
priv->struct_mutex_task = current;
submit = submit_create(dev, gpu, args->nr_bos); submit = submit_create(dev, gpu, args->nr_bos);
if (!submit) { if (!submit) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -442,6 +444,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, ...@@ -442,6 +444,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
if (submit) if (submit)
submit_cleanup(submit, !!ret); submit_cleanup(submit, !!ret);
out_unlock: out_unlock:
priv->struct_mutex_task = NULL;
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment