public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: "Oleg Nesterov" <oleg@redhat.com>,
	"Luca Boccassi" <luca.boccassi@gmail.com>,
	"Lennart Poettering" <lennart@poettering.net>,
	"Daan De Meyer" <daan.j.demeyer@gmail.com>,
	"Mike Yuan" <me@yhndnzj.com>,
	"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>,
	linux-kernel@vger.kernel.org,
	"Christian Brauner" <brauner@kernel.org>
Subject: [PATCH 2/3] coredump: fix error handling for replace_fd()
Date: Mon, 14 Apr 2025 11:53:37 +0200	[thread overview]
Message-ID: <20250414-work-coredump-v1-2-6caebc807ff4@kernel.org> (raw)
In-Reply-To: <20250414-work-coredump-v1-0-6caebc807ff4@kernel.org>

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.

Tested-by: Luca Boccassi <luca.boccassi@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/coredump.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index c33c177a701b..2ed5e6956a09 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -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,6 +517,9 @@ 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};
 

-- 
2.47.2


  parent reply	other threads:[~2025-04-14  9:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-14  9:53 [PATCH 0/3] coredump: hand a pidfd to the usermode coredump helper Christian Brauner
2025-04-14  9:53 ` [PATCH 1/3] pidfs: move O_RDWR into pidfs_alloc_file() Christian Brauner
2025-04-14  9:53 ` Christian Brauner [this message]
2025-04-14 12:11   ` [PATCH 2/3] coredump: fix error handling for replace_fd() Oleg Nesterov
2025-04-14 13:04     ` Christian Brauner
2025-04-14  9:53 ` [PATCH 3/3] coredump: hand a pidfd to the usermode coredump helper Christian Brauner
2025-04-14 12:48   ` Oleg Nesterov
2025-04-14 13:09     ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250414-work-coredump-v1-2-6caebc807ff4@kernel.org \
    --to=brauner@kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=lennart@poettering.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luca.boccassi@gmail.com \
    --cc=me@yhndnzj.com \
    --cc=oleg@redhat.com \
    --cc=zbyszek@in.waw.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox