Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp85297rdh; Wed, 25 Oct 2023 17:15:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtZqvbHNRQW01yq2br+xSUUSM3jQbx8xMdjY0TOn8D0PL9DKnJ3GSjbfYeRvqSOJ7QHeuc X-Received: by 2002:a25:d10b:0:b0:d9a:c5f7:f848 with SMTP id i11-20020a25d10b000000b00d9ac5f7f848mr14567571ybg.63.1698279347106; Wed, 25 Oct 2023 17:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698279347; cv=none; d=google.com; s=arc-20160816; b=nMXY4kd7CQVkqXidUufJkT+s9DvKDBXdBeRxHCnqYMChWrrg03EPXP28DlvMK32BZ5 Kx5i+MGjeewrjcOl1GnwoqWplCYlhv5xTH/PyiHjOtvzr6eyT8hm4xgXVOda/gSJMyMO ZnbDLyG50bQcWTcnUc9GTkOqj1NOnBxWKH1kTaM2S7GsTGCH6t93L1M/pIx63KtjIsPu NIi42k5IuoEbSZpoB53JNsL1mvY7ZGBQgTB48PlIh6Tnc+LOF/9h3DM16YUsaHxc3fpi jd3yqYLS6sjZ11y2mJTnJ0gIj0r3R4u9Q1YUEN02OBVRITs8n3PM9dFvZ0+FBEhJm1mi x97Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-filter; bh=Ayg5mamt8HCVNY+t4GHPswTJfJb2ciVUg3Q8qdqL6WE=; fh=fAqrlMYH1fEHmaaZ3DhbJc1a1C2SUC29hk9YBohK+zY=; b=03Be6ZRIJuCH3KbudZQKG+nojowdChcC3b3SPFASSS9sg6AIjNAzALKJuymOVMVT2x MZYawI4wZCP/QjTBH5b6erxce2hrFKobUM7D/JkndVtgR2lYfUklehhZOXseE0tvIzZ/ kY69UQBOrs5TMctfnlogkzO3TTYstd83jALM5xam/7TufRt7XfTS4Z/JIxto0SiARXJt Q7uyK7h8tGOdjYAmE4aUT9K56q9iU+vpCv4YWSvs2ryx1qlF+hJGSRywJp5dfrhW3mz6 PbC8GoXW6Lt18CC+pegWiBg8Ha7S+TpeRn9jU7slqNVw+TOTeggYa/SW8jwNg+Cug+ou 7liQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ovNPjhYA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id 2-20020a250f02000000b00da0879c90aesi2837558ybp.703.2023.10.25.17.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 17:15:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linux.microsoft.com header.s=default header.b=ovNPjhYA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 288CF81E9F7D; Wed, 25 Oct 2023 17:15:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230395AbjJZAPa (ORCPT + 99 others); Wed, 25 Oct 2023 20:15:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjJZAP2 (ORCPT ); Wed, 25 Oct 2023 20:15:28 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE5F410E; Wed, 25 Oct 2023 17:15:26 -0700 (PDT) Received: from [10.137.106.151] (unknown [131.107.159.23]) by linux.microsoft.com (Postfix) with ESMTPSA id DC7A120B74C0; Wed, 25 Oct 2023 17:15:25 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DC7A120B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1698279326; bh=Ayg5mamt8HCVNY+t4GHPswTJfJb2ciVUg3Q8qdqL6WE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ovNPjhYAJE3PiwQsqnWOT8BVxfey4Ku6txfhhlOv+IbofSxRoW2I/UfuChbVmptfZ OoqUvAEgfqDQMX460M6f1L4bM/7ro6HymGSEFoD4BIoEM+SpVEJLLY/mlmG8bdt1Cy XGfyJLNcmoePkK24YClYdoBvr20aQVIi2uz0YWJo= Message-ID: <84f25e00-3a3a-419f-baea-50d64a1d5575@linux.microsoft.com> Date: Wed, 25 Oct 2023 17:15:25 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC v11 3/19] ipe: add evaluation loop Content-Language: en-US To: Paul Moore , corbet@lwn.net, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, tytso@mit.edu, ebiggers@kernel.org, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, eparis@redhat.com Cc: linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@redhat.com, audit@vger.kernel.org, roberto.sassu@huawei.com, linux-kernel@vger.kernel.org, Deven Bowers References: <1696457386-3010-4-git-send-email-wufan@linux.microsoft.com> From: Fan Wu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 25 Oct 2023 17:15:44 -0700 (PDT) On 10/23/2023 8:52 PM, Paul Moore wrote: > On Oct 4, 2023 Fan Wu wrote: >> >> IPE must have a centralized function to evaluate incoming callers >> against IPE's policy. This iteration of the policy for against the rules >> for that specific caller is known as the evaluation loop. >> >> Signed-off-by: Deven Bowers >> Signed-off-by: Fan Wu ... >> --- >> security/ipe/Makefile | 1 + >> security/ipe/eval.c | 96 +++++++++++++++++++++++++++++++++++++++++++ >> security/ipe/eval.h | 24 +++++++++++ >> 3 files changed, 121 insertions(+) >> create mode 100644 security/ipe/eval.c >> create mode 100644 security/ipe/eval.h > > ... > >> diff --git a/security/ipe/eval.c b/security/ipe/eval.c >> new file mode 100644 >> index 000000000000..5533c359bbeb >> --- /dev/null >> +++ b/security/ipe/eval.c >> @@ -0,0 +1,96 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Copyright (C) Microsoft Corporation. All rights reserved. >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include "ipe.h" >> +#include "eval.h" >> +#include "policy.h" >> + >> +struct ipe_policy __rcu *ipe_active_policy; >> + >> +/** >> + * evaluate_property - Analyze @ctx against a property. >> + * @ctx: Supplies a pointer to the context to be evaluated. >> + * @p: Supplies a pointer to the property to be evaluated. >> + * >> + * Return: >> + * * true - The current @ctx match the @p >> + * * false - The current @ctx doesn't match the @p >> + */ >> +static bool evaluate_property(const struct ipe_eval_ctx *const ctx, >> + struct ipe_prop *p) >> +{ >> + return false; >> +} >> + >> +/** >> + * ipe_evaluate_event - Analyze @ctx against the current active policy. >> + * @ctx: Supplies a pointer to the context to be evaluated. >> + * >> + * This is the loop where all policy evaluation happens against IPE policy. >> + * >> + * Return: >> + * * 0 - OK >> + * * -EACCES - @ctx did not pass evaluation. >> + * * !0 - Error >> + */ >> +int ipe_evaluate_event(const struct ipe_eval_ctx *const ctx) >> +{ >> + bool match = false; >> + enum ipe_action_type action; >> + struct ipe_policy *pol = NULL; >> + const struct ipe_rule *rule = NULL; >> + const struct ipe_op_table *rules = NULL; >> + struct ipe_prop *prop = NULL; >> + >> + rcu_read_lock(); >> + >> + pol = rcu_dereference(ipe_active_policy); >> + if (!pol) { >> + rcu_read_unlock(); >> + return 0; >> + } >> + >> + if (ctx->op == IPE_OP_INVALID) { >> + rcu_read_unlock(); >> + if (pol->parsed->global_default_action == IPE_ACTION_DENY) >> + return -EACCES; > > Assuming that the RCU lock protects @pol, shouldn't it be held until > after the global_default_action comparison? > Yes for this part the unlock should be moved after the comparison. Thanks for spotting this. >> + return 0; >> + } >> + >> + rules = &pol->parsed->rules[ctx->op]; >> + >> + list_for_each_entry(rule, &rules->rules, next) { >> + match = true; >> + >> + list_for_each_entry(prop, &rule->props, next) { >> + match = match && evaluate_property(ctx, prop); > > The @match variable will always be true on the right side above, or am > I missing something? > Yes the "match &&" are completely unnecessary. I will remove them. -Fan >> + if (!match) >> + break; >> + } >> + >> + if (match) >> + break; >> + } >> + >> + if (match) >> + action = rule->action; >> + else if (rules->default_action != IPE_ACTION_INVALID) >> + action = rules->default_action; >> + else >> + action = pol->parsed->global_default_action; >> + >> + rcu_read_unlock(); >> + if (action == IPE_ACTION_DENY) >> + return -EACCES; >> + >> + return 0; >> +} > > -- > paul-moore.com