SKAS3 for 2.6.24-rc7
Subsystems (7)
RFC PATCH 1/1 SKAS3 for 2.6.24-rc7
Please find attached a SKAS3 patch against Linux 2.6.24-rc7, based on Jeff Dike's 2007-12-08 patch for 2.6.23.
Quoteth Jeff:
Quoted 1 line
2.6.24 is going to be even more interesting, given the x86 merge.
Indeed it is. This patch is not perfect and I need some help. Host i386 and x86_64 build with CONFIG_PROC_MM (I tested i386 and it works, but for x86_64 I just made sure it compiles defconfig). Guest i386 builds correctly and runs fine, but I cannot figure this out when building guest x86_64:
CC arch/um/kernel/ptrace.o
In file included from arch/um/include/skas_ptrace.h:12,
from arch/um/kernel/ptrace.c:13:arch/um/include/sysdep/skas_ptrace.h:9: error: redefinition of ‘struct ptrace_faultinfo’arch/um/include/sysdep/skas_ptrace.h:14: error: redefinition of ‘struct ptrace_ldt’
make[1]: *** [arch/um/kernel/ptrace.o] Error 1
make: *** [arch/um/kernel] Error 2
sysdep-i386/skas_ptrace.h and sysdep-x86_64/skas_ptrace.h are nearly identical, so I can't figure out why ptrace_faultinfo and ptrace_ldt are being defined in the first place.
RF
arch/um/sys-i386/ldt.c | 2 arch/x86/Kconfig | 20 ++ arch/x86/ia32/ptrace32.c | 68 +++++++ arch/x86/ia32/sys_ia32.c | 16 + arch/x86/kernel/ldt_32.c | 58 +++--- arch/x86/kernel/ldt_64.c | 55 +++-- arch/x86/kernel/ptrace_32.c | 61 ++++++ arch/x86/kernel/ptrace_64.c | 70 +++++++ arch/x86/kernel/sys_i386_32.c | 27 ++ arch/x86/kernel/sys_x86_64.c | 15 + arch/x86/mm/Makefile_64 | 1 arch/x86/mm/proc_mm_64.c | 85 ++++++++ include/asm-um/compat.h | 9 include/asm-um/proc_mm_32.h | 1 include/asm-um/proc_mm_64.h | 1 include/asm-um/ptrace-x86_64.h | 11 + include/asm-x86/desc_32.h | 3 include/asm-x86/desc_64.h | 3 include/asm-x86/mmu_context_32.h | 19 + include/asm-x86/mmu_context_64.h | 20 +- include/asm-x86/proc_mm_32.h | 18 + include/asm-x86/proc_mm_64.h | 58 ++++++ include/asm-x86/ptrace-abi.h | 6 include/asm-x86/ptrace.h | 65 ++++++ include/linux/mm.h | 19 + include/linux/proc_mm.h | 110 +++++++++++ mm/Makefile | 5 mm/fremap.c | 5 mm/mmap.c | 17 - mm/mprotect.c | 20 +- mm/proc_mm-mod.c | 50 +++++ mm/proc_mm.c | 299 +++++++++++++++++++++++++++++++ 32 files changed, 1133 insertions(+), 84 deletions(-)
arch/um/sys-i386/ldt.c +1 -1
@@ -6,7 +6,7 @@#include "linux/mm.h" #include "asm/unistd.h" #include "os.h" -#include "proc_mm.h" +#include "linux/proc_mm.h" #include "skas.h" #include "skas_ptrace.h" #include "sysdep/tls.h"
arch/x86/ia32/ptrace32.c +68 -0
92 lines not on this page · raw message
arch/x86/ia32/sys_ia32.c +12 -4
@@ -693,11 +693,10 @@return ret; } -asmlinkage long sys32_mmap2 (unsigned long addr,unsigned long len, -unsigned long prot,unsigned long flags, +long do32_mmap2 (struct mm_struct *mm,unsigned long addr, +unsigned long len,unsigned long prot,unsigned long flags,unsigned long fd,unsigned long pgoff) { -struct mm_struct *mm = current->mm;unsigned long error;struct file * file =NULL ;
@@ -709,7 +708,7 @@ }down_write (&mm->mmap_sem); - error =do_mmap_pgoff (file, addr, len, prot, flags, pgoff); + error =__do_mmap_pgoff (mm, file, addr, len, prot, flags, pgoff);up_write (&mm->mmap_sem);if (file)
@@ -717,6 +716,15 @@return error; } +/* XXX: this wrapper can be probably removed, we can simply use the 64-bit +* version.*/ +asmlinkage long sys32_mmap2 (unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long pgoff) +{ +return do32_mmap2 (current->mm, addr, len, prot, flags, fd, pgoff); +} +asmlinkage long sys32_olduname (struct oldold_utsname __user * name) {int err;
arch/x86/Kconfig +20 -0
@@ -813,6 +813,26 @@ has the cost of more pagetable lookup overhead, and also consumes more pagetable space per process. +config PROC_MM + bool "/proc/mm support" + default y + +config PROC_MM_DUMPABLE + bool "Make UML childs /proc/<pid> completely browsable" + default n + help + If in doubt, say N. + + This fiddles with some settings to make sure /proc/<pid> is completely + browsable by who started UML, at the expense of some additional + locking (maybe this could slow down the runned UMLs of a few percents, + I've not tested this). + + Also, if there is a bug in this feature, there is some little + possibility to do privilege escalation if you have UML installed + setuid (which you shouldn't have done) or if UML changes uid on + startup (which will be a good thing, when enabled) ... + # Common NUMA Features config NUMA bool "Numa Memory Allocation and Scheduler Support (EXPERIMENTAL)"
arch/x86/kernel/ldt_32.c +36 -22
144 lines not on this page · raw message
arch/x86/kernel/ldt_64.c +32 -23
146 lines not on this page · raw message
arch/x86/kernel/ptrace_32.c +61 -0
73 lines not on this page · raw message
arch/x86/kernel/ptrace_64.c +70 -0
82 lines not on this page · raw message
arch/x86/kernel/sys_i386_32.c +21 -6
@@ -18,6 +18,7 @@#include <linux/file.h> #include <linux/utsname.h> #include <linux/ipc.h> +#include <asm/proc_mm_32.h> #include <asm/uaccess.h> #include <asm/unistd.h>
@@ -39,13 +40,12 @@return error; } -asmlinkage long sys_mmap2 (unsigned long addr,unsigned long len, -unsigned long prot,unsigned long flags, -unsigned long fd,unsigned long pgoff) +long do_mmap2 (struct mm_struct *mm,unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags,unsigned long fd, +unsigned long pgoff) {int error = -EBADF ;struct file *file =NULL ; -struct mm_struct *mm = current->mm; flags &= ~(MAP_EXECUTABLE |MAP_DENYWRITE );if (!(flags &MAP_ANONYMOUS )) {
@@ -55,7 +55,7 @@ }down_write (&mm->mmap_sem); - error =do_mmap_pgoff (file, addr, len, prot, flags, pgoff); + error =__do_mmap_pgoff (mm, file, addr, len, prot, flags, pgoff);up_write (&mm->mmap_sem);if (file)
@@ -64,6 +64,18 @@return error; } +asmlinkage long sys_mmap2 (unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long pgoff) +{ +long ret =do_mmap2 (current->mm, addr, len, prot, flags, fd, pgoff); + +/* A tail call would reorder parameters on the stack and they would then +* be restored at the wrong places. */ +prevent_tail_call (ret); +return ret; +} +/* * Perform the select(nd, in, out, ex, tv) and mmap() system * calls. Linux/i386 didn't use to be able to handle more than
@@ -92,8 +104,11 @@if (a.offset & ~PAGE_MASK ) goto out; - err =sys_mmap2 (a.addr, a.len, a.prot, a.flags, + err =do_mmap2 (current->mm, a.addr, a.len, a.prot, a.flags, a.fd, a.offset >>PAGE_SHIFT ); +/* A tail call would reorder parameters on the stack and they would then +* be restored at the wrong places. */ +prevent_tail_call (err); out:return err; }
arch/x86/kernel/sys_x86_64.c +11 -4
@@ -15,6 +15,7 @@#include <asm/uaccess.h> #include <asm/ia32.h> +#include <asm/proc_mm_64.h> /* * sys_pipe() is the normal C calling standard for creating
@@ -33,7 +34,7 @@return error; } -asmlinkage long sys_mmap (unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags, +long do64_mmap (struct mm_struct *mm,unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags,unsigned long fd,unsigned long off) {long error;
@@ -51,9 +52,9 @@if (!file) goto out; } -down_write (¤t->mm->mmap_sem); - error =do_mmap_pgoff (file, addr, len, prot, flags, off >>PAGE_SHIFT ); -up_write (¤t->mm->mmap_sem); +down_write (&mm->mmap_sem); + error =__do_mmap_pgoff (mm, file, addr, len, prot, flags, off >>PAGE_SHIFT ); +up_write (&mm->mmap_sem);if (file)fput (file);
@@ -61,6 +62,12 @@return error; } +asmlinkage long sys_mmap (unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long off) +{ +return do64_mmap (current->mm, addr, len, prot, flags, fd, off); +} +static void find_start_end (unsigned long flags,unsigned long *begin,unsigned long *end) {
arch/x86/mm/Makefile_64 +1 -0
@@ -7,4 +7,5 @@ obj-$(CONFIG_NUMA) += numa_64.o obj-$(CONFIG_K8_NUMA) += k8topology_64.o obj-$(CONFIG_ACPI_NUMA) += srat_64.o +obj-$(CONFIG_PROC_MM) += proc_mm_64.o
arch/x86/mm/proc_mm_64.c +85 -0
85 lines not on this page · raw message
include/asm-um/compat.h +9 -0
@@ -0,0 +1,9 @@ +#ifndef _ASM_X86_64_COMPAT_H +#define _ASM_X86_64_COMPAT_H + +typedef s32 compat_int_t ; +typedef s32 compat_long_t ; +typedef u32 compat_uint_t ; +typedef u32 compat_ulong_t ; + +#endif /* _ASM_X86_64_COMPAT_H */
include/asm-um/proc_mm_32.h +1 -0
@@ -0,0 +1 @@ +#include <asm/arch/proc_mm_32.h>
include/asm-um/proc_mm_64.h +1 -0
@@ -0,0 +1 @@ +#include <asm/arch/proc_mm_64.h>
include/asm-um/ptrace-x86_64.h +11 -0
@@ -78,4 +78,15 @@extern long arch_prctl (struct task_struct *task,int code,unsigned long __user *addr); + +struct ptrace_faultinfo { +int is_write; +unsigned long addr; +}; + +struct ptrace_ldt { +int func; +void *ptr; +unsigned long bytecount; +};#endif
include/asm-x86/desc_32.h +3 -0
@@ -216,6 +216,9 @@ return base; } +extern int __modify_ldt (struct mm_struct * mm,int func,void __user *ptr, +unsigned long bytecount); +#else /* __ASSEMBLY__ */ /*
include/asm-x86/desc_64.h +3 -0
@@ -199,6 +199,9 @@extern struct desc_ptr idt_descr; +extern int __modify_ldt (struct mm_struct * mm,int func,void __user *ptr, +unsigned long bytecount); +#endif /* !__ASSEMBLY__ */ #endif
include/asm-x86/mmu_context_32.h +17 -2
@@ -5,6 +5,7 @@#include <asm/atomic.h> #include <asm/pgalloc.h> #include <asm/tlbflush.h> +#include <asm/semaphore.h> #include <asm/paravirt.h> #ifndef CONFIG_PARAVIRT #include <asm-generic/mm_hooks.h>
@@ -17,11 +18,22 @@/* -* Used for LDT copy/destruction. +* Used for LDT initialization/destruction. You cannot copy an LDT with +* init_new_context, since it thinks you are passing it a new LDT and won't +* deallocate its old content. */ int init_new_context (struct task_struct *tsk,struct mm_struct *mm);void destroy_context (struct mm_struct *mm); +/* LDT initialization for a clean environment - needed for SKAS.*/ +static inline void init_new_empty_context (struct mm_struct *mm) +{ +mutex_init (&mm->context.lock); + mm->context.size =0 ; +} + +/* LDT copy for SKAS - for the above problem.*/ +int copy_context (struct mm_struct *mm,struct mm_struct *old_mm);static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) {
@@ -40,6 +52,10 @@ {int cpu =smp_processor_id (); +#ifdef CONFIG_SMP + prev =per_cpu (cpu_tlbstate, cpu).active_mm; +#endif +if (likely (prev != next)) {/* stop flush ipis for the previous mm */ cpu_clear (cpu, prev->cpu_vm_mask);
@@ -61,7 +77,6 @@#ifdef CONFIG_SMP else {per_cpu (cpu_tlbstate, cpu).state =TLBSTATE_OK ; -BUG_ON (per_cpu (cpu_tlbstate, cpu).active_mm != next);if (!cpu_test_and_set (cpu, next->cpu_vm_mask)) {/* We were in lazy tlb mode and leave_mm disabled
include/asm-x86/mmu_context_64.h +18 -2
@@ -7,14 +7,29 @@#include <asm/pda.h> #include <asm/pgtable.h> #include <asm/tlbflush.h> +#include <asm/semaphore.h> #include <asm-generic/mm_hooks.h> /* * possibly do the LDT unload here? +* Used for LDT initialization/destruction. You cannot copy an LDT with +* init_new_context, since it thinks you are passing it a new LDT and won't +* deallocate its old content. */ +int init_new_context (struct task_struct *tsk,struct mm_struct *mm);void destroy_context (struct mm_struct *mm); +/* LDT initialization for a clean environment - needed for SKAS.*/ +static inline void init_new_empty_context (struct mm_struct *mm) +{ +mutex_init (&mm->context.lock); + mm->context.size =0 ; +} + +/* LDT copy for SKAS - for the above problem.*/ +int copy_context (struct mm_struct *mm,struct mm_struct *old_mm); +static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) {#ifdef CONFIG_SMP
@@ -32,6 +47,9 @@ struct task_struct *tsk) {unsigned cpu =smp_processor_id (); +#ifdef CONFIG_SMP + prev =read_pda (active_mm); +#endif if (likely (prev != next)) {/* stop flush ipis for the previous mm */ cpu_clear (cpu, prev->cpu_vm_mask);
@@ -48,8 +66,6 @@#ifdef CONFIG_SMP else {write_pda (mmu_state,TLBSTATE_OK ); -if (read_pda (active_mm) != next) -out_of_line_bug ();if (!cpu_test_and_set (cpu, next->cpu_vm_mask)) {/* We were in lazy tlb mode and leave_mm disabled * tlb flush IPI delivery. We must reload CR3
include/asm-x86/proc_mm_32.h +18 -0
@@ -0,0 +1,18 @@ +#ifndef __ASM_PROC_MM +#define __ASM_PROC_MM + +#include <asm/page.h> + +extern long do_mmap2 (struct mm_struct *mm,unsigned long addr, +unsigned long len,unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long pgoff); + +static inline long __do_mmap (struct mm_struct *mm,unsigned long addr, +unsigned long len,unsigned long prot, +unsigned long flags,unsigned long fd, +unsigned long off) +{ +return do_mmap2 (mm, addr, len, prot, flags, fd, off >>PAGE_SHIFT ); +} + +#endif /* __ASM_PROC_MM */
include/asm-x86/proc_mm_64.h +58 -0
58 lines not on this page · raw message
include/asm-x86/ptrace-abi.h +6 -0
@@ -65,6 +65,12 @@#define PTRACE_GETFPXREGS 18#define PTRACE_SETFPXREGS 19 +#define PTRACE_FAULTINFO 52 +/* 53 was used for PTRACE_SIGPENDING, don't reuse it. */ +#define PTRACE_LDT 54 +#define PTRACE_SWITCH_MM 55 +#define PTRACE_EX_FAULTINFO 56 +#define PTRACE_OLDSETOPTIONS 21/* only useful for access 32bit programs / kernels */
include/asm-x86/ptrace.h +65 -0
69 lines not on this page · raw message
include/linux/mm.h +15 -4
@@ -5,6 +5,7 @@#ifdef __KERNEL__ +#include <linux/proc_mm.h> #include <linux/gfp.h> #include <linux/list.h> #include <linux/mmzone.h>
@@ -996,11 +997,18 @@extern unsigned long get_unmapped_area (struct file *,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -extern unsigned long do_mmap_pgoff (struct file *file,unsigned long addr, +extern unsigned long __do_mmap_pgoff (struct mm_struct *mm,struct file *file, +unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flag, +unsigned long pgoff); +static inline unsigned long do_mmap_pgoff (struct file *file,unsigned long addr,unsigned long len,unsigned long prot, -unsigned long flag,unsigned long pgoff); -extern unsigned long mmap_region (struct file *file,unsigned long addr, -unsigned long len,unsigned long flags, +unsigned long flag,unsigned long pgoff) { +return __do_mmap_pgoff (current->mm, file, addr, len, prot, flag, pgoff); +} + +extern unsigned long mmap_region (struct mm_struct *mm,struct file *file, +unsigned long addr,unsigned long len,unsigned long flags,unsigned int vm_flags,unsigned long pgoff,int accountable);
@@ -1019,6 +1027,9 @@extern int do_munmap (struct mm_struct *,unsigned long ,size_t ); +extern long do_mprotect (struct mm_struct *mm,unsigned long start, +size_t len,unsigned long prot); +extern unsigned long do_brk (unsigned long ,unsigned long );/* filemap.c */
include/linux/proc_mm.h +110 -0
110 lines not on this page · raw message
mm/fremap.c +3 -2
@@ -192,8 +192,9 @@unsigned long addr; flags &=MAP_NONBLOCK ; - addr =mmap_region (vma->vm_file, start, size, - flags, vma->vm_flags, pgoff,1 ); + addr =mmap_region (current->mm, vma->vm_file, start, + size, flags, vma->vm_flags, pgoff, +1 );if (IS_ERR_VALUE (addr)) { err = addr; }else {
mm/Makefile +5 -0
@@ -29,5 +29,10 @@ obj-$(CONFIG_FS_XIP) += filemap_xip.o obj-$(CONFIG_MIGRATION) += migrate.o obj-$(CONFIG_SMP) += allocpercpu.o +obj-$(CONFIG_PROC_MM) += proc_mm.o + +ifeq ($(CONFIG_PROC_MM),y) +obj-m += proc_mm-mod.o +endif obj-$(CONFIG_QUICKLIST) += quicklist.o
mm/mmap.c +8 -9
@@ -887,12 +887,11 @@/* * The caller must hold down_write(current->mm->mmap_sem). */ - -unsigned long do_mmap_pgoff (struct file * file,unsigned long addr, -unsigned long len,unsigned long prot, -unsigned long flags,unsigned long pgoff) +unsigned long __do_mmap_pgoff (struct mm_struct *mm,struct file * file, +unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags, +unsigned long pgoff) { -struct mm_struct * mm = current->mm;struct inode *inode;unsigned int vm_flags;int error;
@@ -1026,10 +1025,10 @@if (error)return error; -return mmap_region (file, addr, len, flags, vm_flags, pgoff, +return mmap_region (mm, file, addr, len, flags, vm_flags, pgoff, accountable); } -EXPORT_SYMBOL (do_mmap_pgoff); +EXPORT_SYMBOL (__do_mmap_pgoff);/* * Some shared mappigns will want the pages marked read-only
@@ -1064,12 +1063,12 @@ } -unsigned long mmap_region (struct file *file,unsigned long addr, +unsigned long mmap_region (struct mm_struct *mm, +struct file *file,unsigned long addr,unsigned long len,unsigned long flags,unsigned int vm_flags,unsigned long pgoff,int accountable) { -struct mm_struct *mm = current->mm;struct vm_area_struct *vma, *prev;int correct_wcount =0 ;int error;
mm/mprotect.c +15 -5
@@ -211,8 +211,9 @@return error; } -asmlinkage long -sys_mprotect (unsigned long start,size_t len,unsigned long prot) +long +do_mprotect (struct mm_struct *mm,unsigned long start,size_t len, +unsigned long prot) {unsigned long vm_flags, nstart, end, tmp, reqprot;struct vm_area_struct *vma, *prev;
@@ -242,9 +243,9 @@ vm_flags =calc_vm_prot_bits (prot); -down_write (¤t->mm->mmap_sem); +down_write (&mm->mmap_sem); - vma =find_vma_prev (current->mm, start, &prev); + vma =find_vma_prev (mm, start, &prev); error = -ENOMEM ;if (!vma) goto out;
@@ -306,6 +307,15 @@ } } out: -up_write (¤t->mm->mmap_sem); +up_write (&mm->mmap_sem);return error; } + +asmlinkage long sys_mprotect (unsigned long start,size_t len,unsigned long prot) +{ +long ret =do_mprotect (current->mm, start, len, prot); +/* A tail call would reorder parameters on the stack and they would then +* be restored at the wrong places. */ +prevent_tail_call (ret); +return ret; +}
mm/proc_mm.c +299 -0
299 lines not on this page · raw message
mm/proc_mm-mod.c +50 -0
50 lines not on this page · raw message
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
RFC PATCH 1/1 SKAS3 for 2.6.24-rc7 (2nd try)
Quoted 3 lines · Ryan Finnie
sysdep-i386/skas_ptrace.handsysdep-x86_64/skas_ptrace.hare nearly identical, so I can't figure out whyptrace_faultinfoandptrace_ldtare being defined in the first place.
Looks like they were added to include/asm-um/ptrace-x86_64.h to solve a disparity in x86_64 that the x86 merge fixed. Removing them let skas_ptrace.h define them, as in i386.
So here we go, attached is an updated version. I also changed CONFIG_PROC_MM_BROWSABLE to depend on CONFIG_PROC_MM. Again, the i386 host and guest build and test properly, but I have only tested building x86_64 host and guest using defconfig. They build correctly, but I haven't test booted them. (I have x86_64 hardware, but don't have a guest userland handy to test with.) Please give it a spin and let me know how it works.
Oh, and let me remind the world: I am not really a C programmer, let alone a kernel programmer. It's quite possible this patch will eat your dog. Hopefully someone like Jeff can chime in Monday and let me know that I did a horrible job porting the patch.
RF
arch/um/sys-i386/ldt.c | 2 arch/x86/Kconfig | 21 ++ arch/x86/ia32/ptrace32.c | 68 +++++++ arch/x86/ia32/sys_ia32.c | 16 + arch/x86/kernel/ldt_32.c | 58 +++--- arch/x86/kernel/ldt_64.c | 55 +++-- arch/x86/kernel/ptrace_32.c | 61 ++++++ arch/x86/kernel/ptrace_64.c | 70 +++++++ arch/x86/kernel/sys_i386_32.c | 27 ++ arch/x86/kernel/sys_x86_64.c | 15 + arch/x86/mm/Makefile_64 | 1 arch/x86/mm/proc_mm_64.c | 85 ++++++++ include/asm-um/compat.h | 9 include/asm-um/proc_mm_32.h | 1 include/asm-um/proc_mm_64.h | 1 include/asm-um/ptrace-x86_64.h | 1 include/asm-x86/desc_32.h | 3 include/asm-x86/desc_64.h | 3 include/asm-x86/mmu_context_32.h | 19 + include/asm-x86/mmu_context_64.h | 20 +- include/asm-x86/proc_mm_32.h | 18 + include/asm-x86/proc_mm_64.h | 58 ++++++ include/asm-x86/ptrace-abi.h | 6 include/asm-x86/ptrace.h | 65 ++++++ include/linux/mm.h | 19 + include/linux/proc_mm.h | 110 +++++++++++ mm/Makefile | 5 mm/fremap.c | 5 mm/mmap.c | 17 - mm/mprotect.c | 20 +- mm/proc_mm-mod.c | 50 +++++ mm/proc_mm.c | 299 +++++++++++++++++++++++++++++++ 32 files changed, 1124 insertions(+), 84 deletions(-)
arch/um/sys-i386/ldt.c +1 -1
@@ -6,7 +6,7 @@#include "linux/mm.h" #include "asm/unistd.h" #include "os.h" -#include "proc_mm.h" +#include "linux/proc_mm.h" #include "skas.h" #include "skas_ptrace.h" #include "sysdep/tls.h"
arch/x86/ia32/ptrace32.c +68 -0
92 lines not on this page · raw message
arch/x86/ia32/sys_ia32.c +12 -4
@@ -693,11 +693,10 @@return ret; } -asmlinkage long sys32_mmap2 (unsigned long addr,unsigned long len, -unsigned long prot,unsigned long flags, +long do32_mmap2 (struct mm_struct *mm,unsigned long addr, +unsigned long len,unsigned long prot,unsigned long flags,unsigned long fd,unsigned long pgoff) { -struct mm_struct *mm = current->mm;unsigned long error;struct file * file =NULL ;
@@ -709,7 +708,7 @@ }down_write (&mm->mmap_sem); - error =do_mmap_pgoff (file, addr, len, prot, flags, pgoff); + error =__do_mmap_pgoff (mm, file, addr, len, prot, flags, pgoff);up_write (&mm->mmap_sem);if (file)
@@ -717,6 +716,15 @@return error; } +/* XXX: this wrapper can be probably removed, we can simply use the 64-bit +* version.*/ +asmlinkage long sys32_mmap2 (unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long pgoff) +{ +return do32_mmap2 (current->mm, addr, len, prot, flags, fd, pgoff); +} +asmlinkage long sys32_olduname (struct oldold_utsname __user * name) {int err;
arch/x86/Kconfig +21 -0
@@ -813,6 +813,27 @@ has the cost of more pagetable lookup overhead, and also consumes more pagetable space per process. +config PROC_MM + bool "/proc/mm support" + default y + +config PROC_MM_DUMPABLE + bool "Make UML childs /proc/<pid> completely browsable" + default n + depends on PROC_MM + help + If in doubt, say N. + + This fiddles with some settings to make sure /proc/<pid> is completely + browsable by who started UML, at the expense of some additional + locking (maybe this could slow down the runned UMLs of a few percents, + I've not tested this). + + Also, if there is a bug in this feature, there is some little + possibility to do privilege escalation if you have UML installed + setuid (which you shouldn't have done) or if UML changes uid on + startup (which will be a good thing, when enabled) ... + # Common NUMA Features config NUMA bool "Numa Memory Allocation and Scheduler Support (EXPERIMENTAL)"
arch/x86/kernel/ldt_32.c +36 -22
144 lines not on this page · raw message
arch/x86/kernel/ldt_64.c +32 -23
146 lines not on this page · raw message
arch/x86/kernel/ptrace_32.c +61 -0
73 lines not on this page · raw message
arch/x86/kernel/ptrace_64.c +70 -0
82 lines not on this page · raw message
arch/x86/kernel/sys_i386_32.c +21 -6
@@ -18,6 +18,7 @@#include <linux/file.h> #include <linux/utsname.h> #include <linux/ipc.h> +#include <asm/proc_mm_32.h> #include <asm/uaccess.h> #include <asm/unistd.h>
@@ -39,13 +40,12 @@return error; } -asmlinkage long sys_mmap2 (unsigned long addr,unsigned long len, -unsigned long prot,unsigned long flags, -unsigned long fd,unsigned long pgoff) +long do_mmap2 (struct mm_struct *mm,unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags,unsigned long fd, +unsigned long pgoff) {int error = -EBADF ;struct file *file =NULL ; -struct mm_struct *mm = current->mm; flags &= ~(MAP_EXECUTABLE |MAP_DENYWRITE );if (!(flags &MAP_ANONYMOUS )) {
@@ -55,7 +55,7 @@ }down_write (&mm->mmap_sem); - error =do_mmap_pgoff (file, addr, len, prot, flags, pgoff); + error =__do_mmap_pgoff (mm, file, addr, len, prot, flags, pgoff);up_write (&mm->mmap_sem);if (file)
@@ -64,6 +64,18 @@return error; } +asmlinkage long sys_mmap2 (unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long pgoff) +{ +long ret =do_mmap2 (current->mm, addr, len, prot, flags, fd, pgoff); + +/* A tail call would reorder parameters on the stack and they would then +* be restored at the wrong places. */ +prevent_tail_call (ret); +return ret; +} +/* * Perform the select(nd, in, out, ex, tv) and mmap() system * calls. Linux/i386 didn't use to be able to handle more than
@@ -92,8 +104,11 @@if (a.offset & ~PAGE_MASK ) goto out; - err =sys_mmap2 (a.addr, a.len, a.prot, a.flags, + err =do_mmap2 (current->mm, a.addr, a.len, a.prot, a.flags, a.fd, a.offset >>PAGE_SHIFT ); +/* A tail call would reorder parameters on the stack and they would then +* be restored at the wrong places. */ +prevent_tail_call (err); out:return err; }
arch/x86/kernel/sys_x86_64.c +11 -4
@@ -15,6 +15,7 @@#include <asm/uaccess.h> #include <asm/ia32.h> +#include <asm/proc_mm_64.h> /* * sys_pipe() is the normal C calling standard for creating
@@ -33,7 +34,7 @@return error; } -asmlinkage long sys_mmap (unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags, +long do64_mmap (struct mm_struct *mm,unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags,unsigned long fd,unsigned long off) {long error;
@@ -51,9 +52,9 @@if (!file) goto out; } -down_write (¤t->mm->mmap_sem); - error =do_mmap_pgoff (file, addr, len, prot, flags, off >>PAGE_SHIFT ); -up_write (¤t->mm->mmap_sem); +down_write (&mm->mmap_sem); + error =__do_mmap_pgoff (mm, file, addr, len, prot, flags, off >>PAGE_SHIFT ); +up_write (&mm->mmap_sem);if (file)fput (file);
@@ -61,6 +62,12 @@return error; } +asmlinkage long sys_mmap (unsigned long addr,unsigned long len,unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long off) +{ +return do64_mmap (current->mm, addr, len, prot, flags, fd, off); +} +static void find_start_end (unsigned long flags,unsigned long *begin,unsigned long *end) {
arch/x86/mm/Makefile_64 +1 -0
@@ -7,4 +7,5 @@ obj-$(CONFIG_NUMA) += numa_64.o obj-$(CONFIG_K8_NUMA) += k8topology_64.o obj-$(CONFIG_ACPI_NUMA) += srat_64.o +obj-$(CONFIG_PROC_MM) += proc_mm_64.o
arch/x86/mm/proc_mm_64.c +85 -0
85 lines not on this page · raw message
include/asm-um/compat.h +9 -0
@@ -0,0 +1,9 @@ +#ifndef _ASM_X86_64_COMPAT_H +#define _ASM_X86_64_COMPAT_H + +typedef s32 compat_int_t ; +typedef s32 compat_long_t ; +typedef u32 compat_uint_t ; +typedef u32 compat_ulong_t ; + +#endif /* _ASM_X86_64_COMPAT_H */
include/asm-um/proc_mm_32.h +1 -0
@@ -0,0 +1 @@ +#include <asm/arch/proc_mm_32.h>
include/asm-um/proc_mm_64.h +1 -0
@@ -0,0 +1 @@ +#include <asm/arch/proc_mm_64.h>
include/asm-um/ptrace-x86_64.h +1 -0
@@ -78,4 +78,5 @@extern long arch_prctl (struct task_struct *task,int code,unsigned long __user *addr); +#endif
include/asm-x86/desc_32.h +3 -0
@@ -216,6 +216,9 @@ return base; } +extern int __modify_ldt (struct mm_struct * mm,int func,void __user *ptr, +unsigned long bytecount); +#else /* __ASSEMBLY__ */ /*
include/asm-x86/desc_64.h +3 -0
@@ -199,6 +199,9 @@extern struct desc_ptr idt_descr; +extern int __modify_ldt (struct mm_struct * mm,int func,void __user *ptr, +unsigned long bytecount); +#endif /* !__ASSEMBLY__ */ #endif
include/asm-x86/mmu_context_32.h +17 -2
@@ -5,6 +5,7 @@#include <asm/atomic.h> #include <asm/pgalloc.h> #include <asm/tlbflush.h> +#include <asm/semaphore.h> #include <asm/paravirt.h> #ifndef CONFIG_PARAVIRT #include <asm-generic/mm_hooks.h>
@@ -17,11 +18,22 @@/* -* Used for LDT copy/destruction. +* Used for LDT initialization/destruction. You cannot copy an LDT with +* init_new_context, since it thinks you are passing it a new LDT and won't +* deallocate its old content. */ int init_new_context (struct task_struct *tsk,struct mm_struct *mm);void destroy_context (struct mm_struct *mm); +/* LDT initialization for a clean environment - needed for SKAS.*/ +static inline void init_new_empty_context (struct mm_struct *mm) +{ +mutex_init (&mm->context.lock); + mm->context.size =0 ; +} + +/* LDT copy for SKAS - for the above problem.*/ +int copy_context (struct mm_struct *mm,struct mm_struct *old_mm);static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) {
@@ -40,6 +52,10 @@ {int cpu =smp_processor_id (); +#ifdef CONFIG_SMP + prev =per_cpu (cpu_tlbstate, cpu).active_mm; +#endif +if (likely (prev != next)) {/* stop flush ipis for the previous mm */ cpu_clear (cpu, prev->cpu_vm_mask);
@@ -61,7 +77,6 @@#ifdef CONFIG_SMP else {per_cpu (cpu_tlbstate, cpu).state =TLBSTATE_OK ; -BUG_ON (per_cpu (cpu_tlbstate, cpu).active_mm != next);if (!cpu_test_and_set (cpu, next->cpu_vm_mask)) {/* We were in lazy tlb mode and leave_mm disabled
include/asm-x86/mmu_context_64.h +18 -2
@@ -7,14 +7,29 @@#include <asm/pda.h> #include <asm/pgtable.h> #include <asm/tlbflush.h> +#include <asm/semaphore.h> #include <asm-generic/mm_hooks.h> /* * possibly do the LDT unload here? +* Used for LDT initialization/destruction. You cannot copy an LDT with +* init_new_context, since it thinks you are passing it a new LDT and won't +* deallocate its old content. */ +int init_new_context (struct task_struct *tsk,struct mm_struct *mm);void destroy_context (struct mm_struct *mm); +/* LDT initialization for a clean environment - needed for SKAS.*/ +static inline void init_new_empty_context (struct mm_struct *mm) +{ +mutex_init (&mm->context.lock); + mm->context.size =0 ; +} + +/* LDT copy for SKAS - for the above problem.*/ +int copy_context (struct mm_struct *mm,struct mm_struct *old_mm); +static inline void enter_lazy_tlb (struct mm_struct *mm,struct task_struct *tsk) {#ifdef CONFIG_SMP
@@ -32,6 +47,9 @@ struct task_struct *tsk) {unsigned cpu =smp_processor_id (); +#ifdef CONFIG_SMP + prev =read_pda (active_mm); +#endif if (likely (prev != next)) {/* stop flush ipis for the previous mm */ cpu_clear (cpu, prev->cpu_vm_mask);
@@ -48,8 +66,6 @@#ifdef CONFIG_SMP else {write_pda (mmu_state,TLBSTATE_OK ); -if (read_pda (active_mm) != next) -out_of_line_bug ();if (!cpu_test_and_set (cpu, next->cpu_vm_mask)) {/* We were in lazy tlb mode and leave_mm disabled * tlb flush IPI delivery. We must reload CR3
include/asm-x86/proc_mm_32.h +18 -0
@@ -0,0 +1,18 @@ +#ifndef __ASM_PROC_MM +#define __ASM_PROC_MM + +#include <asm/page.h> + +extern long do_mmap2 (struct mm_struct *mm,unsigned long addr, +unsigned long len,unsigned long prot,unsigned long flags, +unsigned long fd,unsigned long pgoff); + +static inline long __do_mmap (struct mm_struct *mm,unsigned long addr, +unsigned long len,unsigned long prot, +unsigned long flags,unsigned long fd, +unsigned long off) +{ +return do_mmap2 (mm, addr, len, prot, flags, fd, off >>PAGE_SHIFT ); +} + +#endif /* __ASM_PROC_MM */
include/asm-x86/proc_mm_64.h +58 -0
58 lines not on this page · raw message
include/asm-x86/ptrace-abi.h +6 -0
@@ -65,6 +65,12 @@#define PTRACE_GETFPXREGS 18#define PTRACE_SETFPXREGS 19 +#define PTRACE_FAULTINFO 52 +/* 53 was used for PTRACE_SIGPENDING, don't reuse it. */ +#define PTRACE_LDT 54 +#define PTRACE_SWITCH_MM 55 +#define PTRACE_EX_FAULTINFO 56 +#define PTRACE_OLDSETOPTIONS 21/* only useful for access 32bit programs / kernels */
include/asm-x86/ptrace.h +65 -0
69 lines not on this page · raw message
include/linux/mm.h +15 -4
@@ -5,6 +5,7 @@#ifdef __KERNEL__ +#include <linux/proc_mm.h> #include <linux/gfp.h> #include <linux/list.h> #include <linux/mmzone.h>
@@ -996,11 +997,18 @@extern unsigned long get_unmapped_area (struct file *,unsigned long ,unsigned long ,unsigned long ,unsigned long ); -extern unsigned long do_mmap_pgoff (struct file *file,unsigned long addr, +extern unsigned long __do_mmap_pgoff (struct mm_struct *mm,struct file *file, +unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flag, +unsigned long pgoff); +static inline unsigned long do_mmap_pgoff (struct file *file,unsigned long addr,unsigned long len,unsigned long prot, -unsigned long flag,unsigned long pgoff); -extern unsigned long mmap_region (struct file *file,unsigned long addr, -unsigned long len,unsigned long flags, +unsigned long flag,unsigned long pgoff) { +return __do_mmap_pgoff (current->mm, file, addr, len, prot, flag, pgoff); +} + +extern unsigned long mmap_region (struct mm_struct *mm,struct file *file, +unsigned long addr,unsigned long len,unsigned long flags,unsigned int vm_flags,unsigned long pgoff,int accountable);
@@ -1019,6 +1027,9 @@extern int do_munmap (struct mm_struct *,unsigned long ,size_t ); +extern long do_mprotect (struct mm_struct *mm,unsigned long start, +size_t len,unsigned long prot); +extern unsigned long do_brk (unsigned long ,unsigned long );/* filemap.c */
include/linux/proc_mm.h +110 -0
110 lines not on this page · raw message
mm/fremap.c +3 -2
@@ -192,8 +192,9 @@unsigned long addr; flags &=MAP_NONBLOCK ; - addr =mmap_region (vma->vm_file, start, size, - flags, vma->vm_flags, pgoff,1 ); + addr =mmap_region (current->mm, vma->vm_file, start, + size, flags, vma->vm_flags, pgoff, +1 );if (IS_ERR_VALUE (addr)) { err = addr; }else {
mm/Makefile +5 -0
@@ -29,5 +29,10 @@ obj-$(CONFIG_FS_XIP) += filemap_xip.o obj-$(CONFIG_MIGRATION) += migrate.o obj-$(CONFIG_SMP) += allocpercpu.o +obj-$(CONFIG_PROC_MM) += proc_mm.o + +ifeq ($(CONFIG_PROC_MM),y) +obj-m += proc_mm-mod.o +endif obj-$(CONFIG_QUICKLIST) += quicklist.o
mm/mmap.c +8 -9
@@ -887,12 +887,11 @@/* * The caller must hold down_write(current->mm->mmap_sem). */ - -unsigned long do_mmap_pgoff (struct file * file,unsigned long addr, -unsigned long len,unsigned long prot, -unsigned long flags,unsigned long pgoff) +unsigned long __do_mmap_pgoff (struct mm_struct *mm,struct file * file, +unsigned long addr,unsigned long len, +unsigned long prot,unsigned long flags, +unsigned long pgoff) { -struct mm_struct * mm = current->mm;struct inode *inode;unsigned int vm_flags;int error;
@@ -1026,10 +1025,10 @@if (error)return error; -return mmap_region (file, addr, len, flags, vm_flags, pgoff, +return mmap_region (mm, file, addr, len, flags, vm_flags, pgoff, accountable); } -EXPORT_SYMBOL (do_mmap_pgoff); +EXPORT_SYMBOL (__do_mmap_pgoff);/* * Some shared mappigns will want the pages marked read-only
@@ -1064,12 +1063,12 @@ } -unsigned long mmap_region (struct file *file,unsigned long addr, +unsigned long mmap_region (struct mm_struct *mm, +struct file *file,unsigned long addr,unsigned long len,unsigned long flags,unsigned int vm_flags,unsigned long pgoff,int accountable) { -struct mm_struct *mm = current->mm;struct vm_area_struct *vma, *prev;int correct_wcount =0 ;int error;
mm/mprotect.c +15 -5
@@ -211,8 +211,9 @@return error; } -asmlinkage long -sys_mprotect (unsigned long start,size_t len,unsigned long prot) +long +do_mprotect (struct mm_struct *mm,unsigned long start,size_t len, +unsigned long prot) {unsigned long vm_flags, nstart, end, tmp, reqprot;struct vm_area_struct *vma, *prev;
@@ -242,9 +243,9 @@ vm_flags =calc_vm_prot_bits (prot); -down_write (¤t->mm->mmap_sem); +down_write (&mm->mmap_sem); - vma =find_vma_prev (current->mm, start, &prev); + vma =find_vma_prev (mm, start, &prev); error = -ENOMEM ;if (!vma) goto out;
@@ -306,6 +307,15 @@ } } out: -up_write (¤t->mm->mmap_sem); +up_write (&mm->mmap_sem);return error; } + +asmlinkage long sys_mprotect (unsigned long start,size_t len,unsigned long prot) +{ +long ret =do_mprotect (current->mm, start, len, prot); +/* A tail call would reorder parameters on the stack and they would then +* be restored at the wrong places. */ +prevent_tail_call (ret); +return ret; +}
mm/proc_mm.c +299 -0
299 lines not on this page · raw message
mm/proc_mm-mod.c +50 -0
50 lines not on this page · raw message
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Re: [uml-devel] [RFC PATCH] SKAS3 for 2.6.24-rc7 (2nd try)
Oh, and it appears that with a little glue (attached), the SKAS3 and SKAS4 patches can co-exist. I currently have a host running with both SKAS3 and SKAS4 guests running on it. And if you apply SKAS3, SKAS4 and the glue to a guest, it should be able to run on SKAS3 or SKAS4 hosts (with SKAS4 being preferred if the host has both SKAS3 and SKAS4).
Repeating Jeff's warning about SKAS4: "This is very experimental at this point. Don't let it near anything resembling a production system." (Though SKAS4 has been working quite well for me in testing.)
RF
arch/x86/ia32/ptrace32.c | 4 ++-- arch/x86/kernel/ptrace_32.c | 2 +- arch/x86/kernel/ptrace_64.c | 2 +- include/asm-x86/ptrace-abi.h | 2 +- include/asm-x86/ptrace.h | 2 +- mm/proc_mm.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
arch/x86/ia32/ptrace32.c +2 -2
@@ -273,7 +273,7 @@case PTRACE_EX_FAULTINFO :case PTRACE_FAULTINFO :case PTRACE_LDT : -case PTRACE_SWITCH_MM : +case OLD_PTRACE_SWITCH_MM :#endif break ;
@@ -433,7 +433,7 @@break ; } -case PTRACE_SWITCH_MM : { +case OLD_PTRACE_SWITCH_MM : {struct mm_struct *old = child->mm;struct mm_struct *new =proc_mm_get_mm (data);
arch/x86/kernel/ptrace_32.c +1 -1
@@ -647,7 +647,7 @@break ; } -case PTRACE_SWITCH_MM : { +case OLD_PTRACE_SWITCH_MM : {struct mm_struct *old = child->mm;struct mm_struct *new =proc_mm_get_mm (data);
arch/x86/kernel/ptrace_64.c +1 -1
@@ -601,7 +601,7 @@break ; } -case PTRACE_SWITCH_MM : { +case OLD_PTRACE_SWITCH_MM : {struct mm_struct *old = child->mm;struct mm_struct *new =proc_mm_get_mm64 (data);
include/asm-x86/ptrace-abi.h +1 -1
@@ -68,7 +68,7 @@#define PTRACE_FAULTINFO 52/* 53 was used for PTRACE_SIGPENDING, don't reuse it. */ #define PTRACE_LDT 54 -#define PTRACE_SWITCH_MM 55 +#define OLD_PTRACE_SWITCH_MM 55#define PTRACE_EX_FAULTINFO 56#define PTRACE_OLDSETOPTIONS 21
include/asm-x86/ptrace.h +1 -1
@@ -146,7 +146,7 @@#define PTRACE_FAULTINFO 52/* 53 was used for PTRACE_SIGPENDING, don't reuse it. */ #define PTRACE_LDT 54 -#define PTRACE_SWITCH_MM 55 +#define OLD_PTRACE_SWITCH_MM 55#define PTRACE_EX_FAULTINFO 56struct ptrace_faultinfo {
mm/proc_mm.c +1 -1
@@ -32,7 +32,7 @@ }/* -* This is to be used in PTRACE_SWITCH_MM handling. We are going to set +* This is to be used in OLD_PTRACE_SWITCH_MM handling. We are going to set * child->mm to new, and we must first correctly set new->dumpable. * Since we take task_lock of child and it's needed also by the caller, we * return with it locked.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel