Commit 269b005a authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

coredump: shift down_write(mmap_sem) into coredump_wait()

- move the cprm.mm_flags checks up, before we take mmap_sem

- move down_write(mmap_sem) and ->core_state check from do_coredump()
  to coredump_wait()

This simplifies the code and makes the locking symmetrical.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5e43aef5
...@@ -1662,11 +1662,14 @@ static int coredump_wait(int exit_code, struct core_state *core_state) ...@@ -1662,11 +1662,14 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
struct task_struct *tsk = current; struct task_struct *tsk = current;
struct mm_struct *mm = tsk->mm; struct mm_struct *mm = tsk->mm;
struct completion *vfork_done; struct completion *vfork_done;
int core_waiters; int core_waiters = -EBUSY;
init_completion(&core_state->startup); init_completion(&core_state->startup);
core_state->dumper.task = tsk; core_state->dumper.task = tsk;
core_state->dumper.next = NULL; core_state->dumper.next = NULL;
down_write(&mm->mmap_sem);
if (!mm->core_state)
core_waiters = zap_threads(tsk, mm, core_state, exit_code); core_waiters = zap_threads(tsk, mm, core_state, exit_code);
up_write(&mm->mmap_sem); up_write(&mm->mmap_sem);
...@@ -1860,20 +1863,12 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs) ...@@ -1860,20 +1863,12 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
binfmt = mm->binfmt; binfmt = mm->binfmt;
if (!binfmt || !binfmt->core_dump) if (!binfmt || !binfmt->core_dump)
goto fail; goto fail;
if (!__get_dumpable(cprm.mm_flags))
goto fail;
cred = prepare_creds(); cred = prepare_creds();
if (!cred) if (!cred)
goto fail; goto fail;
down_write(&mm->mmap_sem);
/*
* If another thread got here first, or we are not dumpable, bail out.
*/
if (mm->core_state || !__get_dumpable(cprm.mm_flags)) {
up_write(&mm->mmap_sem);
goto fail_creds;
}
/* /*
* We cannot trust fsuid as being the "true" uid of the * We cannot trust fsuid as being the "true" uid of the
* process nor do we know its entire history. We only know it * process nor do we know its entire history. We only know it
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment