Skip to content

Commit 8890b29

Browse files
committed
exec: Move handling of the point of no return to the top level
Move the handing of the point of no return from search_binary_handler into __do_execve_file so that it is easier to find, and to keep things robust in the face of change. Make it clear that an existing fatal signal will take precedence over a forced SIGSEGV by not forcing SIGSEGV if a fatal signal is already pending. This does not change the behavior but it saves a reader of the code the tedium of reading and understanding force_sig and the signal delivery code. Update the comment in begin_new_exec about where SIGSEGV is forced. Keep point_of_no_return from being a mystery by documenting what the code is doing where it forces SIGSEGV if the code is past the point of no return. Reviewed-by: Kees Cook <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent a28bf13 commit 8890b29

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

fs/exec.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,8 +1329,8 @@ int begin_new_exec(struct linux_binprm * bprm)
13291329
/*
13301330
* With the new mm installed it is completely impossible to
13311331
* fail and return to the original process. If anything from
1332-
* here on returns an error, the check in
1333-
* search_binary_handler() will SEGV current.
1332+
* here on returns an error, the check in __do_execve_file()
1333+
* will SEGV current.
13341334
*/
13351335
bprm->point_of_no_return = true;
13361336
bprm->mm = NULL;
@@ -1721,13 +1721,8 @@ int search_binary_handler(struct linux_binprm *bprm)
17211721

17221722
read_lock(&binfmt_lock);
17231723
put_binfmt(fmt);
1724-
if (retval < 0 && bprm->point_of_no_return) {
1725-
/* we got to flush_old_exec() and failed after it */
1726-
read_unlock(&binfmt_lock);
1727-
force_sigsegv(SIGSEGV);
1728-
return retval;
1729-
}
1730-
if (retval != -ENOEXEC || !bprm->file) {
1724+
if (bprm->point_of_no_return || !bprm->file ||
1725+
(retval != -ENOEXEC)) {
17311726
read_unlock(&binfmt_lock);
17321727
return retval;
17331728
}
@@ -1898,6 +1893,14 @@ static int __do_execve_file(int fd, struct filename *filename,
18981893
return retval;
18991894

19001895
out:
1896+
/*
1897+
* If past the point of no return ensure the the code never
1898+
* returns to the userspace process. Use an existing fatal
1899+
* signal if present otherwise terminate the process with
1900+
* SIGSEGV.
1901+
*/
1902+
if (bprm->point_of_no_return && !fatal_signal_pending(current))
1903+
force_sigsegv(SIGSEGV);
19011904
if (bprm->mm) {
19021905
acct_arg_size(bprm, 0);
19031906
mmput(bprm->mm);

0 commit comments

Comments
 (0)