Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Oleg 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Oleg Nesterov and committed by
Linus Torvalds
269b005a 5e43aef5

+7 -12
+7 -12
fs/exec.c
··· 1662 1662 struct task_struct *tsk = current; 1663 1663 struct mm_struct *mm = tsk->mm; 1664 1664 struct completion *vfork_done; 1665 - int core_waiters; 1665 + int core_waiters = -EBUSY; 1666 1666 1667 1667 init_completion(&core_state->startup); 1668 1668 core_state->dumper.task = tsk; 1669 1669 core_state->dumper.next = NULL; 1670 - core_waiters = zap_threads(tsk, mm, core_state, exit_code); 1670 + 1671 + down_write(&mm->mmap_sem); 1672 + if (!mm->core_state) 1673 + core_waiters = zap_threads(tsk, mm, core_state, exit_code); 1671 1674 up_write(&mm->mmap_sem); 1672 1675 1673 1676 if (unlikely(core_waiters < 0)) ··· 1863 1860 binfmt = mm->binfmt; 1864 1861 if (!binfmt || !binfmt->core_dump) 1865 1862 goto fail; 1863 + if (!__get_dumpable(cprm.mm_flags)) 1864 + goto fail; 1866 1865 1867 1866 cred = prepare_creds(); 1868 1867 if (!cred) 1869 1868 goto fail; 1870 - 1871 - down_write(&mm->mmap_sem); 1872 - /* 1873 - * If another thread got here first, or we are not dumpable, bail out. 1874 - */ 1875 - if (mm->core_state || !__get_dumpable(cprm.mm_flags)) { 1876 - up_write(&mm->mmap_sem); 1877 - goto fail_creds; 1878 - } 1879 - 1880 1869 /* 1881 1870 * We cannot trust fsuid as being the "true" uid of the 1882 1871 * process nor do we know its entire history. We only know it