Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1232502ybb; Wed, 8 Apr 2020 20:18:06 -0700 (PDT) X-Google-Smtp-Source: APiQypITOHzSKyMB8Blds8YxN4FFniPJUcoON6bs565KBCqOuOuyR8rM88AxUnM2bT0aiN5HusNq X-Received: by 2002:a9d:5a9:: with SMTP id 38mr7453749otd.331.1586402286513; Wed, 08 Apr 2020 20:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586402286; cv=none; d=google.com; s=arc-20160816; b=vaSWNB9JFYV19uJWAjnhmO4hEABXbmoF444oHGtmgZDFjSrJWMenpqH8i40JTOG/qB CoF5QtQA/1XAbTPJNsU/bT29Ein7lqlqWsTngdyf/qGxXoRGt5wOtfcPxH66BnDTg2Jb 674kLZGfRwIWvEuSBcryc+hrocjhvk+9tF3QKOf1aaoX1ZiJ1IG3r+oyT8sAKdFc4++O RyKMWO4eSA7AieL15/7x0y9DvymAMBo0i/7LkXycOc3gJGElLkTwbl2MZC8xSnTJA558 l+9aVWSDmbFaWKhEmyPvMx+a1f5ykE2b8Ap+4PYXnenPjMASPROIt/3izI17HYBR28PA EYKw== 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=x9BMuJ+3eBrBKUFQG2UD9I/Y4zx6oHx0ZcuTl4dZ4Tw=; b=VH/wUujnCGKUq8V2wZIT9jayAYQV6cHqU6VueeWTCqDy9e/xNX0DkP36ZMsVAvNbvv 1BKr7M9i1wSNgnd1ArweXg1AmMf8nJ3mlSlM4iTLe6Uy8Flz+MhXxaZ3GdbH1iyKoDaa XhoYwi0+vnw65qVLJ0x+0k2LjXipJPwX/fKtDN+/8mnC5IPGLqdwYCVOGZCJJbZian+Q mWqOmGhoEeCEHI0aiICL5x9qlpYLLWFWwka/hZm0+KcB+g/onrGeuhRab4c+8pmALAl2 /T0rSPQPG/+oNcGhM1en9XfLT7jCqbNwhhpTkiSPol2E34RPK5GrBeo8ASXayU3Of4YB O6Vw== 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 y4si3300815ooh.53.2020.04.08.20.17.52; Wed, 08 Apr 2020 20:18:06 -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 S1726621AbgDIDRR (ORCPT + 99 others); Wed, 8 Apr 2020 23:17:17 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:45873 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726534AbgDIDRR (ORCPT ); Wed, 8 Apr 2020 23:17:17 -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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id A55BDFF806; Thu, 9 Apr 2020 03:17:11 +0000 (UTC) Date: Wed, 8 Apr 2020 20:17:08 -0700 From: Josh Triplett To: Aleksa Sarai Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, linux-arch@vger.kernel.org, Alexander Viro , Arnd Bergmann , Jens Axboe Subject: Re: [PATCH v3 1/3] fs: Support setting a minimum fd for "lowest available fd" allocation Message-ID: <20200409031708.GC6149@localhost> References: <90bf6fd43343ca862e7f61b0834baf2bdbd0e24c.1586321767.git.josh@joshtriplett.org> <20200408120040.mtkqmymfazrv3lqk@yavin.dot.cyphar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200408120040.mtkqmymfazrv3lqk@yavin.dot.cyphar.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 08, 2020 at 10:00:40PM +1000, Aleksa Sarai wrote: > On 2020-04-07, Josh Triplett wrote: > > Some applications want to prevent the usual "lowest available fd" > > allocation from allocating certain file descriptors. For instance, they > > may want to prevent allocation of a closed fd 0, 1, or 2 other than via > > dup2/dup3, or reserve some low file descriptors for other purposes. > > > > Add a prctl to increase the minimum fd and return the previous minimum. > > > > System calls that allocate a specific file descriptor, such as > > dup2/dup3, ignore this minimum. > > > > exec resets the minimum fd, to prevent one program from interfering with > > another program's expectations about fd allocation. > > Why is it implemented as an "increase the value" interface? It feels > like this is meant to avoid some kind of security trap (with a library > reducing the value) but it means that if you want to temporarily raise > the minimum fd number it's not possible (without re-exec()ing yourself, > which is hardly a fun thing to do). > > Then again, this might've been discussed before and I missed it... It was: the previous version was a "get" and "set" interface. That interface didn't allow for the possibility that something else in the process had already set a minimum. This new atomic increase interface (which also serves as a "get" interface if you pass 0) makes it possible for a userspace library to reserve a range. (You have no guarantee about previously allocated descriptors in that range, but you know that no *new* automatically allocated descriptors will appear in that range, which suffices; userspace can do the rest.) - Josh Triplett