Skip to content

Commit

Permalink
Merge tag 'iommu-fixes-v4.4-rc5' of git://git.kernel.org/pub/scm/linu…
Browse files Browse the repository at this point in the history
…x/kernel/git/joro/iommu

Pull IOMMU fixes from Joerg Roedel:
 "Two similar fixes for the Intel and AMD IOMMU drivers to add proper
  access checks before calling handle_mm_fault"

* tag 'iommu-fixes-v4.4-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu:
  iommu/vt-d: Do access checks before calling handle_mm_fault()
  iommu/amd: Do proper access checking before calling handle_mm_fault()
  • Loading branch information
Linus Torvalds committed Dec 18, 2015
2 parents 3273cba + 7f8312a commit ccdd96b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 18 additions & 2 deletions drivers/iommu/amd_iommu_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,22 @@ static void handle_fault_error(struct fault *fault)
}
}

static bool access_error(struct vm_area_struct *vma, struct fault *fault)
{
unsigned long requested = 0;

if (fault->flags & PPR_FAULT_EXEC)
requested |= VM_EXEC;

if (fault->flags & PPR_FAULT_READ)
requested |= VM_READ;

if (fault->flags & PPR_FAULT_WRITE)
requested |= VM_WRITE;

return (requested & ~vma->vm_flags) != 0;
}

static void do_fault(struct work_struct *work)
{
struct fault *fault = container_of(work, struct fault, work);
Expand All @@ -516,8 +532,8 @@ static void do_fault(struct work_struct *work)
goto out;
}

if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) {
/* handle_mm_fault would BUG_ON() */
/* Check if we have the right permissions on the vma */
if (access_error(vma, fault)) {
up_read(&mm->mmap_sem);
handle_fault_error(fault);
goto out;
Expand Down
20 changes: 20 additions & 0 deletions drivers/iommu/intel-svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,23 @@ struct page_req_dsc {
};

#define PRQ_RING_MASK ((0x1000 << PRQ_ORDER) - 0x10)

static bool access_error(struct vm_area_struct *vma, struct page_req_dsc *req)
{
unsigned long requested = 0;

if (req->exe_req)
requested |= VM_EXEC;

if (req->rd_req)
requested |= VM_READ;

if (req->wr_req)
requested |= VM_WRITE;

return (requested & ~vma->vm_flags) != 0;
}

static irqreturn_t prq_event_thread(int irq, void *d)
{
struct intel_iommu *iommu = d;
Expand Down Expand Up @@ -539,6 +556,9 @@ static irqreturn_t prq_event_thread(int irq, void *d)
if (!vma || address < vma->vm_start)
goto invalid;

if (access_error(vma, req))
goto invalid;

ret = handle_mm_fault(svm->mm, vma, address,
req->wr_req ? FAULT_FLAG_WRITE : 0);
if (ret & VM_FAULT_ERROR)
Expand Down

0 comments on commit ccdd96b

Please sign in to comment.