Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp321044ybb; Tue, 7 Apr 2020 23:59:05 -0700 (PDT) X-Google-Smtp-Source: APiQypIvLrptYASzFLaKu94Fq7L4+STPsSSrpabXm5XHkDgA1H1pQ9Jr5FFcAdH2eZFqRlyyJwd8 X-Received: by 2002:a54:4e13:: with SMTP id a19mr1441567oiy.108.1586329144965; Tue, 07 Apr 2020 23:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586329144; cv=none; d=google.com; s=arc-20160816; b=d8bW6hnIgp8V+5xPizV/cXP8pJDSTthOHI7Vr20Wk8EUlqbfHyr2an0m6KPzgFjCLh kdJqHybrBb/LQ9NLUXn9Zb3N3USDdIn+x/Sb/O9lAC7KYVfjNbEHzhqwvutxAqLMlY38 Qini8FuKHpJyLLJx6n4bTjzrn0z08xCA9vp6ZodrfSu3DA3XLjuhnUyLS36TbeJUtZZj uRTC5wLJb+P7sIVhStE9xS4iQW8eIv/G4JP4Z7uJLEchFBSayn6tcPgqT4sx8ixLE2uy O0kGx5NDMp52zw52sszoMjVVrujVZaDzPFJ+MBuk5FMMG0cL9PlBJcsn0KW9pLnnYi2K /4qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=kQlZ+MQc2tM1T8RGcqrc1dIYwO7bP3xe1PSES/QQOW4=; b=OtEdAL+G3JFCquqaCT+YJpe3a6le8t+TitprM8X4PbjpCMdfafXCLgnNRy6UkE7641 cYgYnkBuB5FWkUsi5+WadaK21A1j3pAZSd/zSq1LZ6pYpEgNrtADQJhVrRY3VjENW9GV Siev61AF4RC84NF1XMUoiMH0zYbHjCvxTxT/dLimCiokx+qWTQ7DCgItEDokr8oCBz92 4qdAgOCJqeuvUMo2KOu5nKVcnx+2aa5PykueJWRjKgC8DPF03DPXG7dxEI1rIOGf/Eo3 5DqTu30WmaWsuW7njaUR+7ZnvbvERP/LrAPg5KlMwNUMvDOAiswDa6wOenV8eEpi5EWM Cs0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n198si2033623oig.37.2020.04.07.23.58.50; Tue, 07 Apr 2020 23:59:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726720AbgDHG5z (ORCPT + 99 others); Wed, 8 Apr 2020 02:57:55 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:35549 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726475AbgDHG5y (ORCPT ); Wed, 8 Apr 2020 02:57:54 -0400 Received: from localhost (50-39-163-217.bvtn.or.frontiernet.net [50.39.163.217]) (Authenticated sender: josh@joshtriplett.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 9F48D200004; Wed, 8 Apr 2020 06:57:49 +0000 (UTC) Date: Tue, 7 Apr 2020 23:57:47 -0700 From: Josh Triplett To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, linux-arch@vger.kernel.org Cc: Alexander Viro , Arnd Bergmann , Jens Axboe Subject: [PATCH v3 3/3] fs: pipe2: Support O_SPECIFIC_FD Message-ID: <4ce301ca8ab8f6fdcc8feb05b4f7c026a203f68a.1586321767.git.josh@joshtriplett.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This allows the caller of pipe2 to specify one or both file descriptors rather than having them automatically use the lowest available file descriptor. The caller can specify either file descriptor as -1 to allow that file descriptor to use the lowest available. Signed-off-by: Josh Triplett --- fs/pipe.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 16fb72e9abf7..4681a0d1d587 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -936,19 +936,19 @@ static int __do_pipe_flags(int *fd, struct file **files, int flags) int error; int fdw, fdr; - if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT)) + if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT | O_SPECIFIC_FD)) return -EINVAL; error = create_pipe_files(files, flags); if (error) return error; - error = get_unused_fd_flags(flags); + error = get_specific_unused_fd_flags(fd[0], flags); if (error < 0) goto err_read_pipe; fdr = error; - error = get_unused_fd_flags(flags); + error = get_specific_unused_fd_flags(fd[1], flags); if (error < 0) goto err_fdr; fdw = error; @@ -969,7 +969,11 @@ static int __do_pipe_flags(int *fd, struct file **files, int flags) int do_pipe_flags(int *fd, int flags) { struct file *files[2]; - int error = __do_pipe_flags(fd, files, flags); + int error; + + if (flags & O_SPECIFIC_FD) + return -EINVAL; + error = __do_pipe_flags(fd, files, flags); if (!error) { fd_install(fd[0], files[0]); fd_install(fd[1], files[1]); @@ -987,6 +991,10 @@ static int do_pipe2(int __user *fildes, int flags) int fd[2]; int error; + if (flags & O_SPECIFIC_FD) + if (copy_from_user(fd, fildes, sizeof(fd))) + return -EFAULT; + error = __do_pipe_flags(fd, files, flags); if (!error) { if (unlikely(copy_to_user(fildes, fd, sizeof(fd)))) { -- 2.26.0