remap file pages protection support: use FAULT_SIGSEGV for protection checking
Subsystems (2)
PATCH 19/39 remap file pages protection support: use FAULT_SIGSEGV for protection checking
From: Paolo 'Blaisorblade' Giarrusso <[email protected]>
The arch handler used to check itself protection, now we must possibly move that to the generic VM if the VMA is non-uniform.
For now, do_file_page installs the PTE and doesn't check the fault type, if it was wrong, then it'll do another fault and die only then. I've left this for now to exercise more the code (and it works anyway).
I've also changed do_no_pages to fault in pages with their *exact* permissions for non-uniform VMAs.
The approach for checking is a bit clumsy because we are given a VM_{READ,WRITE,EXEC} mask so we do *strict* checking. For instance, a VM_EXEC mapping (which won't have VM_READ in vma->vm_flags) would give a fault on read.
To fix that properly, we should get a pgprot mask and test pte_read()/write/exec; for now I workaround that in the i386/UML handler, I have patches for fixing that subsequently.
Also, there is a (potential) problem: on VM_NONUNIFORM vmas, in handle_pte_fault(), if the PTE is present we return VM_FAULT_SIGSEGV. This has proven to be a bit strict, at least for UML - so this may break other arches too (only for new functionality). At least, peculiar ones - this problem was due to handle_mm_fault() called for TLB faults rather than PTE faults.
Another problem I've just discovered is that PTRACE_POKETEXT access_process_vm on VM_NONUNIFORM write-protected vma's won't work. That's not a big problem.
---
linux-2.6.git-paolo/arch/i386/mm/fault.c | 28 +++++++-- linux-2.6.git-paolo/include/linux/mm.h | 11 +++ linux-2.6.git-paolo/mm/memory.c | 96 ++++++++++++++++++++++++------- 3 files changed, 108 insertions(+), 27 deletions(-)
arch/i386/mm/fault.c renamed from arch/i386/mm/fault.c~rfp-fault-sigsegv-2 +22 -6
@@ -219,6 +219,7 @@ fastcall void do_page_fault(struct pt_reunsigned long address;unsigned long page;int write; +int access_mask =0 ;siginfo_t info;/* get the address */
@@ -324,23 +325,24 @@ good_area:/* fall through */ case 2 :/* write, not present */ if (!(vma->vm_flags &VM_WRITE )) - goto bad_area; + goto bad_area_prot; write++;break ; -case 1 :/* read, present */ +case 1 :/* read, present - when does this happen? Maybe for NX exceptions? */ goto bad_area;case 0 :/* read, not present */ if (!(vma->vm_flags & (VM_READ |VM_EXEC ))) - goto bad_area; + goto bad_area_prot; } - survive: + access_mask = write ?VM_WRITE :0 ; +handle_fault:/* * If for any reason at all we couldn't handle the fault, * make sure we exit gracefully rather than endlessly redo * the fault. */ -switch (handle_mm_fault (mm, vma, address, write)) { +switch (__handle_mm_fault (mm, vma, address, access_mask)) {case VM_FAULT_MINOR : tsk->min_flt++;break ;
@@ -368,6 +370,20 @@ good_area:up_read (&mm->mmap_sem);return ; +/* If the PTE is not present, the vma protection are not accurate if +* VM_NONUNIFORM; present PTE's are correct for VM_NONUNIFORM and were +* already handled otherwise. */ +bad_area_prot: +if (unlikely (vma->vm_flags &VM_NONUNIFORM )) { + access_mask = write ?VM_WRITE :0 ; +/* Otherwise, on a legitimate read fault on a page mapped as +* exec-only, we get problems. Probably, we should lower +* requirements... we should always test just +* pte_read/write/exec, on vma->vm_page_prot! This way is +* cumbersome. However, for now things should work for i386. */ + access_mask |= vma->vm_flags &VM_EXEC ?VM_EXEC :VM_READ ; + goto handle_fault; + }/* * Something tried to access memory that isn't in our memory map.. * Fix it, but check if it's kernel or user first..
@@ -481,7 +497,7 @@ out_of_memory:if (tsk->pid ==1 ) {yield ();down_read (&mm->mmap_sem); - goto survive; + goto handle_fault; }printk ("VM: killing process %s\n" , tsk->comm);if (error_code &4 )
mm/memory.c renamed from mm/memory.c~rfp-fault-sigsegv-2 +76 -20
183 lines not on this page · raw message
include/linux/mm.h renamed from include/linux/mm.h~rfp-fault-sigsegv-2 +10 -1
@@ -712,7 +712,16 @@ extern pte_t *FASTCALL(pte_alloc_kernel(extern pte_t *FASTCALL (pte_alloc_map (struct mm_struct *mm,pmd_t *pmd,unsigned long address));extern int install_page (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long addr,struct page *page,pgprot_t prot);extern int install_file_pte (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long addr,unsigned long pgoff,pgprot_t prot); -extern int handle_mm_fault (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long address,int write_access); + +/* We reuse VM_READ, VM_WRITE and VM_EXEC for the @access_mask. */ +extern int __handle_mm_fault (struct mm_struct *mm,struct vm_area_struct *vma,unsigned long address,int access_mask); + +static inline int handle_mm_fault (struct mm_struct *mm,struct vm_area_struct *vma, +unsigned long address,int write_access) +{ +return __handle_mm_fault (mm, vma, address, write_access ?VM_WRITE :0 ); +} +extern int make_pages_present (unsigned long addr,unsigned long end);extern int access_process_vm (struct task_struct *tsk,unsigned long addr,void *buf,int len,int write);void install_arg_page (struct vm_area_struct *,struct page *,unsigned long );
_