Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp832891ybz; Wed, 22 Apr 2020 08:46:58 -0700 (PDT) X-Google-Smtp-Source: APiQypKfau6P5S+n6spORTmjntkX8uxf2Xc7gqAp6rYPXFymTHJs+dNQsc/FFnlfgi01jFYB4Wdq X-Received: by 2002:a17:906:bcec:: with SMTP id op12mr26923828ejb.245.1587570418275; Wed, 22 Apr 2020 08:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587570418; cv=none; d=google.com; s=arc-20160816; b=n2q3HGvX64ETLB7Dh5F1DOquTu1Mb0du1ZdZaxb3upCyd2Vp690Sm34k6GPMy+an80 5BgAv8WuAX5nf8tc2ionVfau62nGZpjnCQQEigsrpY8MkYxYtoQc+sfu4NniF+7gGr0C 6WUOnBCZkSHeK5/mj3zBoG6EH0g3gn0of6HTGizuqiqvMV4s3oNb2Zm8U9NLJ6eF1kis TzxfWp+byWdnagUuO54jBAnzZhb3aWQmLt5/6h0cG0yl6ghBSJzzALrkmJDZMZ4YmEt2 2xNVOHnMT4Xfrzv/g9YrYANAcuQP/ZnrtBydcDdAXPFL/MBYQT0sk3Ke+kRKcIun2CjD Q3+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to:date :references:subject:cc:to:from; bh=g1zFp/cDKZQS/1brwCYFEqeQf7in4aLGBLiHb7oYvMo=; b=rKClgaz90ur5K7c6qko9X4OAfOh6sJ//eqM4B8Aoi6v8yTu5lOT1VUwqiUqyEdoyZP 2X/XqD0gTO+JmRmZORxwUEC6+kdmmClQUWIeIG1AhxpfcGzteNERUbaG2FVwRryvAMbG mbUNpKK4zQov6tMZr77nd/sBoC1fugBowtBWHq+FhvCMF4rSvH2VDX1Ky44M23WMo4ZT ls4pfgzsiSgcjcegZHKR453OxMQQT/j68+W4BCkMTv9aUFDiaF3hc0UEgoEt4fx1ydrY /xwdsx+D59iPiTqYxChKuc3WyJfj5vWormfMkrv8/mYm9jimkkpCdSSLvEhr1xUDhGuj I9wA== 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 u26si3214066ejj.44.2020.04.22.08.46.34; Wed, 22 Apr 2020 08:46:58 -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 S1726725AbgDVPop (ORCPT + 99 others); Wed, 22 Apr 2020 11:44:45 -0400 Received: from albireo.enyo.de ([37.24.231.21]:43428 "EHLO albireo.enyo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbgDVPoo (ORCPT ); Wed, 22 Apr 2020 11:44:44 -0400 Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1jRHYE-00031Q-Ug; Wed, 22 Apr 2020 15:44:38 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1jRHYE-0006oS-Ox; Wed, 22 Apr 2020 17:44:38 +0200 From: Florian Weimer To: Mark Wielaard Cc: Josh Triplett , 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 References: <2bb2e92c688b97247f644fe8220054d6c6b66b65.1587531463.git.josh@joshtriplett.org> Date: Wed, 22 Apr 2020 17:44:38 +0200 In-Reply-To: <2bb2e92c688b97247f644fe8220054d6c6b66b65.1587531463.git.josh@joshtriplett.org> (Josh Triplett's message of "Tue, 21 Apr 2020 22:20:20 -0700") Message-ID: <877dy7ikyh.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * 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.