From: Joerg Roedel <joro@8bytes.org>
To: iommu@lists.linux-foundation.org
Cc: Oded Gabbay <oded.gabbay@gmail.com>,
David Woodhouse <dwmw2@infradead.org>,
Jesse Barnes <jbarnes@virtuousgeek.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org, Joerg Roedel <jroedel@suse.de>
Subject: [PATCH 1/4] iommu/amd: Do proper access checking before calling handle_mm_fault()
Date: Tue, 17 Nov 2015 16:11:36 +0100 [thread overview]
Message-ID: <1447773099-2444-2-git-send-email-joro@8bytes.org> (raw)
In-Reply-To: <1447773099-2444-1-git-send-email-joro@8bytes.org>
From: Joerg Roedel <jroedel@suse.de>
The handle_mm_fault function expects the caller to do the
access checks. Not doing so and calling the function with
wrong permissions is a bug (catched by a BUG_ON).
So fix this bug by adding proper access checking to the io
page-fault code in the AMD IOMMUv2 driver.
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
drivers/iommu/amd_iommu_v2.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/amd_iommu_v2.c b/drivers/iommu/amd_iommu_v2.c
index d21d4ed..7caf2fa 100644
--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -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);
@@ -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;
--
1.9.1
next prev parent reply other threads:[~2015-11-17 15:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-17 15:11 [PATCH 0/4 v2] Implement access checks in iommu page fault paths Joerg Roedel
2015-11-17 15:11 ` Joerg Roedel [this message]
2015-11-17 15:11 ` [PATCH 2/4] iommu/amd: Correctly set flags for handle_mm_fault call Joerg Roedel
2015-11-17 15:11 ` [PATCH 3/4] iommu/amd: Cleanup error handling in do_fault() Joerg Roedel
2015-11-17 15:11 ` [PATCH 4/4] iommu/vt-d: Do access checks before calling handle_mm_fault() Joerg Roedel
2015-11-20 15:35 ` David Woodhouse
2015-12-14 14:41 ` Joerg Roedel
2015-11-18 14:07 ` [PATCH 0/4 v2] Implement access checks in iommu page fault paths Oded Gabbay
2015-11-18 16:13 ` Jesse Barnes
2015-11-27 12:07 ` Joerg Roedel
-- strict thread matches above, loose matches on Subject: below --
2015-11-10 13:26 [PATCH 0/4] " Joerg Roedel
2015-11-10 13:26 ` [PATCH 1/4] iommu/amd: Do proper access checking before calling handle_mm_fault() Joerg Roedel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447773099-2444-2-git-send-email-joro@8bytes.org \
--to=joro@8bytes.org \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jbarnes@virtuousgeek.org \
--cc=jroedel@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=oded.gabbay@gmail.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).