Skip to content

Commit 907c49a

Browse files
committed
coredump: fix error handling for replace_fd()
JIRA: https://issues.redhat.com/browse/RHEL-107520 commit 95c5f43 Author: Christian Brauner <brauner@kernel.org> Date: Mon, 14 Apr 2025 15:55:06 +0200 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/20250414-work-coredump-v2-2-685bf231f828@kernel.org Tested-by: Luca Boccassi <luca.boccassi@gmail.com> Reviewed-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent 819af73 commit 907c49a

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
@@ -501,18 +501,23 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
501501
{
502502
struct file *files[2];
503503
struct coredump_params *cp = (struct coredump_params *)info->data;
504-
int err = create_pipe_files(files, 0);
504+
int err;
505+
506+
err = create_pipe_files(files, 0);
505507
if (err)
506508
return err;
507509

508510
cp->file = files[1];
509511

510512
err = replace_fd(0, files[0], 0);
511513
fput(files[0]);
514+
if (err < 0)
515+
return err;
516+
512517
/* and disallow core files too */
513518
current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
514519

515-
return err;
520+
return 0;
516521
}
517522

518523
void do_coredump(const kernel_siginfo_t *siginfo)

0 commit comments

Comments
 (0)