diff options
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 495da2e9a8b4..6144b36cd897 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -47,6 +47,7 @@ | |||
47 | #include <linux/mount.h> | 47 | #include <linux/mount.h> |
48 | #include <linux/audit.h> | 48 | #include <linux/audit.h> |
49 | #include <linux/memcontrol.h> | 49 | #include <linux/memcontrol.h> |
50 | #include <linux/ftrace.h> | ||
50 | #include <linux/profile.h> | 51 | #include <linux/profile.h> |
51 | #include <linux/rmap.h> | 52 | #include <linux/rmap.h> |
52 | #include <linux/acct.h> | 53 | #include <linux/acct.h> |
@@ -80,6 +81,8 @@ DEFINE_PER_CPU(unsigned long, process_counts) = 0; | |||
80 | 81 | ||
81 | __cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */ | 82 | __cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */ |
82 | 83 | ||
84 | DEFINE_TRACE(sched_process_fork); | ||
85 | |||
83 | int nr_processes(void) | 86 | int nr_processes(void) |
84 | { | 87 | { |
85 | int cpu; | 88 | int cpu; |
@@ -137,6 +140,7 @@ void free_task(struct task_struct *tsk) | |||
137 | prop_local_destroy_single(&tsk->dirties); | 140 | prop_local_destroy_single(&tsk->dirties); |
138 | free_thread_info(tsk->stack); | 141 | free_thread_info(tsk->stack); |
139 | rt_mutex_debug_task_free(tsk); | 142 | rt_mutex_debug_task_free(tsk); |
143 | ftrace_graph_exit_task(tsk); | ||
140 | free_task_struct(tsk); | 144 | free_task_struct(tsk); |
141 | } | 145 | } |
142 | EXPORT_SYMBOL(free_task); | 146 | EXPORT_SYMBOL(free_task); |
@@ -147,9 +151,8 @@ void __put_task_struct(struct task_struct *tsk) | |||
147 | WARN_ON(atomic_read(&tsk->usage)); | 151 | WARN_ON(atomic_read(&tsk->usage)); |
148 | WARN_ON(tsk == current); | 152 | WARN_ON(tsk == current); |
149 | 153 | ||
150 | security_task_free(tsk); | 154 | put_cred(tsk->real_cred); |
151 | free_uid(tsk->user); | 155 | put_cred(tsk->cred); |
152 | put_group_info(tsk->group_info); | ||
153 | delayacct_tsk_free(tsk); | 156 | delayacct_tsk_free(tsk); |
154 | 157 | ||
155 | if (!profile_handoff_task(tsk)) | 158 | if (!profile_handoff_task(tsk)) |
@@ -818,12 +821,6 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
818 | if (!sig) | 821 | if (!sig) |
819 | return -ENOMEM; | 822 | return -ENOMEM; |
820 | 823 | ||
821 | ret = copy_thread_group_keys(tsk); | ||
822 | if (ret < 0) { | ||
823 | kmem_cache_free(signal_cachep, sig); | ||
824 | return ret; | ||
825 | } | ||
826 | |||
827 | atomic_set(&sig->count, 1); | 824 | atomic_set(&sig->count, 1); |
828 | atomic_set(&sig->live, 1); | 825 | atomic_set(&sig->live, 1); |
829 | init_waitqueue_head(&sig->wait_chldexit); | 826 | init_waitqueue_head(&sig->wait_chldexit); |
@@ -868,7 +865,6 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
868 | void __cleanup_signal(struct signal_struct *sig) | 865 | void __cleanup_signal(struct signal_struct *sig) |
869 | { | 866 | { |
870 | thread_group_cputime_free(sig); | 867 | thread_group_cputime_free(sig); |
871 | exit_thread_group_keys(sig); | ||
872 | tty_kref_put(sig->tty); | 868 | tty_kref_put(sig->tty); |
873 | kmem_cache_free(signal_cachep, sig); | 869 | kmem_cache_free(signal_cachep, sig); |
874 | } | 870 | } |
@@ -984,16 +980,16 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
984 | DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled); | 980 | DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled); |
985 | #endif | 981 | #endif |
986 | retval = -EAGAIN; | 982 | retval = -EAGAIN; |
987 | if (atomic_read(&p->user->processes) >= | 983 | if (atomic_read(&p->real_cred->user->processes) >= |
988 | p->signal->rlim[RLIMIT_NPROC].rlim_cur) { | 984 | p->signal->rlim[RLIMIT_NPROC].rlim_cur) { |
989 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && | 985 | if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && |
990 | p->user != current->nsproxy->user_ns->root_user) | 986 | p->real_cred->user != INIT_USER) |
991 | goto bad_fork_free; | 987 | goto bad_fork_free; |
992 | } | 988 | } |
993 | 989 | ||
994 | atomic_inc(&p->user->__count); | 990 | retval = copy_creds(p, clone_flags); |
995 | atomic_inc(&p->user->processes); | 991 | if (retval < 0) |
996 | get_group_info(p->group_info); | 992 | goto bad_fork_free; |
997 | 993 | ||
998 | /* | 994 | /* |
999 | * If multiple threads are within copy_process(), then this check | 995 | * If multiple threads are within copy_process(), then this check |
@@ -1048,10 +1044,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1048 | do_posix_clock_monotonic_gettime(&p->start_time); | 1044 | do_posix_clock_monotonic_gettime(&p->start_time); |
1049 | p->real_start_time = p->start_time; | 1045 | p->real_start_time = p->start_time; |
1050 | monotonic_to_bootbased(&p->real_start_time); | 1046 | monotonic_to_bootbased(&p->real_start_time); |
1051 | #ifdef CONFIG_SECURITY | ||
1052 | p->security = NULL; | ||
1053 | #endif | ||
1054 | p->cap_bset = current->cap_bset; | ||
1055 | p->io_context = NULL; | 1047 | p->io_context = NULL; |
1056 | p->audit_context = NULL; | 1048 | p->audit_context = NULL; |
1057 | cgroup_fork(p); | 1049 | cgroup_fork(p); |
@@ -1092,14 +1084,14 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1092 | #ifdef CONFIG_DEBUG_MUTEXES | 1084 | #ifdef CONFIG_DEBUG_MUTEXES |
1093 | p->blocked_on = NULL; /* not blocked yet */ | 1085 | p->blocked_on = NULL; /* not blocked yet */ |
1094 | #endif | 1086 | #endif |
1087 | if (unlikely(ptrace_reparented(current))) | ||
1088 | ptrace_fork(p, clone_flags); | ||
1095 | 1089 | ||
1096 | /* Perform scheduler related setup. Assign this task to a CPU. */ | 1090 | /* Perform scheduler related setup. Assign this task to a CPU. */ |
1097 | sched_fork(p, clone_flags); | 1091 | sched_fork(p, clone_flags); |
1098 | 1092 | ||
1099 | if ((retval = security_task_alloc(p))) | ||
1100 | goto bad_fork_cleanup_policy; | ||
1101 | if ((retval = audit_alloc(p))) | 1093 | if ((retval = audit_alloc(p))) |
1102 | goto bad_fork_cleanup_security; | 1094 | goto bad_fork_cleanup_policy; |
1103 | /* copy all the process information */ | 1095 | /* copy all the process information */ |
1104 | if ((retval = copy_semundo(clone_flags, p))) | 1096 | if ((retval = copy_semundo(clone_flags, p))) |
1105 | goto bad_fork_cleanup_audit; | 1097 | goto bad_fork_cleanup_audit; |
@@ -1113,10 +1105,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1113 | goto bad_fork_cleanup_sighand; | 1105 | goto bad_fork_cleanup_sighand; |
1114 | if ((retval = copy_mm(clone_flags, p))) | 1106 | if ((retval = copy_mm(clone_flags, p))) |
1115 | goto bad_fork_cleanup_signal; | 1107 | goto bad_fork_cleanup_signal; |
1116 | if ((retval = copy_keys(clone_flags, p))) | ||
1117 | goto bad_fork_cleanup_mm; | ||
1118 | if ((retval = copy_namespaces(clone_flags, p))) | 1108 | if ((retval = copy_namespaces(clone_flags, p))) |
1119 | goto bad_fork_cleanup_keys; | 1109 | goto bad_fork_cleanup_mm; |
1120 | if ((retval = copy_io(clone_flags, p))) | 1110 | if ((retval = copy_io(clone_flags, p))) |
1121 | goto bad_fork_cleanup_namespaces; | 1111 | goto bad_fork_cleanup_namespaces; |
1122 | retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs); | 1112 | retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs); |
@@ -1136,6 +1126,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1136 | } | 1126 | } |
1137 | } | 1127 | } |
1138 | 1128 | ||
1129 | ftrace_graph_init_task(p); | ||
1130 | |||
1139 | p->pid = pid_nr(pid); | 1131 | p->pid = pid_nr(pid); |
1140 | p->tgid = p->pid; | 1132 | p->tgid = p->pid; |
1141 | if (clone_flags & CLONE_THREAD) | 1133 | if (clone_flags & CLONE_THREAD) |
@@ -1144,7 +1136,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1144 | if (current->nsproxy != p->nsproxy) { | 1136 | if (current->nsproxy != p->nsproxy) { |
1145 | retval = ns_cgroup_clone(p, pid); | 1137 | retval = ns_cgroup_clone(p, pid); |
1146 | if (retval) | 1138 | if (retval) |
1147 | goto bad_fork_free_pid; | 1139 | goto bad_fork_free_graph; |
1148 | } | 1140 | } |
1149 | 1141 | ||
1150 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; | 1142 | p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; |
@@ -1237,7 +1229,7 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1237 | spin_unlock(¤t->sighand->siglock); | 1229 | spin_unlock(¤t->sighand->siglock); |
1238 | write_unlock_irq(&tasklist_lock); | 1230 | write_unlock_irq(&tasklist_lock); |
1239 | retval = -ERESTARTNOINTR; | 1231 | retval = -ERESTARTNOINTR; |
1240 | goto bad_fork_free_pid; | 1232 | goto bad_fork_free_graph; |
1241 | } | 1233 | } |
1242 | 1234 | ||
1243 | if (clone_flags & CLONE_THREAD) { | 1235 | if (clone_flags & CLONE_THREAD) { |
@@ -1274,6 +1266,8 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1274 | cgroup_post_fork(p); | 1266 | cgroup_post_fork(p); |
1275 | return p; | 1267 | return p; |
1276 | 1268 | ||
1269 | bad_fork_free_graph: | ||
1270 | ftrace_graph_exit_task(p); | ||
1277 | bad_fork_free_pid: | 1271 | bad_fork_free_pid: |
1278 | if (pid != &init_struct_pid) | 1272 | if (pid != &init_struct_pid) |
1279 | free_pid(pid); | 1273 | free_pid(pid); |
@@ -1281,8 +1275,6 @@ bad_fork_cleanup_io: | |||
1281 | put_io_context(p->io_context); | 1275 | put_io_context(p->io_context); |
1282 | bad_fork_cleanup_namespaces: | 1276 | bad_fork_cleanup_namespaces: |
1283 | exit_task_namespaces(p); | 1277 | exit_task_namespaces(p); |
1284 | bad_fork_cleanup_keys: | ||
1285 | exit_keys(p); | ||
1286 | bad_fork_cleanup_mm: | 1278 | bad_fork_cleanup_mm: |
1287 | if (p->mm) | 1279 | if (p->mm) |
1288 | mmput(p->mm); | 1280 | mmput(p->mm); |
@@ -1298,8 +1290,6 @@ bad_fork_cleanup_semundo: | |||
1298 | exit_sem(p); | 1290 | exit_sem(p); |
1299 | bad_fork_cleanup_audit: | 1291 | bad_fork_cleanup_audit: |
1300 | audit_free(p); | 1292 | audit_free(p); |
1301 | bad_fork_cleanup_security: | ||
1302 | security_task_free(p); | ||
1303 | bad_fork_cleanup_policy: | 1293 | bad_fork_cleanup_policy: |
1304 | #ifdef CONFIG_NUMA | 1294 | #ifdef CONFIG_NUMA |
1305 | mpol_put(p->mempolicy); | 1295 | mpol_put(p->mempolicy); |
@@ -1312,9 +1302,9 @@ bad_fork_cleanup_cgroup: | |||
1312 | bad_fork_cleanup_put_domain: | 1302 | bad_fork_cleanup_put_domain: |
1313 | module_put(task_thread_info(p)->exec_domain->module); | 1303 | module_put(task_thread_info(p)->exec_domain->module); |
1314 | bad_fork_cleanup_count: | 1304 | bad_fork_cleanup_count: |
1315 | put_group_info(p->group_info); | 1305 | atomic_dec(&p->cred->user->processes); |
1316 | atomic_dec(&p->user->processes); | 1306 | put_cred(p->real_cred); |
1317 | free_uid(p->user); | 1307 | put_cred(p->cred); |
1318 | bad_fork_free: | 1308 | bad_fork_free: |
1319 | free_task(p); | 1309 | free_task(p); |
1320 | fork_out: | 1310 | fork_out: |
@@ -1358,6 +1348,21 @@ long do_fork(unsigned long clone_flags, | |||
1358 | long nr; | 1348 | long nr; |
1359 | 1349 | ||
1360 | /* | 1350 | /* |
1351 | * Do some preliminary argument and permissions checking before we | ||
1352 | * actually start allocating stuff | ||
1353 | */ | ||
1354 | if (clone_flags & CLONE_NEWUSER) { | ||
1355 | if (clone_flags & CLONE_THREAD) | ||
1356 | return -EINVAL; | ||
1357 | /* hopefully this check will go away when userns support is | ||
1358 | * complete | ||
1359 | */ | ||
1360 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) || | ||
1361 | !capable(CAP_SETGID)) | ||
1362 | return -EPERM; | ||
1363 | } | ||
1364 | |||
1365 | /* | ||
1361 | * We hope to recycle these flags after 2.6.26 | 1366 | * We hope to recycle these flags after 2.6.26 |
1362 | */ | 1367 | */ |
1363 | if (unlikely(clone_flags & CLONE_STOPPED)) { | 1368 | if (unlikely(clone_flags & CLONE_STOPPED)) { |
@@ -1605,8 +1610,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags) | |||
1605 | err = -EINVAL; | 1610 | err = -EINVAL; |
1606 | if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND| | 1611 | if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND| |
1607 | CLONE_VM|CLONE_FILES|CLONE_SYSVSEM| | 1612 | CLONE_VM|CLONE_FILES|CLONE_SYSVSEM| |
1608 | CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWUSER| | 1613 | CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET)) |
1609 | CLONE_NEWNET)) | ||
1610 | goto bad_unshare_out; | 1614 | goto bad_unshare_out; |
1611 | 1615 | ||
1612 | /* | 1616 | /* |