FAILED: patch "[PATCH] ptrace: Don't allow accessing an undumpable mm" failed to apply to 4.4-stable tree
Subsystems (8)
[email protected]
maintainerThe patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
Quoted 1 line
From
84d77d3f06e7e8dea057d10e8ec77ad71f721be3Mon Sep 17 00:00:00 2001
From: "Eric W. Biederman" <[email protected]>
Date: Tue, 22 Nov 2016 12:06:50 -0600
Subject: [PATCH] ptrace: Don't allow accessing an undumpable mm
It is the reasonable expectation that if an executable file is not readable there will be no way for a user without special privileges to read the file. This is enforced in ptrace_attach but if ptrace is already attached before exec there is no enforcement for read-only executables.
As the only way to read such an mm is through access_process_vm spin a variant called ptrace_access_vm that will fail if the target process is not being ptraced by the current process, or the current process did not have sufficient privileges when ptracing began to read the target processes mm.
In the ptrace implementations replace access_process_vm by ptrace_access_vm. There remain several ptrace sites that still use access_process_vm as they are reading the target executables instructions (for kernel consumption) or register stacks. As such it does not appear necessary to add a permission check to those calls.
This bug has always existed in Linux.
arch/alpha/kernel/ptrace.c +1 -1
@@ -283,7 +283,7 @@ long arch_ptrace(struct task_struct *child, long request,/* When I and D space are separate, these will need to be fixed. */ case PTRACE_PEEKTEXT :/* read word at location addr. */ case PTRACE_PEEKDATA : - copied =access_process_vm (child, addr, &tmp,sizeof (tmp), + copied =ptrace_access_vm (child, addr, &tmp,sizeof (tmp),FOLL_FORCE ); ret = -EIO ;if (copied !=sizeof (tmp))
arch/blackfin/kernel/ptrace.c +2 -2
@@ -270,7 +270,7 @@ long arch_ptrace(struct task_struct *child, long request,switch (bfin_mem_access_type (addr, to_copy)) {case BFIN_MEM_ACCESS_CORE :case BFIN_MEM_ACCESS_CORE_ONLY : - copied =access_process_vm (child, addr, &tmp, + copied =ptrace_access_vm (child, addr, &tmp, to_copy,FOLL_FORCE );if (copied)break ;
@@ -323,7 +323,7 @@ long arch_ptrace(struct task_struct *child, long request,switch (bfin_mem_access_type (addr, to_copy)) {case BFIN_MEM_ACCESS_CORE :case BFIN_MEM_ACCESS_CORE_ONLY : - copied =access_process_vm (child, addr, &data, + copied =ptrace_access_vm (child, addr, &data, to_copy,FOLL_FORCE |FOLL_WRITE );break ;
arch/cris/arch-v32/kernel/ptrace.c +1 -1
@@ -147,7 +147,7 @@ long arch_ptrace(struct task_struct *child, long request,/* The trampoline page is globally mapped, no page table to traverse.*/ tmp = *(unsigned long *)addr; }else { - copied =access_process_vm (child, addr, &tmp,sizeof (tmp),FOLL_FORCE ); + copied =ptrace_access_vm (child, addr, &tmp,sizeof (tmp),FOLL_FORCE );if (copied !=sizeof (tmp))break ;
arch/ia64/kernel/ptrace.c +1 -1
@@ -1159,7 +1159,7 @@ arch_ptrace (struct task_struct *child, long request,case PTRACE_PEEKTEXT :case PTRACE_PEEKDATA :/* read word at location addr */ -if (access_process_vm (child, addr, &data,sizeof (data), +if (ptrace_access_vm (child, addr, &data,sizeof (data),FOLL_FORCE ) !=sizeof (data))return -EIO ;
arch/mips/kernel/ptrace32.c +2 -2
@@ -69,7 +69,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,if (get_user (addrOthers, (u32 __user *__user *) (unsigned long ) addr) !=0 )break ; - copied =access_process_vm (child, (u64 )addrOthers, &tmp, + copied =ptrace_access_vm (child, (u64 )addrOthers, &tmp,sizeof (tmp),FOLL_FORCE );if (copied !=sizeof (tmp))break ;
@@ -178,7 +178,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,if (get_user (addrOthers, (u32 __user *__user *) (unsigned long ) addr) !=0 )break ; ret =0 ; -if (access_process_vm (child, (u64 )addrOthers, &data, +if (ptrace_access_vm (child, (u64 )addrOthers, &data,sizeof (data),FOLL_FORCE |FOLL_WRITE ) ==sizeof (data))break ;
arch/powerpc/kernel/ptrace32.c +2 -2
@@ -73,7 +73,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,if (get_user (addrOthers, (u32 __user *__user *)addr) !=0 )break ; - copied =access_process_vm (child, (u64 )addrOthers, &tmp, + copied =ptrace_access_vm (child, (u64 )addrOthers, &tmp,sizeof (tmp),FOLL_FORCE );if (copied !=sizeof (tmp))break ;
@@ -178,7 +178,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,if (get_user (addrOthers, (u32 __user *__user *)addr) !=0 )break ; ret =0 ; -if (access_process_vm (child, (u64 )addrOthers, &tmp, +if (ptrace_access_vm (child, (u64 )addrOthers, &tmp,sizeof (tmp),FOLL_FORCE |FOLL_WRITE ) ==sizeof (tmp))break ;
include/linux/mm.h +2 -0
@@ -1270,6 +1270,8 @@ extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void * unsigned int gup_flags);extern int access_remote_vm (struct mm_struct *mm,unsigned long addr,void *buf,int len,unsigned int gup_flags); +extern int __access_remote_vm (struct task_struct *tsk,struct mm_struct *mm, +unsigned long addr,void *buf,int len,unsigned int gup_flags); long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, unsigned long nr_pages,
include/linux/ptrace.h +3 -0
@@ -8,6 +8,9 @@#include <linux/pid_namespace.h> /* For task_active_pid_ns. */ #include <uapi/linux/ptrace.h> +extern int ptrace_access_vm (struct task_struct *tsk,unsigned long addr, +void *buf,int len,unsigned int gup_flags); +/* * Ptrace flags *
kernel/ptrace.c +36 -6
84 lines not on this page · raw message
mm/memory.c +1 -1
@@ -3868,7 +3868,7 @@ EXPORT_SYMBOL_GPL(generic_access_phys);* Access another process' address space as given in mm. If non-NULL, use the * given task for page fault accounting. */ -static int __access_remote_vm (struct task_struct *tsk,struct mm_struct *mm, +int __access_remote_vm (struct task_struct *tsk,struct mm_struct *mm,unsigned long addr,void *buf,int len,unsigned int gup_flags) {struct vm_area_struct *vma;
mm/nommu.c +1 -1
@@ -1808,7 +1808,7 @@ void filemap_map_pages(struct fault_env *fe, }EXPORT_SYMBOL (filemap_map_pages); -static int __access_remote_vm (struct task_struct *tsk,struct mm_struct *mm, +int __access_remote_vm (struct task_struct *tsk,struct mm_struct *mm,unsigned long addr,void *buf,int len,unsigned int gup_flags) {struct vm_area_struct *vma;