Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp249821pxa; Tue, 11 Aug 2020 01:51:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxCv7Ow9scqjO0UzkA/euaRf+1LGQ+kAkc/hjlCho0EFZWOzHa8SvqJ6lPnwh6xROebvYO X-Received: by 2002:a17:906:4994:: with SMTP id p20mr23743782eju.299.1597135871330; Tue, 11 Aug 2020 01:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597135871; cv=none; d=google.com; s=arc-20160816; b=xHEgREc5Jhqu9/0qw8Bv2/qfmHSvlNdcr+s1WxuHDDyPwjJqrM5IEfqCZRMBNRpB/G VZLZhCY1hbGPakUNlrRBz4z1/gLPPq5ZnDwEMX4IPnEj7Qc5DYlV6pjVQx/SJwczDfKC MoHS41Vo2xnO4nJIEmkoMh9OYq1gE1nP32jmK6NAdRrHP4mIW2pZf/cN//SNHvGLKOOE t29ktFMo+kWmJ1NPpjYanG9yviYXL7aF5RFJepepgIB8RS94/OriYwfS604BeSRZSO4x ZvU7MZFeC8sMfmvVkZ6ZETkWFjBxDMFvXb6Xuxy4I4bP5SdALf71W3vwJHTmy1sKDmJY hFCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=OFNSt55TkEqCBrt9xnaQlk8eh91bY1wMxcZXVB8gwI4=; b=e9+tUvMY2cZXwaDLTkwsQ1G77r6bhA79q8WkxMabHi/UPW2LQUvargfrsfXZ1I38dm aq5D7EVQBr0L5uVYw8C3IXCFhTU6B83Jng6KFLHjROUbhmE2lBfbVpiaGnvEA58Dv6Kw j76BMGXdKV3hqmZfnj/PWirRLEkR8vdHN20LD3N/g+rgK0ZcAbs1FuyoARzhcZb1G17l 3F24jIYR2LhwWkb0gU+6Hdq0lDCYw0UQ3hWOus1B2jPSL5zklyR8KBSFd4fiDvngADj1 9BwVYMNUFwRnlSghef3x967gQ6oA0WAfmUmn4Olk3EVRqbeIGL4O8R0AxokyBOU/3ob7 0YFA== 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 r8si12014138ejs.214.2020.08.11.01.50.48; Tue, 11 Aug 2020 01:51:11 -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 S1728411AbgHKIt2 (ORCPT + 99 others); Tue, 11 Aug 2020 04:49:28 -0400 Received: from smtp-190a.mail.infomaniak.ch ([185.125.25.10]:53099 "EHLO smtp-190a.mail.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728345AbgHKIt1 (ORCPT ); Tue, 11 Aug 2020 04:49:27 -0400 Received: from smtp-2-0000.mail.infomaniak.ch (unknown [10.5.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4BQmjL1hcRzlhjP4; Tue, 11 Aug 2020 10:49:26 +0200 (CEST) Received: from ns3096276.ip-94-23-54.eu (unknown [94.23.54.103]) by smtp-2-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4BQmjJ5QnQzlh8Tj; Tue, 11 Aug 2020 10:49:24 +0200 (CEST) Subject: Re: [PATCH v7 0/7] Add support for O_MAYEXEC To: Al Viro Cc: Kees Cook , Andrew Morton , linux-kernel@vger.kernel.org, Aleksa Sarai , Alexei Starovoitov , Andy Lutomirski , Christian Brauner , Christian Heimes , Daniel Borkmann , Deven Bowers , Dmitry Vyukov , Eric Biggers , Eric Chiang , Florian Weimer , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Lakshmi Ramasubramanian , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , Mimi Zohar , =?UTF-8?Q?Philippe_Tr=c3=a9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , Tetsuo Handa , Thibaut Sautereau , Vincent Strubel , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org References: <20200723171227.446711-1-mic@digikod.net> <202007241205.751EBE7@keescook> <0733fbed-cc73-027b-13c7-c368c2d67fb3@digikod.net> <20200810202123.GC1236603@ZenIV.linux.org.uk> <917bb071-8b1a-3ba4-dc16-f8d7b4cc849f@digikod.net> <20200810230521.GG1236603@ZenIV.linux.org.uk> From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Message-ID: Date: Tue, 11 Aug 2020 10:49:24 +0200 User-Agent: MIME-Version: 1.0 In-Reply-To: <20200810230521.GG1236603@ZenIV.linux.org.uk> Content-Type: text/plain; charset=iso-8859-15 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Antivirus: Dr.Web (R) for Unix mail servers drweb plugin ver.6.0.2.8 X-Antivirus-Code: 0x100000 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/08/2020 01:05, Al Viro wrote: > On Tue, Aug 11, 2020 at 12:43:52AM +0200, Micka?l Sala?n wrote: > >> Hooking on open is a simple design that enables processes to check files >> they intend to open, before they open them. > > Which is a good thing, because...? > >> From an API point of view, >> this series extends openat2(2) with one simple flag: O_MAYEXEC. The >> enforcement is then subject to the system policy (e.g. mount points, >> file access rights, IMA, etc.). > > That's what "unspecified" means - as far as the kernel concerned, it's > "something completely opaque, will let these hooks to play, semantics is > entirely up to them". I see it as an access controls mechanism; access may be granted or denied, as for O_RDONLY, O_WRONLY or (non-Linux) O_EXEC. Even for common access controls, there are capabilities to bypass them (i.e. CAP_DAC_OVERRIDE), but multiple layers may enforce different complementary policies. > >> Checking on open enables to not open a file if it does not meet some >> requirements, the same way as if the path doesn't exist or (for whatever >> reasons, including execution permission) if access is denied. It is a >> good practice to check as soon as possible such properties, and it may >> enables to avoid (user space) time-of-check to time-of-use (TOCTOU) >> attacks (i.e. misuse of already open resources). > > ????? You explicitly assume a cooperating caller. As said in the below (removed) reply, no, quite the contrary. > If it can't be trusted > to issue the check between open and use, or can be manipulated (ptraced, > etc.) into not doing so, how can you rely upon the flag having been passed > in the first place? And TOCTOU window is definitely not wider that way. OK, I guess it would be considered a bug in the application (e.g. buggy resource management between threads). > > If you want to have it done immediately after open(), bloody well do it > immediately after open. If attacker has subverted your control flow to the > extent that allows them to hit descriptor table in the interval between > these two syscalls, you have already lost - they'll simply prevent that > flag from being passed. > > What's the point of burying it inside openat2()? A convenient multiplexor > to hook into? We already have one - it's called do_syscall_... > To check as soon as possible without opening something that should not be opened in the first place. Isn't a dedicated syscall a bit too much for this feature? What about adding a new command/flag to fcntl(2)?