提交 d4925e00 编写于 作者: D Dave Hansen 提交者: Ingo Molnar

mm/gup: Factor out VMA fault permission checking

This code matches a fault condition up with the VMA and ensures
that the VMA allows the fault to be handled instead of just
erroring out.

We will be extending this in a moment to comprehend protection
keys.
Signed-off-by: NDave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dominik Dingel <dingel@linux.vnet.ibm.com>
Cc: Eric B Munson <emunson@akamai.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jason Low <jason.low2@hp.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/20160212210216.C3824032@viggo.jf.intel.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
上级 a927cb83
...@@ -610,6 +610,18 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, ...@@ -610,6 +610,18 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
} }
EXPORT_SYMBOL(__get_user_pages); EXPORT_SYMBOL(__get_user_pages);
bool vma_permits_fault(struct vm_area_struct *vma, unsigned int fault_flags)
{
vm_flags_t vm_flags;
vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
if (!(vm_flags & vma->vm_flags))
return false;
return true;
}
/* /*
* fixup_user_fault() - manually resolve a user page fault * fixup_user_fault() - manually resolve a user page fault
* @tsk: the task_struct to use for page fault accounting, or * @tsk: the task_struct to use for page fault accounting, or
...@@ -645,7 +657,6 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm, ...@@ -645,7 +657,6 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
bool *unlocked) bool *unlocked)
{ {
struct vm_area_struct *vma; struct vm_area_struct *vma;
vm_flags_t vm_flags;
int ret, major = 0; int ret, major = 0;
if (unlocked) if (unlocked)
...@@ -656,8 +667,7 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm, ...@@ -656,8 +667,7 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
if (!vma || address < vma->vm_start) if (!vma || address < vma->vm_start)
return -EFAULT; return -EFAULT;
vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ; if (!vma_permits_fault(vma, fault_flags))
if (!(vm_flags & vma->vm_flags))
return -EFAULT; return -EFAULT;
ret = handle_mm_fault(mm, vma, address, fault_flags); ret = handle_mm_fault(mm, vma, address, fault_flags);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册