From 0c846c3398f42faef575532660d53702c4f6afba Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Thu, 3 May 2012 15:45:00 +1000 Subject: [PATCH] c/r: prctl: simplify PR_SET_MM on mm::code/data assignment The mm::start_code, end_code, start_data, end_data members are set during startup of executable file and are not changed after. But the program itself might map new executable or/and data areas in time so the original values written into mm fields mentioned above might not have correspond VMA area at all, thus if one try to use this prctl codes without underlied VMA, the error will be returned. Drop this requirement. This shrinks the code and eliminates redundant calls to vma_flags_mismatch. The worst thing one can do (if say to write some bad values here) -- the weird results will be shown in /proc/$pid/statm or in /proc/pid/stat. Still, assignement of data on stack (such as command line and environment variables) requires the underlied VMA to exist. Signed-off-by: Cyrill Gorcunov Cc: Kees Cook Cc: Tejun Heo Acked-by: Serge Hallyn Cc: Pavel Emelyanov Cc: KAMEZAWA Hiroyuki Signed-off-by: Andrew Morton --- kernel/sys.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/kernel/sys.c b/kernel/sys.c index bd214a6b7167..66ca44c6875d 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1727,42 +1727,21 @@ static int prctl_set_mm(int opt, unsigned long addr, if (addr >= TASK_SIZE) return -EINVAL; - error = -EINVAL; - down_read(&mm->mmap_sem); vma = find_vma(mm, addr); - if (opt != PR_SET_MM_START_BRK && - opt != PR_SET_MM_BRK && - opt != PR_SET_MM_AUXV) { - /* It must be existing VMA */ - if (!vma || vma->vm_start > addr) - goto out; - } - switch (opt) { case PR_SET_MM_START_CODE: + mm->start_code = addr; + break; case PR_SET_MM_END_CODE: - if (vma_flags_mismatch(vma, VM_READ | VM_EXEC, - VM_WRITE | VM_MAYSHARE)) - goto out; - - if (opt == PR_SET_MM_START_CODE) - mm->start_code = addr; - else - mm->end_code = addr; + mm->end_code = addr; break; - case PR_SET_MM_START_DATA: + mm->start_data = addr; + break; case PR_SET_MM_END_DATA: - if (vma_flags_mismatch(vma, VM_READ | VM_WRITE, - VM_EXEC | VM_MAYSHARE)) - goto out; - - if (opt == PR_SET_MM_START_DATA) - mm->start_data = addr; - else - mm->end_data = addr; + mm->end_data = addr; break; case PR_SET_MM_START_BRK: @@ -1801,6 +1780,8 @@ static int prctl_set_mm(int opt, unsigned long addr, case PR_SET_MM_ARG_END: case PR_SET_MM_ENV_START: case PR_SET_MM_ENV_END: + if (!vma) + goto out; #ifdef CONFIG_STACK_GROWSUP if (vma_flags_mismatch(vma, VM_READ | VM_WRITE | VM_GROWSUP, 0)) #else -- 2.39.2