]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
coredump: fix error handling for replace_fd()
authorChristian Brauner <brauner@kernel.org>
Mon, 14 Apr 2025 13:55:06 +0000 (15:55 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 2 May 2025 12:28:46 +0000 (14:28 +0200)
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>
fs/coredump.c

index c33c177a701b3daa5b9ddb91a1aacc94b4179d1c..9da592aa8f1623a8d1d132c2724ea067578f0ae5 100644 (file)
@@ -507,7 +507,9 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
 {
        struct file *files[2];
        struct coredump_params *cp = (struct coredump_params *)info->data;
-       int err = create_pipe_files(files, 0);
+       int err;
+
+       err = create_pipe_files(files, 0);
        if (err)
                return err;
 
@@ -515,10 +517,13 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
 
        err = replace_fd(0, files[0], 0);
        fput(files[0]);
+       if (err < 0)
+               return err;
+
        /* and disallow core files too */
        current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
 
-       return err;
+       return 0;
 }
 
 void do_coredump(const kernel_siginfo_t *siginfo)