Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32848591rwd; Fri, 7 Jul 2023 23:46:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlGpSKlMXInqqAz0EZKslUtJYnei8KbrXDJosz0W8YB1iP4ZKJv/4YK7QhejHF7tgoVwkORD X-Received: by 2002:a05:6358:9999:b0:134:c859:d32a with SMTP id j25-20020a056358999900b00134c859d32amr11090945rwb.25.1688798774819; Fri, 07 Jul 2023 23:46:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688798774; cv=none; d=google.com; s=arc-20160816; b=oWsxudRCatSRNi4s+7kR/mKgwtUIQsWWKWZ1I6D7766ynpahpSnsmfqi5D5VKl56Qt eLY3BpuBnCpPvEQfoPIbaTRvzuPrWNbyFKk5AVO0NznbCZRsDLoZ3i6nGGaWV3lVOxOO FEsQ3uxbafTfU9L7bBMeeRqPGiL4xXD2JsMgCR/etgYQC/t8jEhwky3mQEC2zxsi8J1b RDz6XYJLtRrqE5g9UQxxbL6oBUBOTO0fqpxX7klpV5zUKtW54Eog6stfMVuoFC5YGv0J CbS3kYHGkSx/lAFPhPPbg4SlTqz1bfq021gh3TuKCWp4OX+NUP/r4WyIWl3VEhXZaRs1 r81A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:subject:cc:to:from :message-id:date:dkim-signature; bh=Pr9IRZWW9eKpjkAEIe/1R+NHyAjULaMI0VUp/S3+Lu8=; fh=Vmgb78f+UWtIut1Oluhwx2oDAe4UZFJl5iee0zHKAXI=; b=hkehfMpJqc0uE7nx+jRZ1r+bDWELVsyMUwZx/DSsclaRahb+shBjoRi9f9JGVL9Ka3 JSqnym2N+q04+FZmyrlCwE0UdxYLmyJV4MLg95q8933nAJe+vlY8NfKa8WP/U7eYuFoK +lbfKsZkJ+97/FiTEjzCGkRieOKlRVc/M/+yLcfmySgNKblv30DfXoTXSEpQU8HlLRAd bzKiC/p5hV8iVsgWHMAgR9IMbstSr/1Eqol5SNVMDus1PC7hPlpKGLFfqMLeotwO7HFA 9wkLIGkO5I1wXs9SHv87RyiBHV7eMTlaon2ypjqd455VJzQXMb4RJ56p7LohMe8OtBl4 IqDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=cnEGslyQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f7-20020a056a001ac700b0064d56036aeasi4452352pfv.255.2023.07.07.23.46.02; Fri, 07 Jul 2023 23:46:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=cnEGslyQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233042AbjGHFhd (ORCPT + 99 others); Sat, 8 Jul 2023 01:37:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232904AbjGHFhL (ORCPT ); Sat, 8 Jul 2023 01:37:11 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6101FEF for ; Fri, 7 Jul 2023 22:36:58 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id 6a1803df08f44-635f1c7412cso17262846d6.0 for ; Fri, 07 Jul 2023 22:36:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1688794617; x=1691386617; h=in-reply-to:references:subject:cc:to:from:message-id:date:from:to :cc:subject:date:message-id:reply-to; bh=Pr9IRZWW9eKpjkAEIe/1R+NHyAjULaMI0VUp/S3+Lu8=; b=cnEGslyQpdnBNLSSp1rxXhTSSkhDwfqUSx/Ul9J71t2DK99oYfA/K6u/Ej+Hv3Wq/r jUDFg555SvEL3MsR4lk83PktHqF36QcKnjNP/seQerubrhFtJsn4xCiIgC5HO2UMbiT0 vZAKIKsOjeVtV2JxdN6AALNiDj5ylJgsA2FNCNYuWdqfgnQZBiCTwnHSC2xytauHOuCD ow1E4PvHNMKk6S17+7mrFKmMbQJDzpiaQVbqJcv1af80ac280QUIPZTXrfcRx2Y56eWU f7so5MIVQigRRgcM7IapiXZH+ltrnfRoS3ghDhatYUcW2hsq+J0Q8I3Pyx0wwDeKH5m4 Cvcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688794617; x=1691386617; h=in-reply-to:references:subject:cc:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Pr9IRZWW9eKpjkAEIe/1R+NHyAjULaMI0VUp/S3+Lu8=; b=ZqnrFfj4Mp3FiQsYwevFR5taGNitfJWO8vsagwWnVMuhly1bxSBUbusG7G7PVXsN9V gmipwiiF8kYQRPTLr2Ovy36W/k6BggmCDue3+sO+JDTurUSwP4lc8WDH9QjCjI/JEtI8 7yn5TeGKWWT7zCF8hDxA2Ic/4UxBMQr0m80x9d6htzMq8BsZGRm4eXDOntC1IR+NQ2Mj F2/L5v8UoJIkiGYV6BXvO64OJ432pzWpRx+GFJnPdLBashtNVNdCYrFWX79VqdTHTXwt FccsrGvVuxiLSYTJuNkVhhD31OEhdk2cKcw6u5hdiZqQXPzeSBUw85Hv168LwrV/Q8Vr HNaQ== X-Gm-Message-State: ABy/qLYGh/AYX+KQIgHgD0OlWL8W3CeipFSkK5z7l8oiS5oO94DeUJOj eu7tdP8Xf5XrTZLbdhQwwnMs X-Received: by 2002:a0c:dc01:0:b0:636:836e:8064 with SMTP id s1-20020a0cdc01000000b00636836e8064mr6540486qvk.63.1688794616895; Fri, 07 Jul 2023 22:36:56 -0700 (PDT) Received: from localhost ([70.22.175.108]) by smtp.gmail.com with ESMTPSA id t25-20020a0cb399000000b006238f82cde4sm2951181qve.108.2023.07.07.22.36.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 22:36:56 -0700 (PDT) Date: Sat, 08 Jul 2023 01:36:56 -0400 Message-ID: From: Paul Moore To: Fan Wu , 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 , Fan Wu Subject: Re: [PATCH RFC v10 3/17] ipe: add evaluation loop References: <1687986571-16823-4-git-send-email-wufan@linux.microsoft.com> In-Reply-To: <1687986571-16823-4-git-send-email-wufan@linux.microsoft.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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-kernel@vger.kernel.org On Jun 28, 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. Can you rewrite that second sentence, it reads a bit awkward and I'm unclear as to the meaning. > Signed-off-by: Deven Bowers > Signed-off-by: Fan Wu > --- > security/ipe/Makefile | 1 + > security/ipe/eval.c | 94 +++++++++++++++++++++++++++++++++++++++++++ > security/ipe/eval.h | 25 ++++++++++++ > 3 files changed, 120 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..59144b2ecdda > --- /dev/null > +++ b/security/ipe/eval.c > @@ -0,0 +1,94 @@ > +// 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 "hooks.h" There is no "hooks.h" at this point in the patchset. In order for 'git bisect' to remain useful (and it can be a very handy tool), we need to ensure that each point in the patchset compiles cleanly. > +#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) > +{ > + int rc = 0; > + 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) { > + action = pol->parsed->global_default_action; > + goto eval; It looks like you are missing a rcu_read_unlock() in this case. Also, given how simplistic the evaluation is in this case, why not just do it here, saving the assignment, jump, etc.? if (ctx->op == INVALID) { rcu_read_unlock() if (global_action == DENY) return -EACCES; 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); Why not break from this loop once evaluate_property() returns false? > + > + 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(); > +eval: > + if (action == __IPE_ACTION_DENY) > + rc = -EACCES; > + > + return rc; This can just be 'return 0;' right? > +} -- paul-moore.com