From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86DA322A7F1; Mon, 2 Jun 2025 14:50:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875853; cv=none; b=NR0QsLcRYBRG5cKGhlA+HVuU5KoN/pRczrENpJYLfR4/fIZ4uwyhPkHFUS55uMwUzeJ3OSc67Zy/ofhm772AtZBRh/rilTcnSZ83j74gth4QOzwKWcBfK3JzIdl1NQ5zTnD+9cqaJkB37ZFeSAalL0d8bkMZ8+68vPcbQqIuqMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875853; c=relaxed/simple; bh=Y+MQ63rIJ+Fw2Flpb2vxLe6M2i9iPIj+VYA2kYIW7DY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XH2w0JEAYOlYutsZOBRd4YIdzZ/j6FMzJHIDjU01OWscCLn7mqGwt0RJ+jYvJ7/BvJ1XgtZhyBQSf63FpX3CdukYdVY0kJPFRVdHMNItePaygf1/9trE96pp+f2hFORU9ribwUaEsl2lKUA+tCHd18S52j3157rCx64zuznMDCc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=uDJpFcFN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="uDJpFcFN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA240C4CEEB; Mon, 2 Jun 2025 14:50:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748875853; bh=Y+MQ63rIJ+Fw2Flpb2vxLe6M2i9iPIj+VYA2kYIW7DY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uDJpFcFNlvsfu6F44we8nZr183rxnTy3HgxYqUMQiEpJPpP1THz+h3SK8uygMuoGm +SwEauXxS7jVHDXoVvDpZuWPzB8cEMuDGb+ZrcjlXjPMGdya6e5tN6SMZ/9fdic+Be lZ908ot07gsoCaYsUvLUGaGkUFetj1tu/M0poB0A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Luca Boccassi , Oleg Nesterov , Christian Brauner Subject: [PATCH 5.10 257/270] coredump: fix error handling for replace_fd() Date: Mon, 2 Jun 2025 15:49:02 +0200 Message-ID: <20250602134317.842297154@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250602134307.195171844@linuxfoundation.org> References: <20250602134307.195171844@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Brauner 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/20250414-work-coredump-v2-2-685bf231f828@kernel.org Tested-by: Luca Boccassi Reviewed-by: Oleg Nesterov Signed-off-by: Christian Brauner Signed-off-by: Greg Kroah-Hartman --- fs/coredump.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/fs/coredump.c +++ b/fs/coredump.c @@ -564,7 +564,9 @@ static int umh_pipe_setup(struct subproc { 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; @@ -572,10 +574,13 @@ static int umh_pipe_setup(struct subproc 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)