Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4325304ybh; Tue, 6 Aug 2019 09:44:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8lCggm4bmJvSsKoPE2vUioHuiwoih2NTqkqRDCWAepSc7sHQReLHgpfK07CcwQzR9Rv67 X-Received: by 2002:a63:5402:: with SMTP id i2mr3857870pgb.414.1565109859585; Tue, 06 Aug 2019 09:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565109859; cv=none; d=google.com; s=arc-20160816; b=FnFfwaXQOXE0rBMTMdv3ZtkVImRgeHrEX+JQggTW7jzvgim4a2jLZ9wAZADEKvL7HQ dRv3vkdjpEvYtzLUsnoXDjJBN8iBAk+S6pfxWY07xjC1KXCHmlaLGdiq2ltdWs38egMO dZfSxepgToHu4hyPQokqNP6HK173tY4SHyZc+vDzSEVN+kgLs66yJH/CbKQKc5m80IMX tRyYZbSH7GQDHs/D8178zJEFlhO/hQzpwTKsLE8ikWcNU0ecnge/IcgQ6D8WBf/6My34 OKTd7pwGz761tj8nl8r5nZHQ0Z7s/58Q58WuMPhLIQVxFpgS5VEvK5j0rXhYsBPrbbxK iDyw== 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:openpgp:from:references:cc:to:subject; bh=00yk+AZqXPoeXtWaW9mZwbbBx5SX/VihhCm61vUhxE8=; b=tViH9ucNFsxaC8hAREyvb+pyxTtnnAnge97NQajX/NpjD/ATetOBu0Mn/rDREERk2a sMI/w3NSI6czUmB2L/Kmc+6Fr1xxiWNgZgaoQDzjqypOvsyb9xGuNk1Rm6fN8aJkxnc+ lOSY+V2PtCkHOFCrqtvPA6J4VCego1O7Z0vOJRpYZks0+Qukxm8YjEpIny0ZG7YkYuQ4 pheHbSv9DnwuQ+csyspmeveze/NcahaeyZhhyV2AHOOwDBv5uinclW3wArUDTM/REHEM xDO760sdoSFUAe777+J80QyJ+0lmk1m1RlSgmNU1qvxtJ4y8g8go1J3wYoAWCZtTO9T3 51MQ== 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 y13si48884529pfp.133.2019.08.06.09.44.03; Tue, 06 Aug 2019 09:44:19 -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 S2387935AbfHFQmW (ORCPT + 99 others); Tue, 6 Aug 2019 12:42:22 -0400 Received: from smtp-sh.infomaniak.ch ([128.65.195.4]:38011 "EHLO smtp-sh.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387860AbfHFQmV (ORCPT ); Tue, 6 Aug 2019 12:42:21 -0400 Received: from smtp8.infomaniak.ch (smtp8.infomaniak.ch [83.166.132.38]) by smtp-sh.infomaniak.ch (8.14.5/8.14.5) with ESMTP id x76GesNS032199 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 6 Aug 2019 18:40:54 +0200 Received: from ns3096276.ip-94-23-54.eu (ns3096276.ip-94-23-54.eu [94.23.54.103]) (authenticated bits=0) by smtp8.infomaniak.ch (8.14.5/8.14.5) with ESMTP id x76GemgJ022929 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Tue, 6 Aug 2019 18:40:48 +0200 Subject: Re: [RFC PATCH v1 1/5] fs: Add support for an O_MAYEXEC flag on sys_open() To: Andy Lutomirski , Jan Kara , Song Liu , Alexei Starovoitov , Daniel Borkmann Cc: LKML , Al Viro , James Morris , Jonathan Corbet , Kees Cook , Matthew Garrett , Michael Kerrisk , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Mimi Zohar , =?UTF-8?Q?Philippe_Tr=c3=a9buchet?= , Shuah Khan , Thibaut Sautereau , Vincent Strubel , Yves-Alexis Perez , Kernel Hardening , Linux API , LSM List , Linux FS Devel , Steve Grubb , Matthew Bobrowski , Aleksa Sarai , Sean Christopherson References: <20181212081712.32347-1-mic@digikod.net> <20181212081712.32347-2-mic@digikod.net> <20181212144306.GA19945@quack2.suse.cz> From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Openpgp: preference=signencrypt Message-ID: <0a16e842-d636-60ac-427a-3500224f4f8d@digikod.net> Date: Tue, 6 Aug 2019 18:40:48 +0200 User-Agent: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 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 05/08/2019 01:55, Andy Lutomirski wrote: > On Wed, Dec 12, 2018 at 6:43 AM Jan Kara wrote: >> >> On Wed 12-12-18 09:17:08, Mickaël Salaün wrote: >>> When the O_MAYEXEC flag is passed, sys_open() may be subject to >>> additional restrictions depending on a security policy implemented by an >>> LSM through the inode_permission hook. >>> >>> The underlying idea is to be able to restrict scripts interpretation >>> according to a policy defined by the system administrator. For this to >>> be possible, script interpreters must use the O_MAYEXEC flag >>> appropriately. To be fully effective, these interpreters also need to >>> handle the other ways to execute code (for which the kernel can't help): >>> command line parameters (e.g., option -e for Perl), module loading >>> (e.g., option -m for Python), stdin, file sourcing, environment >>> variables, configuration files... According to the threat model, it may >>> be acceptable to allow some script interpreters (e.g. Bash) to interpret >>> commands from stdin, may it be a TTY or a pipe, because it may not be >>> enough to (directly) perform syscalls. >>> >>> A simple security policy implementation is available in a following >>> patch for Yama. >>> >>> This is an updated subset of the patch initially written by Vincent >>> Strubel for CLIP OS: >>> https://github.com/clipos-archive/src_platform_clip-patches/blob/f5cb330d6b684752e403b4e41b39f7004d88e561/1901_open_mayexec.patch >>> This patch has been used for more than 10 years with customized script >>> interpreters. Some examples can be found here: >>> https://github.com/clipos-archive/clipos4_portage-overlay/search?q=O_MAYEXEC >>> >>> Signed-off-by: Mickaël Salaün >>> Signed-off-by: Thibaut Sautereau >>> Signed-off-by: Vincent Strubel >>> Reviewed-by: Philippe Trébuchet >>> Cc: Al Viro >>> Cc: Kees Cook >>> Cc: Mickaël Salaün >> >> ... >> >>> diff --git a/fs/open.c b/fs/open.c >>> index 0285ce7dbd51..75479b79a58f 100644 >>> --- a/fs/open.c >>> +++ b/fs/open.c >>> @@ -974,6 +974,10 @@ static inline int build_open_flags(int flags, umode_t mode, struct open_flags *o >>> if (flags & O_APPEND) >>> acc_mode |= MAY_APPEND; >>> >>> + /* Check execution permissions on open. */ >>> + if (flags & O_MAYEXEC) >>> + acc_mode |= MAY_OPENEXEC; >>> + >>> op->acc_mode = acc_mode; >>> >>> op->intent = flags & O_PATH ? 0 : LOOKUP_OPEN; >> >> I don't feel experienced enough in security to tell whether we want this >> functionality or not. But if we do this, shouldn't we also set FMODE_EXEC >> on the resulting struct file? That way also security_file_open() can be >> used to arbitrate such executable opens and in particular >> fanotify permission event FAN_OPEN_EXEC will get properly generated which I >> guess is desirable (support for it is sitting in my tree waiting for the >> merge window) - adding some audit people involved in FAN_OPEN_EXEC to >> CC. Just an idea... >> > > I would really like to land this patch. I'm fiddling with making > bpffs handle permissions intelligently, and the lack of a way to say > "hey, I want to open this bpf program so that I can run it" is > annoying. Are you OK with this series? What about Aleksa's work on openat2(), and Sean's work on SGX/noexec? Is it time to send a new patch series (with a dedicated LSM instead of Yama)?