Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4539016rdh; Wed, 29 Nov 2023 04:28:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEY3LR5rqCHO+YpwlvGm7dheyRFpDbQSoickRcG7UQRv4t/kxM9ZdKqprPfeQ1KKKXm6nS7 X-Received: by 2002:a05:6358:4406:b0:16b:c43f:3da4 with SMTP id z6-20020a056358440600b0016bc43f3da4mr20112387rwc.3.1701260910866; Wed, 29 Nov 2023 04:28:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701260910; cv=none; d=google.com; s=arc-20160816; b=NAZZGhc/QzJPr9zgHK3xXbnimHdHCwAMux7fqu7wrliChWWqlsgu/gVlzOVuJiFKTg GhrdSbt77wJt2vWdDUuRZ9YxNGdEFk6xrTmAJ6eDDKRI/6mWljQQWNAgM8cXFdbSJh1Q GltK8u9h0NzqB4Qa5b99vbXM2e681TlhSYqCPazKzo2pTZnxfmDb67mIo/aNAsVIlrc3 /nU9j9UBo5wtUcEmHjjuBZehaGQT68e7kkrcfdSZ0B+e9hmB6Y/Sr31QOKddO9AMgHA+ 1C/vw54dQunmB112oXGWHogcnHyBHcdU1nD5t3KbOHWt29jaRzS5eULc/eOm8JHHxqx6 MI2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id; bh=JhIy6jtv7PAPDS6165bPvCCEf6JlEPCp4uzDSNThfps=; fh=34P2Tn1w879pv2bKBkfpopDOpz7u/zrbLWZn3NlG648=; b=z/MFnfY6xAT1TKcIW7ArmQm4vxEadesvhywJtw9t73LbCe44NA0o7LyS/VTlB9yYS3 kKVfoFzfeiGWd7R4r1EpepRJuqT7DwAf1BEeSLvP+rREbpIcgelZVRbUZFzhVQwBrPqO Xwi2BMtgitz9uYZZMFqUSC8VMzph4zEeplomAo0w10cOQ8xvak3ofjGka/0tEUP9Mxsv Yt0fqvgps0WeM55Gc8mqfQjl7+amK+3QKzmB7KVK9cFF4lc5oOX8E179tx1U9LEIVZGI YDeGnSnx+4XAOJH3YFIhiX81q9W6WJDdUYWVUledmu73LDaZhhUVrCll9M1sfwL+gB4M ZpMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-162-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pe15-20020a056214494f00b0067a33b92192si8357967qvb.470.2023.11.29.04.28.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 04:28:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-162-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 87DF81C20C2D for ; Wed, 29 Nov 2023 12:28:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 487511DDCE; Wed, 29 Nov 2023 12:28:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none X-Original-To: linux-nfs@vger.kernel.org Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B6B31707; Wed, 29 Nov 2023 04:28:19 -0800 (PST) Received: from mail.maildlp.com (unknown [172.18.186.29]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4SgJCq3X9czB01N3; Wed, 29 Nov 2023 20:14:31 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id 6AE2C1400CA; Wed, 29 Nov 2023 20:28:15 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwAXBXVKLmdlCSKXAQ--.11947S2; Wed, 29 Nov 2023 13:28:14 +0100 (CET) Message-ID: Subject: Re: [PATCH v5 23/23] integrity: Switch from rbtree to LSM-managed blob for integrity_iint_cache From: Roberto Sassu To: Paul Moore Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, jmorris@namei.org, serge@hallyn.com, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, dhowells@redhat.com, jarkko@kernel.org, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com, mic@digikod.net, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, Roberto Sassu Date: Wed, 29 Nov 2023 13:27:51 +0100 In-Reply-To: References: <20231107134012.682009-24-roberto.sassu@huaweicloud.com> <17befa132379d37977fc854a8af25f6d.paul@paul-moore.com> <2084adba3c27a606cbc5ed7b3214f61427a829dd.camel@huaweicloud.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe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1UYxBIdaVFxhVjvjDU0xZFpf9x07UAkuxUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAQBF1jj5cNmwAFsg On Mon, 2023-11-20 at 16:06 -0500, Paul Moore wrote: > On Mon, Nov 20, 2023 at 3:16=E2=80=AFAM Roberto Sassu > wrote: > > On Fri, 2023-11-17 at 15:57 -0500, Paul Moore wrote: > > > On Nov 7, 2023 Roberto Sassu wrote: > > > >=20 > > > > Before the security field of kernel objects could be shared among L= SMs with > > > > the LSM stacking feature, IMA and EVM had to rely on an alternative= storage > > > > of inode metadata. The association between inode metadata and inode= is > > > > maintained through an rbtree. > > > >=20 > > > > Because of this alternative storage mechanism, there was no need to= use > > > > disjoint inode metadata, so IMA and EVM today still share them. > > > >=20 > > > > With the reservation mechanism offered by the LSM infrastructure, t= he > > > > rbtree is no longer necessary, as each LSM could reserve a space in= the > > > > security blob for each inode. However, since IMA and EVM share the > > > > inode metadata, they cannot directly reserve the space for them. > > > >=20 > > > > Instead, request from the 'integrity' LSM a space in the security b= lob for > > > > the pointer of inode metadata (integrity_iint_cache structure). The= other > > > > reason for keeping the 'integrity' LSM is to preserve the original = ordering > > > > of IMA and EVM functions as when they were hardcoded. > > > >=20 > > > > Prefer reserving space for a pointer to allocating the integrity_ii= nt_cache > > > > structure directly, as IMA would require it only for a subset of in= odes. > > > > Always allocating it would cause a waste of memory. > > > >=20 > > > > Introduce two primitives for getting and setting the pointer of > > > > integrity_iint_cache in the security blob, respectively > > > > integrity_inode_get_iint() and integrity_inode_set_iint(). This wou= ld make > > > > the code more understandable, as they directly replace rbtree opera= tions. > > > >=20 > > > > Locking is not needed, as access to inode metadata is not shared, i= t is per > > > > inode. > > > >=20 > > > > Signed-off-by: Roberto Sassu > > > > Reviewed-by: Casey Schaufler > > > > Reviewed-by: Mimi Zohar > > > > --- > > > > security/integrity/iint.c | 71 +++++-------------------------= ---- > > > > security/integrity/integrity.h | 20 +++++++++- > > > > 2 files changed, 29 insertions(+), 62 deletions(-) > > > >=20 > > > > diff --git a/security/integrity/iint.c b/security/integrity/iint.c > > > > index 882fde2a2607..a5edd3c70784 100644 > > > > --- a/security/integrity/iint.c > > > > +++ b/security/integrity/iint.c > > > > @@ -231,6 +175,10 @@ static int __init integrity_lsm_init(void) > > > > return 0; > > > > } > > > >=20 > > > > +struct lsm_blob_sizes integrity_blob_sizes __ro_after_init =3D { > > > > + .lbs_inode =3D sizeof(struct integrity_iint_cache *), > > > > +}; > > >=20 > > > I'll admit that I'm likely missing an important detail, but is there > > > a reason why you couldn't stash the integrity_iint_cache struct > > > directly in the inode's security blob instead of the pointer? For > > > example: > > >=20 > > > struct lsm_blob_sizes ... =3D { > > > .lbs_inode =3D sizeof(struct integrity_iint_cache), > > > }; > > >=20 > > > struct integrity_iint_cache *integrity_inode_get(inode) > > > { > > > if (unlikely(!inode->isecurity)) > > > return NULL; > > > return inode->i_security + integrity_blob_sizes.lbs_inode; > > > } > >=20 > > It would increase memory occupation. Sometimes the IMA policy > > encompasses a small subset of the inodes. Allocating the full > > integrity_iint_cache would be a waste of memory, I guess? >=20 > Perhaps, but if it allows us to remove another layer of dynamic memory > I would argue that it may be worth the cost. It's also worth > considering the size of integrity_iint_cache, while it isn't small, it > isn't exactly huge either. >=20 > > On the other hand... (did not think fully about that) if we embed the > > full structure in the security blob, we already have a mutex available > > to use, and we don't need to take the inode lock (?). >=20 > That would be excellent, getting rid of a layer of locking would be signi= ficant. >=20 > > I'm fully convinced that we can improve the implementation > > significantly. I just was really hoping to go step by step and not > > accumulating improvements as dependency for moving IMA and EVM to the > > LSM infrastructure. >=20 > I understand, and I agree that an iterative approach is a good idea, I > just want to make sure we keep things tidy from a user perspective, > i.e. not exposing the "integrity" LSM when it isn't required. Ok, I went back to it again. I think trying to separate integrity metadata is premature now, too many things at the same time. I started to think, does EVM really need integrity metadata or it can work without? The fact is that CONFIG_IMA=3Dn and CONFIG_EVM=3Dy is allowed, so we have the same problem now. What if we make IMA the one that manages integrity metadata, so that we can remove the 'integrity' LSM? So, no embedding the full structure in the security blob now, move integrity_inode_free() and integrity_kernel_module_request() to IMA, call integrity_iintcache_init() from IMA. EVM verification of new files would fail without IMA, but it would be the same now. Also, evm_verifyxattr() would only work with IMA, as it assumes that the latter creates integrity metadata and passes them as argument. Regarding the LSM order, I would take Casey's suggestion of introducing LSM_ORDER_REALLY_LAST, for EVM. Thanks Roberto