Prev: [PATCH 2/4] coredump: cleanup "ispipe" code
Next: [PATCH 3/4] coredump: factor out put_cred() calls
From: Oleg Nesterov on 16 Mar 2010 15:50 - 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: Oleg Nesterov <oleg(a)redhat.com> --- fs/exec.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) --- 34-rc1/fs/exec.c~4_MMAP_SEM 2010-03-16 19:09:50.000000000 +0100 +++ 34-rc1/fs/exec.c 2010-03-16 19:28:23.000000000 +0100 @@ -1659,12 +1659,15 @@ static int coredump_wait(int exit_code, struct task_struct *tsk = current; struct mm_struct *mm = tsk->mm; struct completion *vfork_done; - int core_waiters; + int core_waiters = -EBUSY; init_completion(&core_state->startup); core_state->dumper.task = tsk; core_state->dumper.next = NULL; - core_waiters = zap_threads(tsk, mm, core_state, exit_code); + + down_write(&mm->mmap_sem); + if (!mm->core_state) + core_waiters = zap_threads(tsk, mm, core_state, exit_code); up_write(&mm->mmap_sem); if (unlikely(core_waiters < 0)) @@ -1857,20 +1860,12 @@ void do_coredump(long signr, int exit_co binfmt = mm->binfmt; if (!binfmt || !binfmt->core_dump) goto fail; + if (!__get_dumpable(cprm.mm_flags)) + goto fail; cred = prepare_creds(); if (!cred) 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 * process nor do we know its entire history. We only know it -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
|
Pages: 1 Prev: [PATCH 2/4] coredump: cleanup "ispipe" code Next: [PATCH 3/4] coredump: factor out put_cred() calls |