Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp232495ybb; Tue, 14 Apr 2020 23:51:36 -0700 (PDT) X-Google-Smtp-Source: APiQypJ0aqXDYXXkoCm2FfD1qSz+H5M9weblUdhuZ6YXsZO+FNGhKfye7WdG+j7fGFlFKLa/pkj1 X-Received: by 2002:a17:906:57d7:: with SMTP id u23mr1990220ejr.354.1586933496110; Tue, 14 Apr 2020 23:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586933496; cv=none; d=google.com; s=arc-20160816; b=04/cV/a74WVMHUza8PjUORKmx8I2is6SkN5zqnFRvgbg99X0vF4KcJzUCaNHQFiO9V isM++HTNt2Ra9mlurW41Qcbt8NPVNn04X9jsys8smMB3PPf8YT0PT47EkeZXVzkMBOJP iGlS4tD64+nnXtke49IG/m0mecLZlfYeDesq2XF8OtDFKrF/rTa1ohK1iHOpiAb7Wxt6 49+6qsfW7GqBmTtLssPHElvXGje7gj7iDNLIdGUHLIuhA4Uf7UVW58IRn7XumYRHq7PF d/jn9BtJ67IY3TgYE87pfoShAevNoByoerkldOw1GLcNHmMWLYehtbVl3dgzt3Expa/b cz1Q== 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=e/4hepSuU5NWdw1FHlIC9UiDVQveVOalirUwzGoG/v3Kfdx1XUu32jp9kT2xyP+Wx0 ywivEK3Xi03EZmKxOBN0UNHzsGA32o3d+NV3VntRVCBk/m7ooVss3OqVyYtDY5+xbeq0 IexgOel4LkRgMbQwZsfNOSqRSk6U2weF4r65vQgpRWSblS9CsT4ADtI9OUwui/AJpR5m YBjyfcxwEiZELI0wwm4mirn2QGfNfY9zoIacN/0+SYrPUKyw/xHWDqVKJUbsxfo34BLV QNWDs4KKX5HhgFhVPsiN0JpjRusriKW2+0sdjen66w2T3Z7x7vLHBMttX7KOGANK5md/ LSaA== 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 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 w20si1373682ejq.91.2020.04.14.23.51.12; Tue, 14 Apr 2020 23:51:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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: best guess record for 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 S2404062AbgDNCQN (ORCPT + 99 others); Mon, 13 Apr 2020 22:16:13 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:42909 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404055AbgDNCQI (ORCPT ); Mon, 13 Apr 2020 22:16:08 -0400 X-Originating-IP: 50.39.163.217 Received: from localhost (50-39-163-217.bvtn.or.frontiernet.net [50.39.163.217]) (Authenticated sender: josh@joshtriplett.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 8FC94240002; Tue, 14 Apr 2020 02:16:03 +0000 (UTC) Date: Mon, 13 Apr 2020 19:16:01 -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 , Aleksa Sarai Subject: [PATCH v4 3/3] fs: pipe2: Support O_SPECIFIC_FD Message-ID: <2993aae005b70f51636553d1522baa063ea01a26.1586830316.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