Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2838103rwa; Mon, 22 Aug 2022 15:04:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR4h36tcgtcqtGBmMgzF/U7EL/jrdbcE1Cg2TxHH1q882HnaGQ019BLYqjcs1iCbuf5teQIv X-Received: by 2002:a17:906:84f0:b0:73d:837a:332c with SMTP id zp16-20020a17090684f000b0073d837a332cmr4098658ejb.679.1661205865502; Mon, 22 Aug 2022 15:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661205865; cv=none; d=google.com; s=arc-20160816; b=XMqknW6mSep6iZrneusah/vgrBz6Q7ShW7l5O1QcUt+dUSFz1rQb0R4JfoE5zVdTPO MVXW+iGwy+RPVCQbyRGBOKzSqPu0SHnNMAy+O7tGmdPcKbJjwmv1MQ6gJ4xAp/2jiSjY Thz+CIJW4XZ625Vl3Ders1fLFqFOxEA5KVU5qzWnBffQzZuspmd6c4hSWNl7m3XPyWJm Ki/VNrUsws8h7iuO1ds6gIKJGXhDRIQmQ7pS5ANrQC6UYbJ7PTohiF5tlZU2Pq6pxrDJ wUkErnxfaeGp8Yy09d7FSNOp4ic825gMOCrxcvAIcvAdTgZLqVXwH7HFGKUHmBLwo1fZ ihpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=fLqGByfEzWlCEhJSksWt4vK5bBn60323rZp1GKVGlS0=; b=gHOLIfulBI2Yk+wNcHyjW93dlX8mwT7+6FZ3lC40Mh+3vwknvnJZN+Lh3Ag+HjhcqB OZlTO/K4Bx0TzUTIto9FNnRC/jUGM6O8SHFKVNDIVq6Sr0mphCc60yv6zSfqFZDE1g5Y btTIxs/3J35n3fB1p85jUL1Ovid3fd5cedBekuapnH2N3qX0Qd+tnM2ZscE3X/AU7VaP NuRDx0JFlT3m7AxVeudKCl3F1jg+OoQLmkoYV7GzmVIQihN2oG0q/KYOpARi9hnqU7as URyj9F0prCVO3VT7/2hsfo1ICeYizH/h/P8gqlN9tjIOxQ1p4acPlUTuAm/+2uI7hOQx +VMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=CPYzIYaW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a056402519100b004469a602b4esi621774edd.66.2022.08.22.15.03.59; Mon, 22 Aug 2022 15:04:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=CPYzIYaW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238375AbiHVVxW (ORCPT + 99 others); Mon, 22 Aug 2022 17:53:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238368AbiHVVxR (ORCPT ); Mon, 22 Aug 2022 17:53:17 -0400 Received: from sonic309-27.consmr.mail.ne1.yahoo.com (sonic309-27.consmr.mail.ne1.yahoo.com [66.163.184.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7B9EC7F for ; Mon, 22 Aug 2022 14:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1661205194; bh=fLqGByfEzWlCEhJSksWt4vK5bBn60323rZp1GKVGlS0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=CPYzIYaW10L5I4fSNXmbeeCrQ8xsfsK+PFbkT3LWEUCqxV4AGLb+MjYVyFSmBL5ubPXPTNPQXnqhVMms8h6SuTxxeTTFyXENQAfjwJLpjp7D0/Ex1J7f/ymc70vf9d7MdKNCALH8lZvJTh5Qom95tuw1lvKYL8boHTeVvpbzxgjBZiJyZAe22BD/V4rKEbMmNQMjO707V7DCH1T21WYdxm2bYFLKuh8dFZ0DLxVHP8t45InYqCWWYvzSmJR9ZLacGX53/AhbXiCphGgs5zHU9Azm0AAw6v0v4RnfsjRDTtIQ0IkMRp0j4Ce/CBv24rlMdFESDaAM46zqW9HagqYF0Q== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1661205194; bh=xPdVikjp3/385E9i4rwjDrrg8pgwvogDhQn9v9e+AhF=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=CIOeYU3KtEiwy3vX8d2CF2ji4eQ44goPEB6PXsgjwWt1GAKWDJIlVs+SReq00ZI8JnvFaWREQq1vHZg3I6+mSYCvOFoLyDH28MtDM5ai+MpNjgLdxgINmvSpTYDhEgSgfFtT9vUSMBE2tUs8yetHxhZW/lj0sNOZye6N/ofsSOq59VbMh6A6NniVSO3TAmkLyuWVKuPLPQG4MVNX+AHsfvptuzt5a8QaVUsgBGG6FSfzhexeicGuha/A2xWHRtsbixrDBnStSwZorG82SqaQPupWNfVaGS8wmkEHAmK3pyM3fl/k/lLREY9BcJ1rs2KgaMOizkVR6cBw5eRwAN384g== X-YMail-OSG: aE4KJ6gVM1kGTFBADa2f5WQQzFqCqUrSXYTgTFStwPEQG3kRutTlw.NjglF33sW 7s8TUgDzo2Nz5EJTn6iUC6vD4ArO82.N1O9iTIQOaD0bD9n0LLZMHOSe4s5BVOrWqyW3zqqxoYhr 5Kej.FkiIRTC2aw6W.N1ljG4Iw8sKb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dMLIax9UqBla_sDbqezEAUzfmSCX2KMoE84tDiAvG45tBhDbkCUzD x8mCWWdK4Mmxp0qEOOj2arRI- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Mon, 22 Aug 2022 21:53:14 +0000 Received: by hermes--production-ne1-6649c47445-jb4gk (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 94984fe3b88a583bcfc62931de86be49; Mon, 22 Aug 2022 21:53:10 +0000 (UTC) Message-ID: Date: Mon, 22 Aug 2022 14:53:08 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH -next 0/5] landlock: add chmod and chown support Content-Language: en-US To: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , =?UTF-8?Q?G=c3=bcnther_Noack?= Cc: Xiu Jianfeng , paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, shuah@kernel.org, corbet@lwn.net, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, casey@schaufler-ca.com References: <20220822114701.26975-1-xiujianfeng@huawei.com> <39df1a34-51dc-da55-ff1c-59cab896c8a0@schaufler-ca.com> <72ca592e-ff1b-120e-3d00-5c79aefbc247@digikod.net> From: Casey Schaufler In-Reply-To: <72ca592e-ff1b-120e-3d00-5c79aefbc247@digikod.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailer: WebService/1.1.20560 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/22/2022 2:21 PM, Mickaël Salaün wrote: > > > On 22/08/2022 23:18, Günther Noack wrote: >> On Mon, Aug 22, 2022 at 12:35:18PM -0700, Casey Schaufler wrote: >>> On 8/22/2022 12:17 PM, Günther Noack wrote: >>>> Hi! >>>> >>>> Very exciting to see! Thank you for sending this! :) >>>> >>>> I'm just throwing in some comments based on the very similar truncate >>>> patch set, in the hope that it helps. (But obviously, Mickaël Salaün >>>> has the last word on this code.) >>>> >>>> Slightly higher level question: Should we start to group the >>>> functionality of multiple LSM hooks under one Landlock flag? (Will it >>>> be harder to change the LSM hook interface in the future if we >>>> continue to add one flag per hook? Or is this structure already >>>> exposed to userspace by other LSMs?) >>> >>> I'm not a landlock expert. The question is nonsensical, yet somewhat >>> frightening nonetheless. Could you put just a touch more context into >>> what you're asking for? >> >> By "Landlock flags", I meant the integer that Landlock uses to >> represent the set of possible operations on a file hierarchy: >> >> Landlock's file system access rights (access_mode_t on the kernel >> side) are defined with an integer with flags (LANDLOCK_ACCESS_FS_*) >> for different operations that one might do with files. They get used >> from userspace to control what is permitted on which parts of the file >> system. (Docs: https://docs.kernel.org/userspace-api/landlock.html) >> >> Currently most of the available Landlock flags map pretty closely to >> one of the file- and path-related LSM hooks. (See various hook >> implementations in security/landlock/fs.c) >> >> The file system operations that Landlock doesn't cover yet (as of >> kernel 5.19) are listed below, and there are potentially a few more >> that might be missing. I suspect/hope that there will be more patches >> in the style of the truncate/chmod/chown patches, which will add that >> coverage. >> >> The question is basically: >> When these patches get added, how should the userspace-exposed >> Landlock file system access rights map to the LSM hooks for these >> upcoming Landlock features? Should each of the newly covered >> operations have its own flag, or is it better to group them? >> >> (It's well possible that the right answer is "one flag per feature", >> but I feel it still makes sense to ask this before all these patches >> get written?) > > Landlock is not strictly tied to the current LSM hooks, but they fit > well (because they are designed to be flexible enough to be use by > multiple access control systems). In fact, Landlock already uses > orthogonal access rights such as LANDLOCK_ACCESS_FS_REFER (using the > path_link or path_rename hooks), LANDLOCK_ACCESS_FS_MAKE_* (using the > path_mknod and path_mkdir hooks)… > > Anyway, the LSM framework is evolving, we can add new hooks and modify > others (e.g. see the security_path_rename hook modification for > FS_REFER) as long as mainline access control systems don't break and > subsystem maintainers are OK with such changes. Like any kernel API, > the LSM API is not stable, but this is not an issue for mainline code. > > Landlock's goal is to find the sweet spot between flexibility for > different sandboxing use cases and an understandable/simple-enough > access control system. The access rights should then be meaningful for > users, which are already familiar with the UAPI/syscalls, hence the > current Landlock access rights (which are not very original, and that > is a good thing). This is why I'm wondering if it is worth it to > differentiate between chmod and chgrp (and add a dedicated access > right per action or only one for both). The lesson from capabilities is that differentiating between chmod, chown and chgrp is pointless, and CAP_DAC_CHMOD, CAP_DAC_CHOWN and CAP_DAC_CHGRP should have just been CAP_DAC_OVERRIDE. On the other hand, those who argue that SELinux proves the value of fine granularity would likely have you go with separate rights. What's important is that you don't tie your rights too tightly to the underlying implementation. That has the potential to expose details of how the code work that user-space has no business basing decisions on. > > >> >> —Günther >> >>>> For example, some of the "missing" operations listed on the Landlock >>>> documentation could also be grouped roughly as: >>>> >>>> Modifying files: >>>>   - truncate >>>> >>>> Modifying file metadata: >>>>   - chmod >>>>   - chown >>>>   - setxattr >>>>   - utime >>>> >>>> Observing files (check presence and file metadata): >>>>   - access >>>>   - stat >>>>   - readlink, following links (can observe symlink presence) >>>>   - chdir (can observe dir presence and 'x' attribute) >>>> >>>> Ungrouped: >>>>   - flock >>>>   - ioctl >>>>   - fcntl >>>> >>>> Do you have opinions on this? > > That could indeed help users identifying currently missing pieces for > their use case. > > >>>> >>>> —Günther >>>> >>>> On Mon, Aug 22, 2022 at 07:46:56PM +0800, Xiu Jianfeng wrote: >>>>> hi, >>>>>    this patchset adds chmod and chown support for landlock >>>>> >>>>> Xiu Jianfeng (5): >>>>>    landlock: expand access_mask_t to u32 type >>>>>    landlock: add chmod and chown support >>>>>    landlock/selftests: add selftests for chmod and chown >>>>>    landlock/samples: add chmod and chown support >>>>>    landlock: update chmod and chown support in document >>>>> >>>>>   Documentation/userspace-api/landlock.rst     |   8 +- >>>>>   include/uapi/linux/landlock.h                |   8 +- >>>>>   samples/landlock/sandboxer.c                 |  12 +- >>>>>   security/landlock/fs.c                       |  16 +- >>>>>   security/landlock/limits.h                   |   2 +- >>>>>   security/landlock/ruleset.h                  |   2 +- >>>>>   security/landlock/syscalls.c                 |   2 +- >>>>>   tools/testing/selftests/landlock/base_test.c |   2 +- >>>>>   tools/testing/selftests/landlock/fs_test.c   | 234 >>>>> ++++++++++++++++++- >>>>>   9 files changed, 274 insertions(+), 12 deletions(-) >>>>> >>>>> -- >>>>> 2.17.1 >>>>> >>>> -- >> >> --