[PATCH] Fix issues with exec_update_mutex

From: Bernd Edlinger
Date: Wed Mar 11 2020 - 10:31:07 EST


Signed-off-by: Bernd Edlinger <bernd.edlinger@xxxxxxxxxx>
---
fs/exec.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index ffeebb1..cde4937 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1021,8 +1021,14 @@ static int exec_mmap(struct mm_struct *mm)
old_mm = current->mm;
exec_mm_release(tsk, old_mm);

- if (old_mm) {
+ if (old_mm)
sync_mm_rss(old_mm);
+
+ ret = mutex_lock_killable(&tsk->signal->exec_update_mutex);
+ if (ret)
+ return ret;
+
+ if (old_mm) {
/*
* Make sure that if there is a core dump in progress
* for the old mm, we get out and die instead of going
@@ -1032,14 +1038,11 @@ static int exec_mmap(struct mm_struct *mm)
down_read(&old_mm->mmap_sem);
if (unlikely(old_mm->core_state)) {
up_read(&old_mm->mmap_sem);
+ mutex_unlock(&tsk->signal->exec_update_mutex);
return -EINTR;
}
}

- ret = mutex_lock_killable(&tsk->signal->exec_update_mutex);
- if (ret)
- return ret;
-
task_lock(tsk);
active_mm = tsk->active_mm;
membarrier_exec_mmap(mm);
@@ -1444,8 +1447,6 @@ static void free_bprm(struct linux_binprm *bprm)
{
free_arg_pages(bprm);
if (bprm->cred) {
- if (!bprm->mm)
- mutex_unlock(&current->signal->exec_update_mutex);
mutex_unlock(&current->signal->cred_guard_mutex);
abort_creds(bprm->cred);
}
@@ -1846,6 +1847,8 @@ static int __do_execve_file(int fd, struct filename *filename,
would_dump(bprm, bprm->file);

retval = exec_binprm(bprm);
+ if (bprm->cred && !bprm->mm)
+ mutex_unlock(&current->signal->exec_update_mutex);
if (retval < 0)
goto out;

--
1.9.1