Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1270820 > unrolled thread

[PATCH 18/37] mm: factor out VMA fault permission checking

Started byDave Hansen <dave@sr71.net>
First post2015-11-17 04:50 +0100
Last post2015-11-27 11:00 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 18/37] mm: factor out VMA fault permission checking Dave Hansen <dave@sr71.net> - 2015-11-17 04:50 +0100
    Re: [PATCH 18/37] mm: factor out VMA fault permission checking Thomas Gleixner <tglx@linutronix.de> - 2015-11-27 11:00 +0100

#1270820 — [PATCH 18/37] mm: factor out VMA fault permission checking

FromDave Hansen <dave@sr71.net>
Date2015-11-17 04:50 +0100
Subject[PATCH 18/37] mm: factor out VMA fault permission checking
Message-ID<qvFrj-82I-7@gated-at.bofh.it>
From: Dave Hansen <dave.hansen@linux.intel.com>

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: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/mm/gup.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff -puN mm/gup.c~pkeys-10-pte-fault mm/gup.c
--- a/mm/gup.c~pkeys-10-pte-fault	2015-11-16 12:35:43.275532100 -0800
+++ b/mm/gup.c	2015-11-16 12:35:43.279532282 -0800
@@ -557,6 +557,17 @@ next_page:
 }
 EXPORT_SYMBOL(__get_user_pages);
 
+bool vma_permits_fault(struct vm_area_struct *vma, unsigned int fault_flags)
+{
+	vm_flags_t 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
  * @tsk:	the task_struct to use for page fault accounting, or
@@ -588,15 +599,13 @@ int fixup_user_fault(struct task_struct
 		     unsigned long address, unsigned int fault_flags)
 {
 	struct vm_area_struct *vma;
-	vm_flags_t vm_flags;
 	int ret;
 
 	vma = find_extend_vma(mm, address);
 	if (!vma || address < vma->vm_start)
 		return -EFAULT;
 
-	vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
-	if (!(vm_flags & vma->vm_flags))
+	if (!vma_permits_fault(vma, fault_flags))
 		return -EFAULT;
 
 	ret = handle_mm_fault(mm, vma, address, fault_flags);
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1278686

FromThomas Gleixner <tglx@linutronix.de>
Date2015-11-27 11:00 +0100
Message-ID<qznYS-18E-9@gated-at.bofh.it>
In reply to#1270820
On Mon, 16 Nov 2015, Dave Hansen wrote:
> +bool vma_permits_fault(struct vm_area_struct *vma, unsigned int fault_flags)
> +{
> +	vm_flags_t vm_flags =
> +		(fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
> +

	vm_flags_t vm_flags;

	vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;

makes it readable w/o brain twisting.

Thanks,

	tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web