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.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 62C21C5517A for ; Tue, 3 Nov 2020 16:03:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D556223EA for ; Tue, 3 Nov 2020 16:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728309AbgKCQDv (ORCPT ); Tue, 3 Nov 2020 11:03:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728161AbgKCQDv (ORCPT ); Tue, 3 Nov 2020 11:03:51 -0500 Received: from smtp-8fae.mail.infomaniak.ch (smtp-8fae.mail.infomaniak.ch [IPv6:2001:1600:4:17::8fae]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7DBBC061A04 for ; Tue, 3 Nov 2020 08:03:50 -0800 (PST) Received: from smtp-3-0000.mail.infomaniak.ch (unknown [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4CQZMm1C8kzlhqv5; Tue, 3 Nov 2020 17:03:48 +0100 (CET) Received: from ns3096276.ip-94-23-54.eu (unknown [94.23.54.103]) by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4CQZMk0bzXzlh8TS; Tue, 3 Nov 2020 17:03:46 +0100 (CET) Subject: Re: [PATCH v22 07/12] landlock: Support filesystem access-control To: Jann Horn Cc: James Morris , "Serge E . Hallyn" , Al Viro , Andy Lutomirski , Anton Ivanov , Arnd Bergmann , Casey Schaufler , Jeff Dike , Jonathan Corbet , Kees Cook , Michael Kerrisk , Richard Weinberger , Shuah Khan , Vincent Dagonneau , Kernel Hardening , Linux API , linux-arch , "open list:DOCUMENTATION" , linux-fsdevel , kernel list , "open list:KERNEL SELFTEST FRAMEWORK" , linux-security-module , the arch/x86 maintainers , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= References: <20201027200358.557003-1-mic@digikod.net> <20201027200358.557003-8-mic@digikod.net> From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Message-ID: <056d8f1a-b45f-379f-d81a-8c13a1536c3f@digikod.net> Date: Tue, 3 Nov 2020 17:03:45 +0100 User-Agent: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org On 29/10/2020 02:06, Jann Horn wrote: > (On Tue, Oct 27, 2020 at 9:04 PM Mickaël Salaün wrote: >> diff --git a/security/landlock/fs.c b/security/landlock/fs.c > [...] >> +static inline u32 get_file_access(const struct file *const file) >> +{ >> + u32 access = 0; >> + >> + if (file->f_mode & FMODE_READ) { >> + /* A directory can only be opened in read mode. */ >> + if (S_ISDIR(file_inode(file)->i_mode)) >> + return LANDLOCK_ACCESS_FS_READ_DIR; >> + access = LANDLOCK_ACCESS_FS_READ_FILE; >> + } >> + /* >> + * A LANDLOCK_ACCESS_FS_APPEND could be added but we also need to check >> + * fcntl(2). >> + */ > > Once https://lore.kernel.org/linux-api/20200831153207.GO3265@brightrain.aerifal.cx/ > lands, pwritev2() with RWF_NOAPPEND will also be problematic for > classifying "write" vs "append"; you may want to include that in the > comment. (Or delete the comment.) Contrary to fcntl(2), pwritev2(2) doesn't seems to modify the file description. Otherwise, other LSMs would need to be patched. I'll remove this comment anyway. > >> + if (file->f_mode & FMODE_WRITE) >> + access |= LANDLOCK_ACCESS_FS_WRITE_FILE; >> + /* __FMODE_EXEC is indeed part of f_flags, not f_mode. */ >> + if (file->f_flags & __FMODE_EXEC) >> + access |= LANDLOCK_ACCESS_FS_EXECUTE; >> + return access; >> +} > [...] >