From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bombadil.infradead.org ([198.137.202.133]:59148 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727511AbeLMRNR (ORCPT ); Thu, 13 Dec 2018 12:13:17 -0500 Date: Thu, 13 Dec 2018 09:13:10 -0800 From: Matthew Wilcox To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , linux-kernel@vger.kernel.org, Al Viro , James Morris , Jonathan Corbet , Kees Cook , Matthew Garrett , Michael Kerrisk , Mimi Zohar , Philippe =?iso-8859-1?Q?Tr=E9buchet?= , Shuah Khan , Thibaut Sautereau , Vincent Strubel , Yves-Alexis Perez , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [RFC PATCH v1 0/5] Add support for O_MAYEXEC Message-ID: <20181213171310.GR6830@bombadil.infradead.org> References: <20181212081712.32347-1-mic@digikod.net> <20181213030228.GM6830@bombadil.infradead.org> <374ea88c-edc5-f1a6-3637-748635e1e7df@ssi.gouv.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <374ea88c-edc5-f1a6-3637-748635e1e7df@ssi.gouv.fr> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Thu, Dec 13, 2018 at 04:17:29PM +0100, Micka�l Sala�n wrote: > On 13/12/2018 04:02, Matthew Wilcox wrote: > > On Wed, Dec 12, 2018 at 09:17:07AM +0100, Micka�l Sala�n wrote: > >> The goal of this patch series is to control script interpretation. A > >> new O_MAYEXEC flag used by sys_open() is added to enable userland script > >> interpreter to delegate to the kernel (and thus the system security > >> policy) the permission to interpret scripts or other files containing > >> what can be seen as commands. > > > > I don't have a problem with the concept, but we're running low on O_ bits. > > Does this have to be done before the process gets a file descriptor, > > or could we have a new syscall? Since we're going to be changing the > > interpreters anyway, it doesn't seem like too much of an imposition to > > ask them to use: > > > > int verify_for_exec(int fd) > > > > instead of adding an O_MAYEXEC. > > Adding a new syscall for this simple use case seems excessive. I think We have somewhat less than 400 syscalls today. We have 20 O_ bits defined. Obviously there's a lower practical limit on syscalls, but in principle we could have up to 2^32 syscalls, and there are only 12 O_ bits remaining. > that the open/openat syscall familly are the right place to do an atomic > open and permission check, the same way the kernel does for other file > access. Moreover, it will be easier to patch upstream interpreters > without the burden of handling a (new) syscall that may not exist on the > running system, whereas unknown open flags are ignored. Ah, but that's the problem. The interpreter can see an -ENOSYS response and handle it appropriately. If the flag is silently ignored, the interpreter has no idea whether it can do a racy check or whether to skip even trying to do the check.