Skip to content

Commit

Permalink
coredump: factor out put_cred() calls
Browse files Browse the repository at this point in the history
Given that do_coredump() calls put_cred() on exit path, it is a bit ugly
to do put_cred() + "goto fail" twice, just add the new "fail_creds" label.

Signed-off-by: Oleg Nesterov <[email protected]>
Cc: David Howells <[email protected]>
Cc: Neil Horman <[email protected]>
Cc: Roland McGrath <[email protected]>
Cc: Andi Kleen <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed May 27, 2010
1 parent d5bf4c4 commit 5e43aef
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,19 +1862,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
goto fail;

cred = prepare_creds();
if (!cred) {
retval = -ENOMEM;
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);
put_cred(cred);
goto fail;
goto fail_creds;
}

/*
Expand All @@ -1889,10 +1886,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
}

retval = coredump_wait(exit_code, &core_state);
if (retval < 0) {
put_cred(cred);
goto fail;
}
if (retval < 0)
goto fail_creds;

old_cred = override_creds(cred);

Expand Down Expand Up @@ -2009,9 +2004,10 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
if (ispipe)
atomic_dec(&core_dump_count);
fail_unlock:
coredump_finish(mm);
revert_creds(old_cred);
fail_creds:
put_cred(cred);
coredump_finish(mm);
fail:
return;
}

0 comments on commit 5e43aef

Please sign in to comment.