Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp337286ybz; Tue, 21 Apr 2020 22:24:04 -0700 (PDT) X-Google-Smtp-Source: APiQypJMICCJqWMrBE2F+raAceKUaqEluie643hS8gx/CmShiWUDitVsmu5s3ELNu+Lr9GowzfeQ X-Received: by 2002:aa7:d514:: with SMTP id y20mr22193394edq.28.1587533043793; Tue, 21 Apr 2020 22:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587533043; cv=none; d=google.com; s=arc-20160816; b=zF1GFXobj51NDIxF7It780/uIsUG5M2CvyozkyjacLyNN7LMpRgJX3KwkwJq+sWwEg ooQnmZTFZxgJnGw48T9g14zf0Iq2diggHrh/ePtMoQgdk7h5D7lgy+0o8S+O0iojPmG1 TXIBWw5B2nofjqfwoAwczvlJNmqCYmIG8XROElg6vM03UG8YG3gkZmj4Gq/95Vqy6Fg2 FRSgp+Lkfdt7A2qps//R28/iJY5FxPXqFcoiLoGkqJ+nGocjUEbjwp+OkeN5zD1b9ysw igJYmFskg7vvEl4NqdB9CeKTCKOFCnYgS1eELJZD6fXo2dAjshX+9Jq1vQ8ydUDm34O2 LXBQ== 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=xDLn7DHzXBFtNg8+kY+Fp11garWY8AepYt6ZCryZqeQ=; b=WtHmKcwHpZCADXq/lu8DVMzVxod0Kie7alUBE3veZ542yRhkKMypXMBPdG9eZp+4ng D1YyMu61/NWAx0w1C4goVi6z63SA8FsnPimHsgzB2xNwusAIxRVtBx2LDzwuAosD6lai ZFr4k45qD5LGXigLFukKb0xE/cwaA+aWhT19aS2DXnlf5+CFSOfR3F7rbjbcQnfMOyQV 1Eh6Dep+hkEIFJ/LrELJYu5s/fN18zQqfXziZa3x1u+BrZLp1EbgDmiZNPmOjaryNR84 UzLe80n9GN1S+M7AdSLlqgvHcXA3StgS34Ck1sJ7IDqYy5yDbfqrw1LN6jbVffsJVw7M 6lvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y91si2647865edy.285.2020.04.21.22.23.40; Tue, 21 Apr 2020 22:24:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726468AbgDVFUb (ORCPT + 99 others); Wed, 22 Apr 2020 01:20:31 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:48245 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbgDVFUa (ORCPT ); Wed, 22 Apr 2020 01:20:30 -0400 Received: from localhost (50-39-163-217.bvtn.or.frontiernet.net [50.39.163.217]) (Authenticated sender: josh@joshtriplett.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id D539D100004; Wed, 22 Apr 2020 05:20:23 +0000 (UTC) Date: Tue, 21 Apr 2020 22:20:20 -0700 From: Josh Triplett To: io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mtk.manpages@gmail.com Cc: Alexander Viro , Arnd Bergmann , Jens Axboe , Aleksa Sarai , linux-man@vger.kernel.org Subject: [PATCH v5 3/3] fs: pipe2: Support O_SPECIFIC_FD Message-ID: <2bb2e92c688b97247f644fe8220054d6c6b66b65.1587531463.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.2