Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2064257rdb; Mon, 20 Nov 2023 00:17:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGs8dflKSw5TkK0soVTHy4tkIZSK7z6wFZgy++9cpLC0tOaXARPVmrTlMH7DkY57SCilExX X-Received: by 2002:aa7:9310:0:b0:6c3:3213:2d17 with SMTP id cz16-20020aa79310000000b006c332132d17mr4735983pfb.29.1700468268634; Mon, 20 Nov 2023 00:17:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700468268; cv=none; d=google.com; s=arc-20160816; b=PnMPMznSzsz7X2FM2m0x1sXMWR0odVQvcRggvlvtzj4TLJM2Rd2KubAFgIVsRYiwHG ZA2b/t71pxe52vCOliwxxjWT8UEnm3Ss6JXiaNOXrVSXHZTGFJ63A0WbrqGLwsKzzxF8 5fMzYx/op39AUnwUfiNOUAIwIHdq31153Ci2BcsUVphFxzLJl6bQyefzbB/xX2V6mLq0 8f8lEMPr1uajys3NJV8LOYg9cPF+gsdwW97ouXWMfgnH5DUKlrQsP9JSE0oRHFdjffM4 WaHKF9hP7H+Tm5tPWF/GK/sturXiiDe4eEp67mN6dkFv/t1bbcpSSG+KzllLfZGHkSac +oog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=nSHFghhauVqavz3XOGiOvT1gLTXS+tZa23jyw7jf6oU=; fh=KVlUtu08b7STLqjYhUdApMrqqLOdwdVjJOubj6I/Y0Y=; b=gV92XQnCf+rdcZIspz0yQdzoljQrC5+ddeGcgaVPi6wnDSk+pBE1mW/Wa0Puqjoa0M 5cYfB/M2gdcRbDhB5gOtR54dc++dnsLv2oF0XOTKPHwh1zhQAY+eBzk847dk5PQyne1S XU4VxXMmrm5LoPQqyf79+i8nqcyJc5kUkxiGKBX/Q4CtHbKFzgmPQgQNc45eyIvsJJfV 6j9ytUzU4/zn8YyktdAlm76fvWOUyjgNtLOAdHXGlKJW//Vg/BkAmj6QHlz0igeVz6BW s7tqYSEXV6lqyng+i4H2sIty9RRPO5uAlqvmp68rT+6fNs85F8ZS9RnLYYlurGIgCLEv WYZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bq20-20020a056a02045400b005b7dd1e13e7si8430199pgb.556.2023.11.20.00.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 00:17:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9D1F0802B079; Mon, 20 Nov 2023 00:17:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232168AbjKTIRC convert rfc822-to-8bit (ORCPT + 99 others); Mon, 20 Nov 2023 03:17:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232183AbjKTIRA (ORCPT ); Mon, 20 Nov 2023 03:17:00 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E9EE3; Mon, 20 Nov 2023 00:16:56 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4SYg0Z1Pc1z9v7GV; Mon, 20 Nov 2023 16:00:14 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwDHxV_LFVtlN1ABAQ--.398S2; Mon, 20 Nov 2023 09:16:26 +0100 (CET) Message-ID: <2084adba3c27a606cbc5ed7b3214f61427a829dd.camel@huaweicloud.com> Subject: Re: [PATCH v5 23/23] integrity: Switch from rbtree to LSM-managed blob for integrity_iint_cache From: Roberto Sassu To: Paul Moore , 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 Cc: 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: Mon, 20 Nov 2023 09:16:09 +0100 In-Reply-To: <17befa132379d37977fc854a8af25f6d.paul@paul-moore.com> References: <20231107134012.682009-24-roberto.sassu@huaweicloud.com> <17befa132379d37977fc854a8af25f6d.paul@paul-moore.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 X-CM-TRANSID: GxC2BwDHxV_LFVtlN1ABAQ--.398S2 X-Coremail-Antispam: 1UD129KBjvJXoWxAF17Kw1kuFWrWr45ur1kGrg_yoWrJr43pF W3Ka47Jr1kXFyI9rn2vF45uFWSgFWSgFWUGwn0k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WL_BLOCKED,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-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 00:17:02 -0800 (PST) On Fri, 2023-11-17 at 15:57 -0500, Paul Moore wrote: > On Nov 7, 2023 Roberto Sassu wrote: > > > > Before the security field of kernel objects could be shared among LSMs 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. > > > > Because of this alternative storage mechanism, there was no need to use > > disjoint inode metadata, so IMA and EVM today still share them. > > > > With the reservation mechanism offered by the LSM infrastructure, the > > 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. > > > > Instead, request from the 'integrity' LSM a space in the security blob 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. > > > > Prefer reserving space for a pointer to allocating the integrity_iint_cache > > structure directly, as IMA would require it only for a subset of inodes. > > Always allocating it would cause a waste of memory. > > > > 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 would make > > the code more understandable, as they directly replace rbtree operations. > > > > Locking is not needed, as access to inode metadata is not shared, it is per > > inode. > > > > 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(-) > > > > 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; > > } > > > > +struct lsm_blob_sizes integrity_blob_sizes __ro_after_init = { > > + .lbs_inode = sizeof(struct integrity_iint_cache *), > > +}; > > 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: > > struct lsm_blob_sizes ... = { > .lbs_inode = sizeof(struct integrity_iint_cache), > }; > > struct integrity_iint_cache *integrity_inode_get(inode) > { > if (unlikely(!inode->isecurity)) > return NULL; > return inode->i_security + integrity_blob_sizes.lbs_inode; > } 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? 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 (?). 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. Thanks Roberto