Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4501762rdb; Fri, 15 Sep 2023 04:26:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8y5Hy8Pv7TmOXPwm6kOY+jGaePP9OKh6yJ/RfmnqYIidvqdHmE1mrrMma5fTKZB5zz09d X-Received: by 2002:a17:902:748c:b0:1c0:aa07:1792 with SMTP id h12-20020a170902748c00b001c0aa071792mr1145347pll.36.1694777194696; Fri, 15 Sep 2023 04:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694777194; cv=none; d=google.com; s=arc-20160816; b=leOqNjodscNB4M1Oj3WYcKMX10+d0uqNb6rxdl45rx49ZhngrYIcOhA2W548xYnFJs ad/EFVk3/cJ9Oidwy74eqDxcjRhhMeUyGJql2LNXi30vXywZ8kzD6rYutdMM+cf5sOP/ YFmHFqtd1gPwItYlZ3ZtcFII7dZ4g6IpwIBVmbFDkBJx6Dydvu2OlyB//wuBJav4BiBt Eu2CCVpMDi2DVp2JQm4CDYVnO1TUOAQEF+msWApdEiVpFs+UXcbWc1deYsQ0Ht8z3tST uqphqn+thhAJ7Se84F9LtYOZVw10EUXi8+DM/x5Rqgex5g6y3ZbbIv/jZQ3/ihLNYBWt DaiQ== 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=ntVhHtvpz9S1qT/WOFCFrZCTVzP5mUVcFOtGZvEKgok=; fh=5d2xhgJtXEk0WjSfSSUs99kj3vm7UTbC5YS/jbK/OFI=; b=C3JsQZPbWME6ZNJjUu+Geu44MD/z5q7dGQlOYx7iZjcnQioH0XgsmFeD/jR4xV5r0Y UtJb+eLO+WVXOvn0BiL8889LDO0d6S/Khd+pN2Wz/Swg/WZE0DwWirLKOQudP/O34YnM v7TnJJUwfI1iwFCg5yPhVCrFJyytXVBdVNIFOyumMoslrDMcwplTEUo54JmhLWyiPitV WNgdKLspX+wLRrqQqCrTM88vlEmNKuwSbY7roCO5swODeN/8A6M+RwU3LkQCDhdjeB88 +w7kmkES0tyK/aow1qJDy/Y6g7ym7wcN1tiH/QwPe/tdCkxw3JYJAjvej3HW0ES3tmpl Gu4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l20-20020a170903005400b001bf1d1d99besi3138038pla.423.2023.09.15.04.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 04:26:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 4D7F383711B9; Fri, 15 Sep 2023 02:41:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233830AbjIOJl2 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 15 Sep 2023 05:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233872AbjIOJlT (ORCPT ); Fri, 15 Sep 2023 05:41:19 -0400 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556F1271C; Fri, 15 Sep 2023 02:40:31 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4Rn84T1Yt9z9xqnp; Fri, 15 Sep 2023 17:28:09 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwAHXrlkJgRlA3tfAA--.51551S2; Fri, 15 Sep 2023 10:40:02 +0100 (CET) Message-ID: Subject: Re: [PATCH v3 25/25] integrity: Switch from rbtree to LSM-managed blob for integrity_iint_cache From: Roberto Sassu To: Stefan Berger , 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, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, dhowells@redhat.com, jarkko@kernel.org, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, Roberto Sassu Date: Fri, 15 Sep 2023 11:39:44 +0200 In-Reply-To: <82486de4-2917-afb6-2ae3-6ea7f1346dc0@linux.ibm.com> References: <20230904133415.1799503-1-roberto.sassu@huaweicloud.com> <20230904134049.1802006-6-roberto.sassu@huaweicloud.com> <82486de4-2917-afb6-2ae3-6ea7f1346dc0@linux.ibm.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: GxC2BwAHXrlkJgRlA3tfAA--.51551S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Kr15tFWxGr47CFW7try7KFg_yoW8Kr4DpF 4SgayUJw1Dtryvkr4vvFW5urWSgayjgayUWrn0k3WkZ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OCKED,SPF_HELO_NONE,SPF_NONE 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 (howler.vger.email [0.0.0.0]); Fri, 15 Sep 2023 02:41:34 -0700 (PDT) On Tue, 2023-09-12 at 12:19 -0400, Stefan Berger wrote: > On 9/4/23 09:40, Roberto Sassu wrote: > > From: Roberto Sassu > > > > 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. > > > > 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. Thus, request from the 'integrity' LSM a > > space in the security blob for the pointer of inode metadata > > (integrity_iint_cache structure). > > > > Prefer this 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 > > --- > > > > @@ -145,10 +91,8 @@ static void integrity_inode_free(struct inode *inode) > > if (!IS_IMA(inode)) > > return; > > I think you can remove this check !IS_IMA()  as well since the next > function called here integrity_iint_find() already has this check: > > struct integrity_iint_cache *integrity_iint_find(struct inode *inode) > { >         if (!IS_IMA(inode)) >                 return NULL; > >         return integrity_inode_get_iint(inode); > } I agree, thanks! Roberto > > > > - write_lock(&integrity_iint_lock); > > - iint = __integrity_iint_find(inode); > > - rb_erase(&iint->rb_node, &integrity_iint_tree); > > - write_unlock(&integrity_iint_lock); > > + iint = integrity_iint_find(inode); <-------------- > > + integrity_inode_set_iint(inode, NULL); > > > > iint_free(iint); > > }