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 534172036E9; Fri, 17 Oct 2025 14:56:27 +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=1760712988; cv=none; b=SMUdlBN3x3NehNtj1yBCseatJvZHJ+QRAs0xPWm9FQqanTkXSVcvIYwzrsQw1M70dd7rBThYShfH+fisiOpZAXZopJbn13b8gQTs3RrUpKQ38rnNzBz8DBHe1jOljMDgsm68Ea8gojxXkVYsyt8AldXDUv0Q998jZoRNPeerw48= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760712988; c=relaxed/simple; bh=2+YBKuuvlla75+G566nnl83BDJkpPFD/VX/D7iwUgls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PF7PO2QwU0MFxW+KS1T6u6WxMvw0sBL2XTrwRQec8N1T2VW8NXtuPD/NZyXcAmNqLxa8HktGxcXHbSholmnb+LCojNdt40jexPVcxksJ3iVfn4jhcB6DoaBb6UH4FRVL23PbL58X4gXbHbzWwnO8H7pNdgY6kOWD5qqG8e0OP+Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hrHxkV/Q; 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="hrHxkV/Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 613A9C4CEFE; Fri, 17 Oct 2025 14:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760712987; bh=2+YBKuuvlla75+G566nnl83BDJkpPFD/VX/D7iwUgls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hrHxkV/QRtwd9Crlr/BdN9WntRJVlu9osZqFbiPHbHp5pwPmG74WFGPYFgIkHAb9v AJxZHyCuyfBCzSZygvi3RWr5Aw2J/RSWFuoqG2tM83p/RU5MrULfo8eBqkkf9sJb/E j5FEtIIEBs3wjHm/QPQsGR+/wSOCGpuUm9oCKO1o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Al Viro , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Christian Brauner Subject: [PATCH 6.1 001/168] fs: always return zero on success from replace_fd() Date: Fri, 17 Oct 2025 16:51:20 +0200 Message-ID: <20251017145129.057771056@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251017145129.000176255@linuxfoundation.org> References: <20251017145129.000176255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Weißschuh commit 708c04a5c2b78e22f56e2350de41feba74dfccd9 upstream. replace_fd() returns the number of the new file descriptor through the return value of do_dup2(). However its callers never care about the specific returned number. In fact the caller in receive_fd_replace() treats any non-zero return value as an error and therefore never calls __receive_sock() for most file descriptors, which is a bug. To fix the bug in receive_fd_replace() and to avoid the same issue happening in future callers, signal success through a plain zero. Suggested-by: Al Viro Link: https://lore.kernel.org/lkml/20250801220215.GS222315@ZenIV/ Fixes: 173817151b15 ("fs: Expand __receive_fd() to accept existing fd") Fixes: 42eb0d54c08a ("fs: split receive_fd_replace from __receive_fd") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh Link: https://lore.kernel.org/20250805-fix-receive_fd_replace-v3-1-b72ba8b34bac@linutronix.de Signed-off-by: Christian Brauner Signed-off-by: Greg Kroah-Hartman --- fs/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/file.c +++ b/fs/file.c @@ -1136,7 +1136,10 @@ int replace_fd(unsigned fd, struct file err = expand_files(files, fd); if (unlikely(err < 0)) goto out_unlock; - return do_dup2(files, file, fd, flags); + err = do_dup2(files, file, fd, flags); + if (err < 0) + return err; + return 0; out_unlock: spin_unlock(&files->file_lock);