[PATCH 2/2] do_coredump: move !ispipe code into "else" branch

From: Oleg Nesterov
Date: Fri Jun 26 2009 - 18:31:02 EST


do_coredump() does a lot of file checks which are only needed when !ispipe,
move them into "else" branch.

Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>

--- WAIT/fs/exec.c~CD_2_ISPIPE 2009-06-26 20:06:01.000000000 +0200
+++ WAIT/fs/exec.c 2009-06-26 20:59:57.000000000 +0200
@@ -1784,9 +1784,6 @@ void do_coredump(long signr, int exit_co
* at which point file size limits and permissions will be imposed
* as it does with any other process
*/
- if ((!ispipe) && (core_limit < binfmt->min_coredump))
- goto fail_unlock;
-
if (ispipe) {
helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc);
if (!helper_argv) {
@@ -1818,39 +1815,43 @@ void do_coredump(long signr, int exit_co
corename);
goto fail_unlock;
}
- } else
+ } else {
+ if (core_limit < binfmt->min_coredump)
+ goto fail_unlock;
+
file = filp_open(corename,
O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
0600);
- if (IS_ERR(file))
- goto fail_unlock;
- inode = file->f_path.dentry->d_inode;
- if (inode->i_nlink > 1)
- goto close_fail; /* multiple links - don't dump */
- if (!ispipe && d_unhashed(file->f_path.dentry))
- goto close_fail;
+ if (IS_ERR(file))
+ goto fail_unlock;

- /* AK: actually i see no reason to not allow this for named pipes etc.,
- but keep the previous behaviour for now. */
- if (!ispipe && !S_ISREG(inode->i_mode))
- goto close_fail;
- /*
- * Dont allow local users get cute and trick others to coredump
- * into their pre-created files:
- */
- if (inode->i_uid != current_fsuid())
- goto close_fail;
- if (!file->f_op)
- goto close_fail;
- if (!file->f_op->write)
- goto close_fail;
- if (!ispipe && do_truncate(file->f_path.dentry, 0, 0, file) != 0)
- goto close_fail;
+ if (d_unhashed(file->f_path.dentry))
+ goto close_fail;
+ inode = file->f_path.dentry->d_inode;
+ if (inode->i_nlink > 1)
+ goto close_fail; /* multiple links - don't dump */
+ /* AK: actually i see no reason to not allow this for named
+ pipes etc, but keep the previous behaviour for now. */
+ if (!S_ISREG(inode->i_mode))
+ goto close_fail;
+ /*
+ * Dont allow local users get cute and trick others to coredump
+ * into their pre-created files:
+ */
+ if (inode->i_uid != current_fsuid())
+ goto close_fail;
+ if (!file->f_op)
+ goto close_fail;
+ if (!file->f_op->write)
+ goto close_fail;
+ if (do_truncate(file->f_path.dentry, 0, 0, file) != 0)
+ goto close_fail;
+ }

retval = binfmt->core_dump(signr, regs, file, core_limit);
-
if (retval)
current->signal->group_exit_code |= 0x80;
+
close_fail:
filp_close(file, NULL);
fail_unlock:

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/