Skip to content

Commit ccf0fa6

Browse files
committed
exec: Move exec_mmap right after de_thread in flush_old_exec
I have read through the code in exec_mmap and I do not see anything that depends on sighand or the sighand lock, or on signals in anyway so this should be safe. This rearrangement of code has two significant benefits. It makes the determination of passing the point of no return by testing bprm->mm accurate. All failures prior to that point in flush_old_exec are either truly recoverable or they are fatal. Further this consolidates all of the possible indefinite waits for userspace together at the top of flush_old_exec. The possible wait for a ptracer on PTRACE_EVENT_EXIT, the possible wait for a page fault to be resolved in clear_child_tid, and the possible wait for a page fault in exit_robust_list. This consolidation allows the creation of a mutex to replace cred_guard_mutex that is not held over possible indefinite userspace waits. Which will allow removing deadlock scenarios from the kernel. Signed-off-by: "Eric W. Biederman" <[email protected]> Reviewed-by: Bernd Edlinger <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Kirill Tkhai <[email protected]> Signed-off-by: Bernd Edlinger <[email protected]> Signed-off-by: Eric W. Biederman <[email protected]>
1 parent 153ffb6 commit ccf0fa6

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

fs/exec.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,18 +1272,6 @@ int flush_old_exec(struct linux_binprm * bprm)
12721272
if (retval)
12731273
goto out;
12741274

1275-
#ifdef CONFIG_POSIX_TIMERS
1276-
exit_itimers(me->signal);
1277-
flush_itimer_signals();
1278-
#endif
1279-
1280-
/*
1281-
* Make the signal table private.
1282-
*/
1283-
retval = unshare_sighand(me);
1284-
if (retval)
1285-
goto out;
1286-
12871275
/*
12881276
* Must be called _before_ exec_mmap() as bprm->mm is
12891277
* not visibile until then. This also enables the update
@@ -1307,6 +1295,18 @@ int flush_old_exec(struct linux_binprm * bprm)
13071295
*/
13081296
bprm->mm = NULL;
13091297

1298+
#ifdef CONFIG_POSIX_TIMERS
1299+
exit_itimers(me->signal);
1300+
flush_itimer_signals();
1301+
#endif
1302+
1303+
/*
1304+
* Make the signal table private.
1305+
*/
1306+
retval = unshare_sighand(me);
1307+
if (retval)
1308+
goto out;
1309+
13101310
set_fs(USER_DS);
13111311
me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD |
13121312
PF_NOFREEZE | PF_NO_SETAFFINITY);

0 commit comments

Comments
 (0)