From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B45DC433E2 for ; Tue, 8 Sep 2020 20:03:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8EF520768 for ; Tue, 8 Sep 2020 20:03:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730312AbgIHUDl (ORCPT ); Tue, 8 Sep 2020 16:03:41 -0400 Received: from smtp-bc0a.mail.infomaniak.ch ([45.157.188.10]:59541 "EHLO smtp-bc0a.mail.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730455AbgIHPYC (ORCPT ); Tue, 8 Sep 2020 11:24:02 -0400 Received: from smtp-3-0001.mail.infomaniak.ch (unknown [10.4.36.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4Bm4Zc3mc0zlhVkF; Tue, 8 Sep 2020 14:43:36 +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 4Bm4ZX61Rqzlh8TW; Tue, 8 Sep 2020 14:43:32 +0200 (CEST) Subject: Re: [RFC PATCH v8 1/3] fs: Introduce AT_INTERPRETED flag for faccessat2(2) To: Mimi Zohar , linux-kernel@vger.kernel.org Cc: Aleksa Sarai , Alexei Starovoitov , Al Viro , Andrew Morton , 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 , Kees Cook , Lakshmi Ramasubramanian , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , Miklos Szeredi , =?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, Thibaut Sautereau , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Stephen Smalley , John Johansen References: <20200908075956.1069018-1-mic@digikod.net> <20200908075956.1069018-2-mic@digikod.net> From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Message-ID: <75451684-58f3-b946-dca4-4760fa0d7440@digikod.net> Date: Tue, 8 Sep 2020 14:43:32 +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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/09/2020 14:28, Mimi Zohar wrote: > Hi Mickael, > > On Tue, 2020-09-08 at 09:59 +0200, Mickaël Salaün wrote: >> diff --git a/fs/open.c b/fs/open.c >> index 9af548fb841b..879bdfbdc6fa 100644 >> --- a/fs/open.c >> +++ b/fs/open.c >> @@ -405,9 +405,13 @@ static long do_faccessat(int dfd, const char __user *filename, int mode, int fla >> if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ >> return -EINVAL; >> >> - if (flags & ~(AT_EACCESS | AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) >> + if (flags & ~(AT_EACCESS | AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH | >> + AT_INTERPRETED)) >> return -EINVAL; >> >> + /* Only allows X_OK with AT_INTERPRETED for now. */ >> + if ((flags & AT_INTERPRETED) && !(mode & S_IXOTH)) >> + return -EINVAL; >> if (flags & AT_SYMLINK_NOFOLLOW) >> lookup_flags &= ~LOOKUP_FOLLOW; >> if (flags & AT_EMPTY_PATH) >> @@ -426,7 +430,30 @@ static long do_faccessat(int dfd, const char __user *filename, int mode, int fla >> >> inode = d_backing_inode(path.dentry); >> >> - if ((mode & MAY_EXEC) && S_ISREG(inode->i_mode)) { >> + if ((flags & AT_INTERPRETED)) { >> + /* >> + * For compatibility reasons, without a defined security policy >> + * (via sysctl or LSM), using AT_INTERPRETED must map the >> + * execute permission to the read permission. Indeed, from >> + * user space point of view, being able to execute data (e.g. >> + * scripts) implies to be able to read this data. >> + * >> + * The MAY_INTERPRETED_EXEC bit is set to enable LSMs to add >> + * custom checks, while being compatible with current policies. >> + */ >> + if ((mode & MAY_EXEC)) { > > Why is the ISREG() test being dropped? Without dropping it, there > would be no reason for making the existing test an "else" clause. The ISREG() is not dropped, it is just moved below with the rest of the original code. The corresponding code (with the path_noexec call) for AT_INTERPRETED is added with the next commit, and it relies on the sysctl configuration for compatibility reasons. > >> + mode |= MAY_INTERPRETED_EXEC; >> + /* >> + * For compatibility reasons, if the system-wide policy >> + * doesn't enforce file permission checks, then >> + * replaces the execute permission request with a read >> + * permission request. >> + */ >> + mode &= ~MAY_EXEC; >> + /* To be executed *by* user space, files must be readable. */ >> + mode |= MAY_READ; > > After this change, I'm wondering if it makes sense to add a call to > security_file_permission(). IMA doesn't currently define it, but > could. Yes, that's the idea. We could replace the following inode_permission() with file_permission(). I'm not sure how this will impact other LSMs though. > > Mimi > >> + } >> + } else if ((mode & MAY_EXEC) && S_ISREG(inode->i_mode)) { >> /* >> * MAY_EXEC on regular files is denied if the fs is mounted >> * with the "noexec" flag. >