Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

exec: kill task_struct->did_exec

We can kill either task->did_exec or PF_FORKNOEXEC, they are mutually
exclusive. The patch kills ->did_exec because it has a single user.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Oleg Nesterov and committed by
Linus Torvalds
98611e4e 63e46b95

+2 -6
-1
fs/exec.c
··· 1424 1424 audit_bprm(bprm); 1425 1425 trace_sched_process_exec(current, old_pid, bprm); 1426 1426 ptrace_event(PTRACE_EVENT_EXEC, old_vpid); 1427 - current->did_exec = 1; 1428 1427 proc_exec_connector(current); 1429 1428 } 1430 1429
-1
include/linux/sched.h
··· 1239 1239 /* Used for emulating ABI behavior of previous Linux versions */ 1240 1240 unsigned int personality; 1241 1241 1242 - unsigned did_exec:1; 1243 1242 unsigned in_execve:1; /* Tell the LSMs that the process is doing an 1244 1243 * execve */ 1245 1244 unsigned in_iowait:1;
-1
kernel/fork.c
··· 1226 1226 if (!try_module_get(task_thread_info(p)->exec_domain->module)) 1227 1227 goto bad_fork_cleanup_count; 1228 1228 1229 - p->did_exec = 0; 1230 1229 delayacct_tsk_init(p); /* Must remain after dup_task_struct() */ 1231 1230 copy_flags(clone_flags, p); 1232 1231 INIT_LIST_HEAD(&p->children);
+2 -3
kernel/sys.c
··· 895 895 * only important on a multi-user system anyway, to make sure one user 896 896 * can't send a signal to a process owned by another. -TYT, 12/12/91 897 897 * 898 - * Auch. Had to add the 'did_exec' flag to conform completely to POSIX. 899 - * LBT 04.03.94 898 + * !PF_FORKNOEXEC check to conform completely to POSIX. 900 899 */ 901 900 SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid) 902 901 { ··· 931 932 if (task_session(p) != task_session(group_leader)) 932 933 goto out; 933 934 err = -EACCES; 934 - if (p->did_exec) 935 + if (!(p->flags & PF_FORKNOEXEC)) 935 936 goto out; 936 937 } else { 937 938 err = -ESRCH;