Path: blob/main/website/static/security/patches/EN-14:06/exec-9.2.patch
18096 views
Index: sys/kern/kern_exec.c1===================================================================2--- sys/kern/kern_exec.c (revision 266979)3+++ sys/kern/kern_exec.c (working copy)4@@ -280,6 +280,7 @@ kern_execve(td, args, mac_p)5struct mac *mac_p;6{7struct proc *p = td->td_proc;8+ struct vmspace *oldvmspace;9int error;1011AUDIT_ARG_ARGV(args->begin_argv, args->argc,12@@ -296,6 +297,8 @@ kern_execve(td, args, mac_p)13PROC_UNLOCK(p);14}1516+ KASSERT((td->td_pflags & TDP_EXECVMSPC) == 0, ("nested execve"));17+ oldvmspace = td->td_proc->p_vmspace;18error = do_execve(td, args, mac_p);1920if (p->p_flag & P_HADTHREADS) {21@@ -310,6 +313,12 @@ kern_execve(td, args, mac_p)22thread_single_end();23PROC_UNLOCK(p);24}25+ if ((td->td_pflags & TDP_EXECVMSPC) != 0) {26+ KASSERT(td->td_proc->p_vmspace != oldvmspace,27+ ("oldvmspace still used"));28+ vmspace_free(oldvmspace);29+ td->td_pflags &= ~TDP_EXECVMSPC;30+ }3132return (error);33}34Index: sys/sys/proc.h35===================================================================36--- sys/sys/proc.h (revision 266979)37+++ sys/sys/proc.h (working copy)38@@ -977,4 +977,5 @@ curthread_pflags_restore(int save)3940#endif /* _KERNEL */4142+#define TDP_EXECVMSPC 0x40000000 /* Execve destroyed old vmspace */43#endif /* !_SYS_PROC_H_ */44Index: sys/vm/vm_map.c45===================================================================46--- sys/vm/vm_map.c (revision 266979)47+++ sys/vm/vm_map.c (working copy)48@@ -3669,6 +3669,8 @@ vmspace_exec(struct proc *p, vm_offset_t minuser,49struct vmspace *oldvmspace = p->p_vmspace;50struct vmspace *newvmspace;5152+ KASSERT((curthread->td_pflags & TDP_EXECVMSPC) == 0,53+ ("vmspace_exec recursed"));54newvmspace = vmspace_alloc(minuser, maxuser);55if (newvmspace == NULL)56return (ENOMEM);57@@ -3685,7 +3687,7 @@ vmspace_exec(struct proc *p, vm_offset_t minuser,58PROC_VMSPACE_UNLOCK(p);59if (p == curthread->td_proc)60pmap_activate(curthread);61- vmspace_free(oldvmspace);62+ curthread->td_pflags |= TDP_EXECVMSPC;63return (0);64}65666768