Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2516109rdb; Mon, 20 Nov 2023 13:06:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFm8+OhJqb3JEQnZXsd5Hd5TF0vT5UIdAACWdn0BsT83i4vhQ1N+NwhqIAg/+y9csDoGvx1 X-Received: by 2002:a05:6a20:3d84:b0:187:94ca:2a91 with SMTP id s4-20020a056a203d8400b0018794ca2a91mr7116366pzi.39.1700514398147; Mon, 20 Nov 2023 13:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700514398; cv=none; d=google.com; s=arc-20160816; b=PtYabXtJiDwyMv0ZOyMGsH1YSqm1jXk32AXOLI0uydtFNVgNySj/8Ju0cIIEWgplvV yKwSmzqFrZOTO7/BrrB2CGTb5Dzc0rsi9DwRLNhHe/eF30fR9CJi9iPZG1qOLYgd+n9M 84EGnBkwDFA3rZk2xk0qekligdCYuTgvcXsB/osXqG5V9abehhwxJxVH00m0a/TcQNtQ 7nT6oucBAsCx04btiRMbICLxPChUcd+6k6K6mlB/cAcrG+nti0kvn9h8NukNQ9X+rL3x kn3cQpbP2quPQsJDNq3Sb/ruzTNKHVxoK6El4JJGE7tzALNZhG3Q1gUUhChZStiRECmx 9D4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=NG2FEhp12pFkNfvVzutmm+LjhzXXRny+ltBXXG6QNR4=; fh=s9Iuyz1kEJMk2gmQIedHGVeqIbfYEjpayR1DQWj8YhI=; b=aJNmfDNeiNeAtQjHV2hjWhTW5Mk9KzAcSHYSyz0dt41ejljMMVY+tQtpZ1Xff48ONU XhnRGCzGSwZIlvhuNiyJxDyCY8Dun210wh0waoJjRiyDpeHOhpcy4j2Aa94WM2pJJcXf VngIofoQzpiqnG1Gb8P/LIVBopQnpQiNoi/wNPBgwKs+kQX/o9nRZ7lgwQO1gYAIIR6E as1TxvCm7Jfrz4RV44QqyHGl2ATRJzYYHzKZ6SKr207YtG+BbHwSiMAiFI6XixH13L6+ FSOFZXlYtwCIgRBJ32q7O2+HrhMXSJ8nlhFTYFbI4KI81Gb0O475SvLVfcPEnpQRYDw+ MwfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=YLhyT6Rm; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id z1-20020a056a00240100b006cbba705c9esi529964pfh.207.2023.11.20.13.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 13:06:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=YLhyT6Rm; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4992E808A372; Mon, 20 Nov 2023 13:06:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230310AbjKTVG1 (ORCPT + 99 others); Mon, 20 Nov 2023 16:06:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbjKTVG0 (ORCPT ); Mon, 20 Nov 2023 16:06:26 -0500 Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B47BE7 for ; Mon, 20 Nov 2023 13:06:21 -0800 (PST) Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-5caf387f2aaso9465247b3.3 for ; Mon, 20 Nov 2023 13:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1700514380; x=1701119180; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NG2FEhp12pFkNfvVzutmm+LjhzXXRny+ltBXXG6QNR4=; b=YLhyT6RmzMxgdwWF3OzA1dbTAz8GYwlqdzU9jExIzFo7f7lyo2lc/g5s8M1FPVxNVx 9xH5Qe/wVsv58MHQpjcvW3LKQcQ5vIb9Aa73yrI/rkqK7MVSaCFxHqne8L13lT5gfTNd jrz2ZdVN1Qe3itctMb74xkKwKI6nJ4cxYD4hmugMHvP5aWDW4emrejI+By1/ZbG0f7JT cFXvDnsb5rYwIE/fidXu7jWV6ZgD3xHcJYQin5mUIyp4H3oCK5n4tdFaaQXQEZFpoH+G SJuLfuXl8Rod2tCYybo07Z13jXhOFKBICD9TAWYrNxzyLdOcfmQ9oJDeTWht/WBRaKY0 ufgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700514380; x=1701119180; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NG2FEhp12pFkNfvVzutmm+LjhzXXRny+ltBXXG6QNR4=; b=SGGFE5EfhkxmuFSsqVmXM2CU/LnEz5YxYB548eWG+9MQwrU7ZYDQPWuH5sTvwevz4g ssrJgY1aExJPqqwP1aoyu6cWVclzyi4PLPYELfvXVjOizRgysH7BmfBDGNhTmTow/vZK gIASLXZHIYzz8gE1HdtXCVXTQPhM79oYC1elF+7S5pgnbaNp+RDuZfXLp8rYdft5PMRu Oe1Af6ioNCUFgeScu7SpNLbqksIcFI0/8Bsd6r6AxC59bHtHU6W5igLv3Mgquc3F7ea2 NArL5+f0MHfmqOPfvOqQzVC9JHHFYS6pBGEn6wQ/+wx2xCQCZu7uGU1arz381x1n/Us0 3ZFw== X-Gm-Message-State: AOJu0YwPxszv53q0Nr0ghTD77qc7TH3q5kcPGrl0ALe+yFCcmcprXvCk 246uCTBwieUP3PivJHflxiOn6bMwJKGigQh6X0Pi X-Received: by 2002:a81:ac17:0:b0:5ca:7629:7a9a with SMTP id k23-20020a81ac17000000b005ca76297a9amr4086414ywh.37.1700514380344; Mon, 20 Nov 2023 13:06:20 -0800 (PST) MIME-Version: 1.0 References: <20231107134012.682009-24-roberto.sassu@huaweicloud.com> <17befa132379d37977fc854a8af25f6d.paul@paul-moore.com> <2084adba3c27a606cbc5ed7b3214f61427a829dd.camel@huaweicloud.com> In-Reply-To: <2084adba3c27a606cbc5ed7b3214f61427a829dd.camel@huaweicloud.com> From: Paul Moore Date: Mon, 20 Nov 2023 16:06:09 -0500 Message-ID: Subject: Re: [PATCH v5 23/23] integrity: Switch from rbtree to LSM-managed blob for integrity_iint_cache To: Roberto Sassu 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 13:06:27 -0800 (PST) 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: > > > > > > Before the security field of kernel objects could be shared among LSM= s with > > > the LSM stacking feature, IMA and EVM had to rely on an alternative s= torage > > > of inode metadata. The association between inode metadata and inode i= s > > > maintained through an rbtree. > > > > > > Because of this alternative storage mechanism, there was no need to u= se > > > 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 t= he > > > 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 blo= b for > > > the pointer of inode metadata (integrity_iint_cache structure). The o= ther > > > reason for keeping the 'integrity' LSM is to preserve the original or= dering > > > 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 inod= es. > > > 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 operati= ons. > > > > > > 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 =3D { > > > + .lbs_inode =3D 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 ... =3D { > > .lbs_inode =3D 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? 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. > 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 (?). That would be excellent, getting rid of a layer of locking would be signifi= cant. > 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. 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. -- paul-moore.com