Skip to content

Commit 95c5f43

Browse files
committed
coredump: fix error handling for replace_fd()
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]>
1 parent c57f07b commit 95c5f43

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
@@ -507,18 +507,23 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
507507
{
508508
struct file *files[2];
509509
struct coredump_params *cp = (struct coredump_params *)info->data;
510-
int err = create_pipe_files(files, 0);
510+
int err;
511+
512+
err = create_pipe_files(files, 0);
511513
if (err)
512514
return err;
513515

514516
cp->file = files[1];
515517

516518
err = replace_fd(0, files[0], 0);
517519
fput(files[0]);
520+
if (err < 0)
521+
return err;
522+
518523
/* and disallow core files too */
519524
current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
520525

521-
return err;
526+
return 0;
522527
}
523528

524529
void do_coredump(const kernel_siginfo_t *siginfo)

0 commit comments

Comments
 (0)