Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4697926pxa; Mon, 10 Aug 2020 16:05:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwV2MXwwjDCotIl7sAP27HVGtacHJAXTqNJnmprk2/46lDa86pLfdixqEQTgFKkS0AfjhvA X-Received: by 2002:a17:906:eca4:: with SMTP id qh4mr23222152ejb.255.1597100754213; Mon, 10 Aug 2020 16:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597100754; cv=none; d=google.com; s=arc-20160816; b=IBnx8rq4HJdpvA98nK4jo+8V2/7iLLcGTrOO+lu6/Dy+0eeSKDhbxZ1qORjd6c4Qfg jw4iAL1wxjwa0t2P5sDdnFn9msUeKGG2WQSy74REta5oAbr7kHMtXkZYMms15b38I2T5 RoakzIAxW2Jf2FEg/41EZwx9SKQzdHCbCgjdbP1PcV8LiEzHggVdB6Wcf4e/co3d7J3C K7lGiVva+M1MvN854aRKs9yge/NqMZA+ya8Kzd2Hq/m9rtf5f0+hPVu3WzmzFyjcjEiY 8u1tt3P+50tFWFivDvvPT4FFa0wrVempTofuZHD5uf8zy3dIwzcKLL2V5PEJrt83QlF5 LtFQ== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=FD4/MDk5WwnURnuc/jZmQ+Kde4ex+xh6Ky7vtljOMA4=; b=m1je7kyLJwkfXsPXEquI+XNN8v2VIix4UJoQz2Dh2MdMz0PIqu6qy8qF0uxNzVnE4s K5dwyBfmkFGKJfPxcNIzOGNazo06vYitVNUCzBPKSYwdVW4kqmKyDUrx6N99jIXb09vY MP5tkEIejf5/KMjY81RWibayDC/9AWDjd4tU4XcxMYOt7fN0DovE764rvPmOrG/S47YZ tX234tMhDi7JIJo0vgXcqIyHF/+29nFabStLQr33pbJDNwvD2qGOtB6VNhyT31Lptqbb DxXB9hUiKw0q9IfboiiQGDgoEBxg45ifGnPt+cdnw/G//1ZbFJYc28l2zS0xFXpPG7rD uHOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HiQBICnL; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si7185386ejr.111.2020.08.10.16.04.59; Mon, 10 Aug 2020 16:05:54 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=HiQBICnL; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727079AbgHJXDd (ORCPT + 99 others); Mon, 10 Aug 2020 19:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727088AbgHJXDc (ORCPT ); Mon, 10 Aug 2020 19:03:32 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E559CC06178A for ; Mon, 10 Aug 2020 16:03:31 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id v9so11437331ljk.6 for ; Mon, 10 Aug 2020 16:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=FD4/MDk5WwnURnuc/jZmQ+Kde4ex+xh6Ky7vtljOMA4=; b=HiQBICnLr5/84HZ02YSQlI9TIeEUtE9mvP2fW2c/4PW4LHtuIztNSCxNuDKx8calC7 og0R4FG9eCyWjYfjN0z6wAv1wV+itYKxdNUdB7tEix2FZ/z7KabLVGcT+Mg4dxS88gXW Vx+BTyxoJ8HQZr50P7xJevopSsl0oe6TYyrREVsgEyDEYAtyICy12+zT1IZ2vWC32A8q pvB901XZsFKzsU1Tme77470++JHeCkrAsOpoB1Ugl2P2Am0NBP0X+0N+ZsoSNE2ijS1G 4ui1hrzB8DtzFnAbcol1E5jBCrvtfI3Z14736AyU12BevqGTS3eBQ4w39G5Q5EwpOezP lC/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=FD4/MDk5WwnURnuc/jZmQ+Kde4ex+xh6Ky7vtljOMA4=; b=RIv3WOY7JGwApVsTKg7wjcQHRnD4afkALZhJhjh8h5cpHf8KdPM/2+ys7MDP60Yc5E B5AcqGcgPVX9H9W29QtfgbjsVNilPimlrMB2xuESpkJfIriV3M4jSM6ToSeeu8G33YIX WZlSDAZrD5Q3GlKuxamdidQ7470HBko8ZNIMBFHNlnss38INrqCLFywCmMXkmcLeDU61 NU7K2FkDw3651RFk7UISB7T/2309LN257VJjRh7mr4bujtiF1Cjv4XfMTug5imxVlhM3 yxLvWNgelc9OvLIUFEBAZKEGP05bAVAaN27DxtE8d42YwpiP0KhV3PJiarMg8MGvMa9e xM4A== X-Gm-Message-State: AOAM532UIX9Azk+xWwZDz95As9u5G2xWDPx6P/3NAZkBonct9sOM2GKb NEWmCOpBzIhs1VQPWdqeBaKAS2LLG8wu4h4keWzS4Ea0 X-Received: by 2002:a2e:b058:: with SMTP id d24mr1685315ljl.265.1597100609834; Mon, 10 Aug 2020 16:03:29 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <917bb071-8b1a-3ba4-dc16-f8d7b4cc849f@digikod.net> From: Jann Horn Date: Tue, 11 Aug 2020 01:03:03 +0200 Message-ID: Subject: Re: [PATCH v7 0/7] Add support for O_MAYEXEC To: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Cc: Al Viro , Kees Cook , Andrew Morton , kernel list , 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 , 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 , Linux API , linux-integrity@vger.kernel.org, linux-security-module , linux-fsdevel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 11, 2020 at 12:43 AM Micka=C3=ABl Sala=C3=BCn = wrote: > On 10/08/2020 22:21, Al Viro wrote: > > On Mon, Aug 10, 2020 at 10:11:53PM +0200, Micka=C3=ABl Sala=C3=BCn wrot= e: > >> It seems that there is no more complains nor questions. Do you want me > >> to send another series to fix the order of the S-o-b in patch 7? > > > > There is a major question regarding the API design and the choice of > > hooking that stuff on open(). And I have not heard anything resembling > > a coherent answer. > > Hooking on open is a simple design that enables processes to check files > they intend to open, before they open them. 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.). > > 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. You can do exactly the same thing if you do the check in a separate syscall though. And it provides a greater degree of flexibility; for example, you can use it in combination with fopen() without having to modify the internals of fopen() or having to use fdopen(). > 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). The assumption that security checks should happen as early as possible can actually cause security problems. For example, because seccomp was designed to do its checks as early as possible, including before ptrace, we had an issue for a long time where the ptrace API could be abused to bypass seccomp filters. Please don't decide that a check must be ordered first _just_ because it is a security check. While that can be good for limiting attack surface, it can also create issues when the idea is applied too broadly. I don't see how TOCTOU issues are relevant in any way here. If someone can turn a script that is considered a trusted file into an untrusted file and then maliciously change its contents, you're going to have issues either way because the modifications could still happen after openat(); if this was possible, the whole thing would kind of fall apart. And if that isn't possible, I don't see any TOCTOU. > It is important to keep > in mind that the use cases we are addressing consider that the (user > space) script interpreters (or linkers) are trusted and unaltered (i.e. > integrity/authenticity checked). These are similar sought defensive > properties as for SUID/SGID binaries: attackers can still launch them > with malicious inputs (e.g. file paths, file descriptors, environment > variables, etc.), but the binaries can then have a way to check if they > can extend their trust to some file paths. > > Checking file descriptors may help in some use cases, but not the ones > motivating this series. It actually provides a superset of the functionality that your existing patches provide. > Checking (already) opened resources could be a > *complementary* way to check execute permission, but it is not in the > scope of this series.