Message ID | 20221201104125.919483-1-roberto.sassu@huaweicloud.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp188179wrr; Thu, 1 Dec 2022 02:44:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf4bu1xoTyDngiAVTQkA/yw+EPnGwx46D5DapxaDc+6S0Zq4a5nuUmZqzeZWYlfXzzQYScaH X-Received: by 2002:a17:907:2c45:b0:7b8:bbbe:5ca with SMTP id hf5-20020a1709072c4500b007b8bbbe05camr38387282ejc.544.1669891470103; Thu, 01 Dec 2022 02:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669891470; cv=none; d=google.com; s=arc-20160816; b=dsGx3uQYxkyHzYQkWO75y/DXXyZDyJjiD6XGCWDBc2ldUd5lHDgD9G3ZVYRA9cGVMD h1TzAMFHFo5I0tEhcL2Z/hc53wPwTeMuYQfNNUyorS1xQar/ejIke2vmoSV82W8L/JkU c6aHIhJagsFIQMlbuuc7T9EcIP4VD7IORHEiar/NkNc4NknyTNWsGFVnpHn0qemzYNJ5 PWhIPjouQ1eAqaxbnvBpwEk+RRUfYMfY/tVKNeooyNJoVp3WYar9VoXUqiT5TNrxPA87 mXPKqrjaHlYkDdFIPRnzZgS9+eE3koSJer+3jm3N6ajblHqlGjr2CHvmcS+vNYvDtsTY Phkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Gs4GjnHE0DcZvou7znAyrcLO1MTAFbt4N5+7vDM00h4=; b=VAcZw/WWeNscrsV0MK58tZrLBp/NykGdThYIGzBXzieL1bq26VPtSA+WLJGnatrYHw HgxiMcNKHndcfedeV7cYZNrmeBjE7fa30nfYYc6+UlMbpjP9bYharipNzzEEaW56H1wQ 1I3b5X8Mn78ZyA/Z1OwSpabtsUEQBIMEyij5nnB2LTraWMDkH/nw9/P73NNY5cKAGLnH VTmIw93qd1uAveHpvVJlgtPuBrGVdWvN4Z4Osno3LtOV9O51V3xlAPKZO6nEI8GFGwk4 3effqzYmWSJ3DkOpp6W0ejzgBrHG0FehPs+3NKFtsP7EKM3O3WDDIMEeKafNwC6BdA/O 1YNw== ARC-Authentication-Results: i=1; mx.google.com; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r12-20020aa7d14c000000b004520b01a355si524026edo.52.2022.12.01.02.44.02; Thu, 01 Dec 2022 02:44:30 -0800 (PST) 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; 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 S230437AbiLAKmn (ORCPT <rfc822;heyuhang3455@gmail.com> + 99 others); Thu, 1 Dec 2022 05:42:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbiLAKm3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 1 Dec 2022 05:42:29 -0500 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73A24A0BFB; Thu, 1 Dec 2022 02:42:27 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4NNCC023vKz9xFfw; Thu, 1 Dec 2022 18:35:24 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwCHcm_phIhjrxuvAA--.49496S2; Thu, 01 Dec 2022 11:41:57 +0100 (CET) From: Roberto Sassu <roberto.sassu@huaweicloud.com> To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com Cc: ocfs2-devel@oss.oracle.com, reiserfs-devel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kernel@vger.kernel.org, keescook@chromium.org, nicolas.bouchinet@clip-os.org, Roberto Sassu <roberto.sassu@huawei.com> Subject: [PATCH v7 0/6] evm: Do HMAC of multiple per LSM xattrs for new inodes Date: Thu, 1 Dec 2022 11:41:19 +0100 Message-Id: <20221201104125.919483-1-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: LxC2BwCHcm_phIhjrxuvAA--.49496S2 X-Coremail-Antispam: 1UD129KBjvJXoWxKFy3Xr47Aw1rKry3XFy8uFg_yoWDGr4fpF Wjga15Krn8AFWjgrWfAa1xua1SgrWrGr47JrZ3Gryjy3Z8Gr1xtr1Ikry5ua45XrZ5AF9Y qw17Awn8uwn8A37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkIb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxAIw28I cxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2 IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI 42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42 IY6xAIw20EY4v20xvaj40_Wr1j6rW3Jr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2 z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU13rcDUUUUU== X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgANBF1jj4IjMwABsp X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751008118396777563?= X-GMAIL-MSGID: =?utf-8?q?1751008118396777563?= |
Series |
evm: Do HMAC of multiple per LSM xattrs for new inodes
|
|
Message
Roberto Sassu
Dec. 1, 2022, 10:41 a.m. UTC
From: Roberto Sassu <roberto.sassu@huawei.com>
One of the major goals of LSM stacking is to run multiple LSMs side by side
without interfering with each other. The ultimate decision will depend on
individual LSM decision.
Several changes need to be made to the LSM infrastructure to be able to
support that. This patch set tackles one of them: gives to each LSM the
ability to specify one or multiple xattrs to be set at inode creation
time and, at the same time, gives to EVM the ability to access all those
xattrs and calculate the HMAC on them.
The first problem that this patch set addresses is to make the
inode_init_security hook definition suitable to use with EVM which, unlike
other LSMs, needs to have visibility of all xattrs and not only the one
that the LSM infrastructure passes to the LSM to be set.
The solution is to replace in the inode_init_security definition the
name/value/len parameters with the beginning of the array containing all
xattrs set by LSMs. Due to security_old_inode_init_security() API
limitation of setting only one xattr, it has been dropped and the remaining
users, ocfs2 and reiserfs, switch to security_inode_init_security().
However, due to the complexity of the changes required to fully exploit the
ability of security_inode_init_security() to set multiple xattrs, those
users can still set only one xattr (the first set in the xattr array) where
previously they called security_old_inode_init_security().
Furthermore, while EVM is invoked unlike before, its xattr will not be set
as it would not be the first set in the xattr array, or if it is the first,
there would not be protected xattrs to calculate the HMAC on.
The second problem this patch set addresses is the limitation of the
call_int_hook() of stopping the loop when the return value from a hook
implementation is not zero. Unfortunately, for the inode_init_security hook
it is a legitimate case to return -EOPNOTSUPP, but this would not
necessarily mean that there is an error to report to the LSM infrastructure
but just that an LSM does not will to set an xattr. Other LSMs should be
still consulted as well.
The solution for this specific case is to replace the call_int_hook() with
the loop itself, so that -EOPNOTSUPP can be ignored.
Next, this patch set removes the limitation of creating only two xattrs,
one by an active LSM and another by EVM. This patch set extends the
reservation mechanism of the LSM infrastructure, to allow each LSM to
request one or multiple xattrs. While this could potentially lead to
reaching the filesystem limits of number/size of the xattrs, it seems not
an issue that need to be solved by the LSM infrastructure but by the
filesystems themselves. Currently, if the limit is reached, the only
workaround would be to use fewer LSMs.
The reservation mechanism concept makes it very easy for LSMs to position
themselves correctly in the xattr array, as the LSM infrastructure at
initialization time changes the number of xattrs requested by each LSM with
an offset. LSMs can just take that offset as the starting index in the
xattr array and fill the next slots depending on how many xattrs they
requested.
However, while this concept is intuitive, it needs extra care. While for
security blobs (the main reason of the reservation mechanism) it is not
relevant for an LSM if other LSMs filled their portion, it matters for
xattrs, as both EVM and initxattrs() callbacks scan the entire array until
a terminator (xattr with NULL name). If an LSM did not provide an xattr,
which could happen if it is loaded but not initialized, consumers of the
xattr array would stop prematurely.
This patch set avoids this problem by compacting the xattr array each time
after an LSM executed its implementation of the inode_init_security hook.
It needs to be done after each LSM, and not after all, since there might be
LSMs scanning that xattr array too. Compacting the array after all LSMs
would be too late.
Finally, this patch set modifies the evm_inode_init_security() definition
to be compatible with the inode_init_security hook definition and adds
support for scanning the whole xattr array and for calculating the HMAC
on all xattrs provided by LSMs.
This patch set has been tested by introducing several instances of a
TestLSM (some providing an xattr, some not, one with a wrong implementation
to see how the LSM infrastructure handles it, one providing multiple xattrs
and another providing an xattr but in a disabled state). The patch is not
included in this set but it is available here:
https://github.com/robertosassu/linux/commit/e13a03236df0c399dccb73df5fe4cfceb4bb1d89
The test, added to ima-evm-utils, is available here:
https://github.com/robertosassu/ima-evm-utils/blob/evm-multiple-lsms-v5-devel-v3/tests/evm_multiple_lsms.test
The test takes a UML kernel built by Github Actions and launches it several
times, each time with a different combination of LSMs and filesystems (ext4,
reiserfs, ocfs2). After boot, it first checks that there is an xattr for each
LSM providing it (for reiserfs and ocfs2 just the first LSM), and then (for
ext4) calculates the HMAC in user space and compares it with the HMAC
calculated by EVM in kernel space.
A test report can be obtained here:
https://github.com/robertosassu/ima-evm-utils/actions/runs/3525619568/jobs/5912560168
The patch set has been tested with both the SElinux and Smack test suites.
Below, there is the summary of the test results:
SELinux Test Suite result (without patches):
Files=73, Tests=1346, 225 wallclock secs ( 0.43 usr 0.23 sys + 6.11 cusr 58.70 csys = 65.47 CPU)
Result: FAIL
Failed 4/73 test programs. 13/1346 subtests failed.
SELinux Test Suite result (with patches):
Files=73, Tests=1346, 225 wallclock secs ( 0.44 usr 0.22 sys + 6.15 cusr 59.94 csys = 66.75 CPU)
Result: FAIL
Failed 4/73 test programs. 13/1346 subtests failed.
Smack Test Suite result (without patches):
95 Passed, 0 Failed, 100% Success rate
Smack Test Suite result (with patches):
95 Passed, 0 Failed, 100% Success rate
Changelog
v6:
- Add a comment in Smack to introduce its xattrs (suggested by Casey)
- Document the overloaded meaning of -EOPNOTSUPP in
security_inode_init_security() (suggested by Mimi)
v5:
- Modify the cover letter to explain that the goal of this patch set is
supporting multiple per LSM xattrs in EVM, and not moving IMA and EVM to
the LSM infrastructure (suggested by Mimi)
- Remove references in the patches description about moving IMA and EVM
to the LSM infrastructure (suggested by Mimi)
- Explain that the additional EVM invocation due to the switch to
security_inode_init_security() will not cause the EVM xattr to be added
(suggested by Mimi)
v4:
- Remove patch to call reiserfs_security_free(), already queued
- Switch ocfs2 and reiserfs to security_inode_init_security() (suggested by
Mimi)
- Remove security_old_inode_init_security() (suggested by Paul)
- Rename security_check_compact_xattrs() to
security_check_compact_filled_xattrs() and add function description
(suggested by Mimi)
- Rename checked_xattrs parameter of security_check_compact_filled_xattrs()
to num_filled_xattrs (suggested by Mimi)
- Rename cur_xattrs variable in security_inode_init_security() to
num_filled_xattrs (suggested by Mimi)
v3:
- Don't free the xattr name in reiserfs_security_free()
- Don't include fs_data parameter in inode_init_security hook
- Don't change evm_inode_init_security(), as it will be removed if EVM is
stacked
- Fix inode_init_security hook documentation
- Drop lsm_find_xattr_slot(), use simple xattr reservation mechanism and
introduce security_check_compact_xattrs() to compact the xattr array
- Don't allocate xattr array if LSMs didn't reserve any xattr
- Return zero if initxattrs() is not provided to
security_inode_init_security(), -EOPNOTSUPP if value is not provided to
security_old_inode_init_security()
- Request LSMs to fill xattrs if only value (not the triple) is provided to
security_old_inode_init_security(), to avoid unnecessary memory
allocation
v2:
- rewrite selinux_old_inode_init_security() to use
security_inode_init_security()
- add lbs_xattr field to lsm_blob_sizes structure, to give the ability to
LSMs to reserve slots in the xattr array (suggested by Casey)
- add new parameter base_slot to inode_init_security hook definition
v1:
- add calls to reiserfs_security_free() and initialize sec->value to NULL
(suggested by Tetsuo and Mimi)
- change definition of inode_init_security hook, replace the name, value
and len triple with the xattr array (suggested by Casey)
- introduce lsm_find_xattr_slot() helper for LSMs to find an unused slot in
the passed xattr array
Roberto Sassu (6):
reiserfs: Switch to security_inode_init_security()
ocfs2: Switch to security_inode_init_security()
security: Remove security_old_inode_init_security()
security: Allow all LSMs to provide xattrs for inode_init_security
hook
evm: Align evm_inode_init_security() definition with LSM
infrastructure
evm: Support multiple LSMs providing an xattr
fs/ocfs2/namei.c | 18 ++---
fs/ocfs2/xattr.c | 30 ++++++-
fs/reiserfs/xattr_security.c | 23 ++++--
include/linux/evm.h | 12 +--
include/linux/lsm_hook_defs.h | 3 +-
include/linux/lsm_hooks.h | 17 ++--
include/linux/security.h | 12 ---
security/integrity/evm/evm.h | 2 +
security/integrity/evm/evm_crypto.c | 9 ++-
security/integrity/evm/evm_main.c | 28 +++++--
security/security.c | 121 +++++++++++++++++++++-------
security/selinux/hooks.c | 19 +++--
security/smack/smack_lsm.c | 33 +++++---
13 files changed, 226 insertions(+), 101 deletions(-)
Comments
On Thu, Dec 1, 2022 at 5:42 AM Roberto Sassu <roberto.sassu@huaweicloud.com> wrote: > > From: Roberto Sassu <roberto.sassu@huawei.com> > > One of the major goals of LSM stacking is to run multiple LSMs side by side > without interfering with each other. The ultimate decision will depend on > individual LSM decision. > > Several changes need to be made to the LSM infrastructure to be able to > support that. This patch set tackles one of them: gives to each LSM the > ability to specify one or multiple xattrs to be set at inode creation > time and, at the same time, gives to EVM the ability to access all those > xattrs and calculate the HMAC on them. ... > The patch set has been tested with both the SElinux and Smack test suites. > Below, there is the summary of the test results: > > SELinux Test Suite result (without patches): > Files=73, Tests=1346, 225 wallclock secs ( 0.43 usr 0.23 sys + 6.11 cusr 58.70 csys = 65.47 CPU) > Result: FAIL > Failed 4/73 test programs. 13/1346 subtests failed. > > SELinux Test Suite result (with patches): > Files=73, Tests=1346, 225 wallclock secs ( 0.44 usr 0.22 sys + 6.15 cusr 59.94 csys = 66.75 CPU) > Result: FAIL > Failed 4/73 test programs. 13/1346 subtests failed. Can you provide some more information on which of the selinux-testsuite tests failed? That shouldn't be happening and I'm a little concerned that these test failures, even if unrelated to your work here, could be masking failures which are related.
On Thu, 2023-01-12 at 12:15 -0500, Paul Moore wrote: > On Thu, Dec 1, 2022 at 5:42 AM Roberto Sassu > <roberto.sassu@huaweicloud.com> wrote: > > From: Roberto Sassu <roberto.sassu@huawei.com> > > > > One of the major goals of LSM stacking is to run multiple LSMs side by side > > without interfering with each other. The ultimate decision will depend on > > individual LSM decision. > > > > Several changes need to be made to the LSM infrastructure to be able to > > support that. This patch set tackles one of them: gives to each LSM the > > ability to specify one or multiple xattrs to be set at inode creation > > time and, at the same time, gives to EVM the ability to access all those > > xattrs and calculate the HMAC on them. > > ... > > > The patch set has been tested with both the SElinux and Smack test suites. > > Below, there is the summary of the test results: > > > > SELinux Test Suite result (without patches): > > Files=73, Tests=1346, 225 wallclock secs ( 0.43 usr 0.23 sys + 6.11 cusr 58.70 csys = 65.47 CPU) > > Result: FAIL > > Failed 4/73 test programs. 13/1346 subtests failed. > > > > SELinux Test Suite result (with patches): > > Files=73, Tests=1346, 225 wallclock secs ( 0.44 usr 0.22 sys + 6.15 cusr 59.94 csys = 66.75 CPU) > > Result: FAIL > > Failed 4/73 test programs. 13/1346 subtests failed. > > Can you provide some more information on which of the > selinux-testsuite tests failed? That shouldn't be happening and I'm a > little concerned that these test failures, even if unrelated to your > work here, could be masking failures which are related. Uhm, my virtual machine has been used for many tests and was not clean. This time, I installed a fresh Fedora 37 and compiled the kernel with the same configuration as the shipped kernel. Everything works now: All tests successful. Files=74, Tests=1363, 210 wallclock secs ( 0.42 usr 0.11 sys + 6.66 cusr 22.33 csys = 29.52 CPU) Result: PASS Roberto
On Thu, Dec 1, 2022 at 5:42 AM Roberto Sassu <roberto.sassu@huaweicloud.com> wrote: > > From: Roberto Sassu <roberto.sassu@huawei.com> > > One of the major goals of LSM stacking is to run multiple LSMs side by side > without interfering with each other. The ultimate decision will depend on > individual LSM decision. > > Several changes need to be made to the LSM infrastructure to be able to > support that. This patch set tackles one of them: gives to each LSM the > ability to specify one or multiple xattrs to be set at inode creation > time and, at the same time, gives to EVM the ability to access all those > xattrs and calculate the HMAC on them. Hi Roberto, The v7 draft of this patchset had some good discussion, and based on a quick read of the comments it looks like everyone was eventually satisfied that the v7 draft was good and no further changes were necessary, is that correct or do you have an updated draft of this patchset?
On Wed, 2023-03-08 at 17:16 -0500, Paul Moore wrote: > On Thu, Dec 1, 2022 at 5:42 AM Roberto Sassu > <roberto.sassu@huaweicloud.com> wrote: > > From: Roberto Sassu <roberto.sassu@huawei.com> > > > > One of the major goals of LSM stacking is to run multiple LSMs side by side > > without interfering with each other. The ultimate decision will depend on > > individual LSM decision. > > > > Several changes need to be made to the LSM infrastructure to be able to > > support that. This patch set tackles one of them: gives to each LSM the > > ability to specify one or multiple xattrs to be set at inode creation > > time and, at the same time, gives to EVM the ability to access all those > > xattrs and calculate the HMAC on them. > > Hi Roberto, > > The v7 draft of this patchset had some good discussion, and based on a > quick read of the comments it looks like everyone was eventually > satisfied that the v7 draft was good and no further changes were > necessary, is that correct or do you have an updated draft of this > patchset? Hi Paul I addressed few more concerns from Mimi and Casey. I think v8 should be good to send (unless you have more comments/suggestions). Thanks Roberto