Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-doc
Path: blob/main/website/static/security/patches/EN-14:06/exec-9.patch
18096 views
1
Index: sys/kern/kern_exec.c
2
===================================================================
3
--- sys/kern/kern_exec.c (revision 266584)
4
+++ sys/kern/kern_exec.c (revision 266585)
5
@@ -282,6 +282,7 @@ kern_execve(td, args, mac_p)
6
struct mac *mac_p;
7
{
8
struct proc *p = td->td_proc;
9
+ struct vmspace *oldvmspace;
10
int error;
11
12
AUDIT_ARG_ARGV(args->begin_argv, args->argc,
13
@@ -298,6 +299,8 @@ kern_execve(td, args, mac_p)
14
PROC_UNLOCK(p);
15
}
16
17
+ KASSERT((td->td_pflags & TDP_EXECVMSPC) == 0, ("nested execve"));
18
+ oldvmspace = td->td_proc->p_vmspace;
19
error = do_execve(td, args, mac_p);
20
21
if (p->p_flag & P_HADTHREADS) {
22
@@ -312,6 +315,12 @@ kern_execve(td, args, mac_p)
23
thread_single_end();
24
PROC_UNLOCK(p);
25
}
26
+ if ((td->td_pflags & TDP_EXECVMSPC) != 0) {
27
+ KASSERT(td->td_proc->p_vmspace != oldvmspace,
28
+ ("oldvmspace still used"));
29
+ vmspace_free(oldvmspace);
30
+ td->td_pflags &= ~TDP_EXECVMSPC;
31
+ }
32
33
return (error);
34
}
35
Index: sys/sys/proc.h
36
===================================================================
37
--- sys/sys/proc.h (revision 266584)
38
+++ sys/sys/proc.h (revision 266585)
39
@@ -426,6 +426,7 @@ do { \
40
#define TDP_NERRNO 0x08000000 /* Last errno is already in td_errno */
41
#define TDP_UIOHELD 0x10000000 /* Current uio has pages held in td_ma */
42
#define TDP_DEVMEMIO 0x20000000 /* Accessing memory for /dev/mem */
43
+#define TDP_EXECVMSPC 0x40000000 /* Execve destroyed old vmspace */
44
45
/*
46
* Reasons that the current thread can not be run yet.
47
Index: sys/sys
48
===================================================================
49
--- sys/sys (revision 266584)
50
+++ sys/sys (revision 266585)
51
52
Property changes on: sys/sys
53
___________________________________________________________________
54
Modified: svn:mergeinfo
55
Merged /head/sys/sys:r266464
56
Index: sys/vm/vm_map.c
57
===================================================================
58
--- sys/vm/vm_map.c (revision 266584)
59
+++ sys/vm/vm_map.c (revision 266585)
60
@@ -3752,6 +3752,8 @@ vmspace_exec(struct proc *p, vm_offset_t minuser,
61
struct vmspace *oldvmspace = p->p_vmspace;
62
struct vmspace *newvmspace;
63
64
+ KASSERT((curthread->td_pflags & TDP_EXECVMSPC) == 0,
65
+ ("vmspace_exec recursed"));
66
newvmspace = vmspace_alloc(minuser, maxuser);
67
if (newvmspace == NULL)
68
return (ENOMEM);
69
@@ -3768,7 +3770,7 @@ vmspace_exec(struct proc *p, vm_offset_t minuser,
70
PROC_VMSPACE_UNLOCK(p);
71
if (p == curthread->td_proc)
72
pmap_activate(curthread);
73
- vmspace_free(oldvmspace);
74
+ curthread->td_pflags |= TDP_EXECVMSPC;
75
return (0);
76
}
77
78
Index: sys
79
===================================================================
80
--- sys (revision 266584)
81
+++ sys (revision 266585)
82
83
Property changes on: sys
84
___________________________________________________________________
85
Modified: svn:mergeinfo
86
Merged /head/sys:r266464
87
88