[PATCH RFC 06/19] exec: move unshare_sighand() before exec_mmap()
Christian Brauner
brauner at kernel.org
Tue Nov 24 22:58:29 UTC 2026
A task that called vfork() sleeps until the child has released the mm.
During exec that happens in exec_mmap(). A child that was created with
CLONE_SIGHAND shares its signal table with the parent and
unshare_sighand() only gives it a private one after exec_mmap(). So the
parent runs again while the child is still on the table they share. If
the parent ignores a signal right after vfork() returned the new image
can end up ignoring it as well.
It used to be the other way around. Commit ccf0fa6be026 ("exec: Move
exec_mmap right after de_thread in flush_old_exec") moved exec_mmap() in
front of it for two reasons. bprm->mm was to tell whether exec is past
the point of no return and everything that can wait for userspace
indefinitely was to sit in front of the lock that became
exec_update_lock.
Move it back to where it used to be, right after de_thread() and the
posix timer cleanup. Nothing in between relies on the signal table still
being shared. With that the table is private before the parent is woken
up. And the new table isn't allocated with exec_update_lock held
anymore.
Fixes: ccf0fa6be026 ("exec: Move exec_mmap right after de_thread in flush_old_exec")
Cc: stable at vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner at kernel.org>
---
fs/exec.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index 8d2b14e1d455c..87b78fce609de 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1171,6 +1171,14 @@ int begin_new_exec(struct linux_binprm * bprm)
*/
posixtimer_exec();
+ /*
+ * Make the signal table private before a vfork() parent that shares
+ * it is woken up.
+ */
+ retval = unshare_sighand(me);
+ if (retval)
+ goto out;
+
/* see the comment in check_unsafe_exec() */
current->fs->in_exec = 0;
@@ -1223,13 +1231,6 @@ int begin_new_exec(struct linux_binprm * bprm)
if (retval)
goto out_unlock;
- /*
- * Make the signal table private.
- */
- retval = unshare_sighand(me);
- if (retval)
- goto out_unlock;
-
me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC |
PF_NOFREEZE | PF_NO_SETAFFINITY);
flush_thread();
--
2.53.0
More information about the Linux-security-module-archive
mailing list