Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp732325ybz; Fri, 1 May 2020 07:34:34 -0700 (PDT) X-Google-Smtp-Source: APiQypIfwpOLDOqYQnCIdCl4BXcczLF6dgM8vrkfozyT0mqeMi4zwNmS37SDBJGwXwj3svchafUU X-Received: by 2002:a17:906:4907:: with SMTP id b7mr3252695ejq.279.1588343674000; Fri, 01 May 2020 07:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588343673; cv=none; d=google.com; s=arc-20160816; b=H0AurEbGePOcGat3NOY3gHpwNb07BYC5gRmXkp+17C2Q2fG2t0OkHZx+Dk/L6JaTmd G9c0PPLIM7z2iwEnV1KBX+cmP9kaiG4ofmm5FSdhy/KQT9UYviPm1Z0Ycm26mYyls4FV s6vVgsnJmDC2Akmy+iRGqv0Fs5KNiV8hhc0rjnxQznLNtHPsbG6ziCPSZDWUAItPxqNU 5Mr05SR/ZEr4xWNIST6+qN3gBuHpHQZjQEK4t63BXenXArQXXklaEVSrFqoH1vhB64YU 1wULv+UFoTfI0g0d8K49mBHl0YIE9A++x44ZY9YUfPE8H3T0OTnYGZe6kxcItxsYWnzA uraQ== 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=uYikDd4PNnQaB6SQzxFAcd8LBXka6eYQM1BHvZik3WE=; b=te05TK14fyWtm83j4VGQuOc2vu1k6Q5lTUloEHPLNy5f6thMl88AkUUAjKpiSVl+nf g9WMVkc2hmv37uK/hzlMREPv3HJy45H5x9j9DqAqx52YVSWoT5Eb24M840JIv/pKZlSB BlPVsCBm7GQkLukkq5gVfn3D6khA0MSPpDh5pPo/TDM9nJdB01c9glrdv0NTjQjm6HTH ViHMP7BeLRWtp8/KsHipgfIFPzQ+BGUzquJ1qVDqsWyzUxmt2RRhBOoYrl/nBzDsWEu3 ySsZ1KsotOji13FoEcIFmLl9ydWjkfiQK5VjuaLLizxh/XUcl9QCmzk2n3cJhsmbnf8F wZmw== 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 x61si1821335ede.23.2020.05.01.07.34.07; Fri, 01 May 2020 07:34:33 -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 S1729149AbgEAOc0 (ORCPT + 99 others); Fri, 1 May 2020 10:32:26 -0400 Received: from smtp-8fa9.mail.infomaniak.ch ([83.166.143.169]:51087 "EHLO smtp-8fa9.mail.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728856AbgEAOcZ (ORCPT ); Fri, 1 May 2020 10:32:25 -0400 Received: from smtp-3-0001.mail.infomaniak.ch (unknown [10.4.36.108]) by smtp-2-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 49DF8659L7zlhH6x; Fri, 1 May 2020 16:32:22 +0200 (CEST) Received: from ns3096276.ip-94-23-54.eu (unknown [94.23.54.103]) by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 49DF850BX5zlvJFk; Fri, 1 May 2020 16:32:20 +0200 (CEST) Subject: Re: [PATCH v3 3/5] fs: Enable to enforce noexec mounts or file exec through RESOLVE_MAYEXEC To: James Morris Cc: linux-kernel@vger.kernel.org, Aleksa Sarai , Alexei Starovoitov , Al Viro , Andy Lutomirski , Christian Heimes , Daniel Borkmann , Deven Bowers , Eric Chiang , Florian Weimer , Jan Kara , Jann Horn , Jonathan Corbet , Kees Cook , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Mimi Zohar , =?UTF-8?Q?Philippe_Tr=c3=a9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , Thibaut Sautereau , Vincent Strubel , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org References: <20200428175129.634352-1-mic@digikod.net> <20200428175129.634352-4-mic@digikod.net> From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Message-ID: Date: Fri, 1 May 2020 16:32:20 +0200 User-Agent: MIME-Version: 1.0 In-Reply-To: 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 01/05/2020 06:22, James Morris wrote: > On Tue, 28 Apr 2020, Micka?l Sala?n wrote: > >> Enable to either propagate the mount options from the underlying VFS >> mount to prevent execution, or to propagate the file execute permission. >> This may allow a script interpreter to check execution permissions >> before reading commands from a file. > > I'm finding the description of this patch difficult to understand. > > In the first case, this seems to mean: if you open a file with > RESOLVE_MAYEXEC from a noexec mount, then it will fail. Correct? Yes. > > In the second case, do you mean a RESOLVE_MAYEXEC open will fail if the > file does not have +x set for the user? Yes, and this is still in the hands sysadmins. As explain in the documentation patch, the sysctl takes a bitfield consisting of "mount !noexec" or "file exec permission". It is not an exclusive OR. The "file exec permission" could be seen as a more strict restriction than only the mount one. > > >> The main goal is to be able to protect the kernel by restricting >> arbitrary syscalls that an attacker could perform with a crafted binary >> or certain script languages. > > This sounds like the job of seccomp. Why is this part of MAYEXEC? The initial goal of O_MAYEXEC (in CLIP OS 4) is to prevent untrusted code execution. Code execution leads to system calls, which could lead to data access/modification, and kernel attacks. seccomp can't enable execution of only some files, it only enables an on/off execution policy (i.e. by filtering execve(2) ). > >> It also improves multilevel isolation >> by reducing the ability of an attacker to use side channels with >> specific code. These restrictions can natively be enforced for ELF >> binaries (with the noexec mount option) but require this kernel >> extension to properly handle scripts (e.g., Python, Perl). > > Again, not sure why you're talking about side channels and MAYEXEC and > mount options. Are you more generally talking about being able to prevent > execution of arbitrary script files included by an interpreter? Yes, I explain the thread model, especially the risk of scripts. Multilevel isolation can be bypassed simply by using CPU instructions (e.g. side channel attacks), not even syscalls. The ability to execute arbitrary code, including advanced scripting languages, can lead to this kind of CPU attacks. > >> Add a new sysctl fs.open_mayexec_enforce to control this behavior. >> Indeed, because of compatibility with installed systems, only the system >> administrator is able to check that this new enforcement is in line with >> the system mount points and file permissions. A following patch adds >> documentation. > > I don't like the idea of any of this feature set being configurable. > RESOLVE_MAYEXEC as a new flag should have well-defined, stable semantics. Unfortunately, as discussed in the v2 email thread [1], if we impose such restrictions with the O_MAYEXEC flag, then almost no userspace application will use it because it could cause unexpected behavior. Indeed, the application developers may not know the configuration of the system their applications will be run on. Only sysadmins know the mount points configuration (either they are have noexec or not), and if the set of application installed on the system works well with the set of files (e.g. according to their permissions). It is the same issue as with a system-wide LSM policy configuration. Processes should be able to tell their use of a file, but the sysadmin using common distro binaries should be able to control the execution policy according to the maturity of the current system installation. However, for fully controlled distros such as CLIP OS, it make sense to enforce such restrictions at kernel build time. I can add an alternative kernel configuration to enforce a particular policy at boot and disable this sysctl. [1] https://lore.kernel.org/lkml/1fbf54f6-7597-3633-a76c-11c4b2481add@ssi.gouv.fr/