Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1291357ybz; Wed, 22 Apr 2020 17:47:52 -0700 (PDT) X-Google-Smtp-Source: APiQypIdsAM7WsfBW/LFwU3h12erxzKKCOsqrK/ONGZTzLnHKSVnn9R4W0ZLQ8X7qglLzA92IYKs X-Received: by 2002:a17:906:7c4e:: with SMTP id g14mr728344ejp.382.1587602872481; Wed, 22 Apr 2020 17:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587602872; cv=none; d=google.com; s=arc-20160816; b=UZ5NW+6WnKU+01nJjopKC4iwqv5pu9D1Pu5ZEAZ9NZeakbAgxgok1YbDqFRotruOSC KteKKMOzEuRc3xXxjgbCl0N58VGBA2S1U+upBHlu3dO6F3oGEY41oGg9jwr2mGWgej6k z/VSXAJ9cDYY28Xf/EBPRMuPCUGRzchyKgvbHQcQdg1RqikCjjUAjKWlZNFUiIbrWQa3 Z6DyxgfkL25nIZohPhDZf5hoT+90L8v1PtshkvPH2sepO1jDKLAnZ03JhT5sGhrcQxJc k/NZRbUEE/tP36DM/Y2aQ2TlMTkhUcJh9yTYWr/tXCBAgLAdCL9cO/gcABinwjFFP8XC ZCiw== 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=+uUF2To3ld4KiKZsqWYjGL1qmFrcvxdkA+VvqJ6dwGE=; b=H6EhQwY8/0eCCJ4C9b+wF6gg3h0kAXGQcQJ4cmA6GcTtIX3ZOeyNEWZF275ycmJGZ5 8YmNGfiLLIGhR1OshXoNJPzAtwns3S0rMS2dIqYT4KNQFV9tf23OhDHqFy/PI8nTR/7+ Eo7QJboxXLDs1kp+zbGkOE5zUec6KriNuuPlXjd0B5D1NkZYjTPTzKdqgJjrIGU5NgGU fuBcWLvnDecbIWli5DnhJ6IcC4qi39+W9roKgWaAowupKWa72J99iCaJcrtRTgNdUlyv 93GyvcOHnY8ua/97IQ0GU1b0/AWDV/bgUpD2dLOqe5p1hZ2wcAMQjaBh3o2GlCvju2c0 agZg== 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 h4si384974edz.258.2020.04.22.17.47.27; Wed, 22 Apr 2020 17:47:52 -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 S1726343AbgDWAoT (ORCPT + 99 others); Wed, 22 Apr 2020 20:44:19 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:48805 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725846AbgDWAoS (ORCPT ); Wed, 22 Apr 2020 20:44:18 -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 40A4B100002; Thu, 23 Apr 2020 00:44:10 +0000 (UTC) Date: Wed, 22 Apr 2020 17:44:07 -0700 From: Josh Triplett To: Florian Weimer Cc: Mark Wielaard , io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mtk.manpages@gmail.com, Alexander Viro , Arnd Bergmann , Jens Axboe , Aleksa Sarai , linux-man@vger.kernel.org Subject: Re: [PATCH v5 3/3] fs: pipe2: Support O_SPECIFIC_FD Message-ID: <20200423004407.GB161058@localhost> References: <2bb2e92c688b97247f644fe8220054d6c6b66b65.1587531463.git.josh@joshtriplett.org> <877dy7ikyh.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <877dy7ikyh.fsf@mid.deneb.enyo.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 22, 2020 at 05:44:38PM +0200, Florian Weimer wrote: > * Josh Triplett: > > 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)))) { > > Mark, I think this will need (or at least benefit from) some valgrind > changes. Yes, this makes pipe2 read the memory of its first argument from userspace, if and only if its second argument contains the O_SPECIFIC_FD flag. - Josh Triplett