Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp216065rdf; Mon, 20 Nov 2023 23:58:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDqEcprApMK0wAmU5qgOAZelN8NLVz0L2UgY6CmupsBQe7uNM4fJaE8mmF3opqKAmjctH7 X-Received: by 2002:a05:6a21:1487:b0:187:db8b:e3e8 with SMTP id od7-20020a056a21148700b00187db8be3e8mr8820861pzb.39.1700553533322; Mon, 20 Nov 2023 23:58:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700553533; cv=none; d=google.com; s=arc-20160816; b=SwnEeVPuiIhFcwpzy4BJygG4rBwmleg65J1V6XO7f2htkxWy90SvX6WaVxII1ntDtq OuS5pf4ziQjn0z5NYrjZpsa2siq2qE4L4SKGzO4SzNrzQQhFcH786NB3VVgiC5RkIuBt 9bAq3Q44YtC7GnOmRsMqeSx0UwiupQTRznKpi30ji9stH03fP1e6kuADRIMITU4axFM5 iLMr420SyZqB95gshJSxS0FyeJ6tbjlS6cPgEnBgcG5wOBRTcdjTMswYcbWEZ3aml2t3 MGYjTRiYlhgnTDQ9cHfPBsrVILZ+godhZTNlPMQ0Pc14Z6+BNzA7868EeMMeyOGeJfrr wh+Q== 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=0nxSe/a4bXL3nVBpQ9/Y2zFL+iq/u5AFFRXaXWrStLg=; fh=lNe9QOYNu+8zj/ZmTgUtLRLtCnnPNSxVEeh58kZX04A=; b=oyCnk7f5M2IvVcjtQcAf5oN9GZyEbiyVchU5RfZd+04lWVYw7afzvMHXuth8FBI+y8 hq5v1NGrKLnAVbbKomjVwrdIK6TVnjAG4RJvy/n8lG6xPKyWMet0w28p/O38Vh2l/G1G fMCq6y+f2v42Iu5PMan23L0NlrNnvWAqhc/2Xvrqr+CajF43jgIj53AQ5CbEkSlKElQR 9Dj8SW+MwjgKcFgdu1T5i0rFfafGwDzcLkiXoFsYNBr0Pn6NuAEuwanN4mEA5jAr1Jgs B56L/VIZ6EFbsAJ1zRABAw9R9jIfj9q8bE8xZMx7JykObH4WsuBdmr2FWReyrNn0kzMD p6IQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-3-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m9-20020a170902db0900b001b8b4330585si10202571plx.510.2023.11.20.23.58.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 23:58:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-3-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 303FEB2132C for ; Tue, 21 Nov 2023 07:58:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B93DE374D1; Tue, 21 Nov 2023 07:58:48 +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 A090CC3; Mon, 20 Nov 2023 23:58:43 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4SZGcc6rRPz9y5Z0; Tue, 21 Nov 2023 15:45:04 +0800 (CST) Received: from [127.0.0.1] (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwD35HQHY1xldiUUAQ--.11542S2; Tue, 21 Nov 2023 08:58:13 +0100 (CET) Message-ID: <884eb5167283c7ce0604b3dae9807d99b661eff8.camel@huaweicloud.com> Subject: Re: [PATCH v6 25/25] security: Enforce ordering of 'ima' and 'evm' LSMs From: Roberto Sassu To: Casey Schaufler , 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, paul@paul-moore.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, 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: Tue, 21 Nov 2023 08:57:56 +0100 In-Reply-To: <24a9f95d-6a28-47d3-a0cf-48e1698e2445@schaufler-ca.com> References: <20231120173318.1132868-1-roberto.sassu@huaweicloud.com> <20231120173318.1132868-26-roberto.sassu@huaweicloud.com> <24a9f95d-6a28-47d3-a0cf-48e1698e2445@schaufler-ca.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-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2jsIE c7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07UAkuxUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAIBF1jj5atPwAAs4 X-CFilter-Loop: Reflected On Mon, 2023-11-20 at 16:50 -0800, Casey Schaufler wrote: > On 11/20/2023 9:33 AM, Roberto Sassu wrote: > > From: Roberto Sassu > >=20 > > The ordering of LSM_ORDER_LAST LSMs depends on how they are placed in t= he > > .lsm_info.init section of the kernel image. > >=20 > > Without making any assumption on the LSM ordering based on how they are > > compiled, enforce that ordering at LSM infrastructure level. > >=20 > > Signed-off-by: Roberto Sassu > > --- > > security/security.c | 25 +++++++++++++++++++++++++ > > 1 file changed, 25 insertions(+) > >=20 > > diff --git a/security/security.c b/security/security.c > > index 351a124b771c..b98db79ca500 100644 > > --- a/security/security.c > > +++ b/security/security.c > > @@ -263,6 +263,18 @@ static void __init initialize_lsm(struct lsm_info = *lsm) > > } > > } > > =20 > > +/* Find an LSM with a given name. */ > > +static struct lsm_info __init *find_lsm(const char *name) > > +{ > > + struct lsm_info *lsm; > > + > > + for (lsm =3D __start_lsm_info; lsm < __end_lsm_info; lsm++) > > + if (!strcmp(lsm->name, name)) > > + return lsm; > > + > > + return NULL; > > +} > > + > > /* > > * Current index to use while initializing the lsm id list. > > */ > > @@ -333,10 +345,23 @@ static void __init ordered_lsm_parse(const char *= order, const char *origin) > > =20 > > /* LSM_ORDER_LAST is always last. */ > > for (lsm =3D __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > + /* Do it later, to enforce the expected ordering. */ > > + if (!strcmp(lsm->name, "ima") || !strcmp(lsm->name, "evm")) > > + continue; > > + >=20 > Hard coding the ordering of LSMs is incredibly ugly and unlikely to scale= . > Not to mention perplexing the next time someone creates an LSM that "has = to be last". Uhm, yes, not the best solution. > Why isn't LSM_ORDER_LAST sufficient? If it really isn't, how about adding > and using LSM_ORDER_LAST_I_REALLY_MEAN_IT* ? I don't know if the order at run-time reflects the order in the Makefile (EVM is compiled after IMA). If it does, there is no need for this patch. > Alternatively, a declaration of ordering requirements with regard to othe= r > LSMs in lsm_info. You probably don't care where ima is relative to Yama, > but you need to be after SELinux and before evm. lsm_info could have=20 > must_precede and must_follow lists. Maybe a must_not_combine list, too, > although I'm hoping to make that unnecessary.=20 Uhm, I agree. Will think about how to make it more straightforward. > And you should be using LSM_ID values instead of LSM names. Ok. Thanks Roberto > --- > * Naming subject to Paul's sensibilities, of course. >=20 > > if (lsm->order =3D=3D LSM_ORDER_LAST) > > append_ordered_lsm(lsm, " last"); > > } > > =20 > > + /* Ensure that the 'ima' and 'evm' LSMs are last and in this order. *= / > > + lsm =3D find_lsm("ima"); > > + if (lsm) > > + append_ordered_lsm(lsm, " last"); > > + > > + lsm =3D find_lsm("evm"); > > + if (lsm) > > + append_ordered_lsm(lsm, " last"); > > + > > /* Disable all LSMs not in the ordered list. */ > > for (lsm =3D __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > if (exists_ordered_lsm(lsm))