Skip to content

Commit fc7846a

Browse files
braunergregkh
authored andcommitted
coredump: fix error handling for replace_fd()
commit 95c5f43181fe9c1b5e5a4bd3281c857a5259991f upstream. The replace_fd() helper returns the file descriptor number on success and a negative error code on failure. The current error handling in umh_pipe_setup() only works because the file descriptor that is replaced is zero but that's pretty volatile. Explicitly check for a negative error code. Link: https://lore.kernel.org/[email protected] Tested-by: Luca Boccassi <[email protected]> Reviewed-by: Oleg Nesterov <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3939280 commit fc7846a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/coredump.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,18 +493,23 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
493493
{
494494
struct file *files[2];
495495
struct coredump_params *cp = (struct coredump_params *)info->data;
496-
int err = create_pipe_files(files, 0);
496+
int err;
497+
498+
err = create_pipe_files(files, 0);
497499
if (err)
498500
return err;
499501

500502
cp->file = files[1];
501503

502504
err = replace_fd(0, files[0], 0);
503505
fput(files[0]);
506+
if (err < 0)
507+
return err;
508+
504509
/* and disallow core files too */
505510
current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
506511

507-
return err;
512+
return 0;
508513
}
509514

510515
void do_coredump(const kernel_siginfo_t *siginfo)

0 commit comments

Comments
 (0)