Skip to content

Commit f87d1c9

Browse files
committed
exec: Move would_dump into flush_old_exec
I goofed when I added mm->user_ns support to would_dump. I missed the fact that in the case of binfmt_loader, binfmt_em86, binfmt_misc, and binfmt_script bprm->file is reassigned. Which made the move of would_dump from setup_new_exec to __do_execve_file before exec_binprm incorrect as it can result in would_dump running on the script instead of the interpreter of the script. The net result is that the code stopped making unreadable interpreters undumpable. Which allows them to be ptraced and written to disk without special permissions. Oops. The move was necessary because the call in set_new_exec was after bprm->mm was no longer valid. To correct this mistake move the misplaced would_dump from __do_execve_file into flos_old_exec, before exec_mmap is called. I tested and confirmed that without this fix I can attach with gdb to a script with an unreadable interpreter, and with this fix I can not. Cc: [email protected] Fixes: f84df2a ("exec: Ensure mm->user_ns contains the execed files") Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 6a8b55e commit f87d1c9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/exec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,8 @@ int flush_old_exec(struct linux_binprm * bprm)
13171317
*/
13181318
set_mm_exe_file(bprm->mm, bprm->file);
13191319

1320+
would_dump(bprm, bprm->file);
1321+
13201322
/*
13211323
* Release all of the old mmap stuff
13221324
*/
@@ -1876,8 +1878,6 @@ static int __do_execve_file(int fd, struct filename *filename,
18761878
if (retval < 0)
18771879
goto out;
18781880

1879-
would_dump(bprm, bprm->file);
1880-
18811881
retval = exec_binprm(bprm);
18821882
if (retval < 0)
18831883
goto out;

0 commit comments

Comments
 (0)