Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32852757rwd; Fri, 7 Jul 2023 23:52:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFakg+VVkhCujTBj12jhl4LeL8wEuiw1ra681QiwXAUrqgJmRhK+wlCjd4TzW6hKBeddjC4 X-Received: by 2002:aa7:db48:0:b0:51d:d1e5:81c with SMTP id n8-20020aa7db48000000b0051dd1e5081cmr7231396edt.19.1688799160781; Fri, 07 Jul 2023 23:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688799160; cv=none; d=google.com; s=arc-20160816; b=vck85QJBMMT+gzbiDziNc1Wwavuk+9Y8HDAohS9rcBe7IZzPb5BbwmrUiKpPfaZVDG t4//+QhkO++SPcp0UraOWtJYKWNRNkTl8LqASQhhiexCZkZ4KADiRhp1daBhyOOaye7A M4qTRrdSQ+dTgNmzhAPetZ2IegRUzgObokS1No+bbYI9iaQRIu1Cbd2++0rmEmlEiT6c 0R/Xb9k0pQUI9TW8cFuOauwgEwqgwWKFvMVZSECiPdaOzlQJINJK9L0j8QG8fsfCdIyG ZDUqGqoMW51VyIn/78Eh5KVlnJ4nPedg4kGWpKP+weCkO2NVXmM1he1J+UXlYjjpEyA5 8uLA== 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=v2wkHCwd4vm+IEtkc2nWyRw52RwR9sbRYqSY91RfFRQ=; fh=Vmgb78f+UWtIut1Oluhwx2oDAe4UZFJl5iee0zHKAXI=; b=FyNsDW3QN6Wmv6quydzrgrMfjHq8lsqCxLaue5gBesYI1OhSwoePm4A71X7I+rioV5 Q1oeWRZOQvLTyOAxHaoFINtauT5vAurqHQgOoyEMrihbAxdmjxgL4C0YSDZ60EOB0G3l I8TynTrB6QvneOrfxfUdHMvsklUTqbgZH8QUi3k/ZOj/kILOsqBCbO1IJC/jdLTQ9Tev OQuSkv3fDVbfAIuOH2Vg4YC018RQVcMXeoe0b4jGAjaxqvICY3a9RtKeJDXFGe1e/gmt rchMoL0wmEJnmqJw3O1WOtojG/OggsYhWjbS8P1JZO2Qpko4rNqlXunJgDmxoZVwC2lC T8qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=A7TKcyKu; 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 k26-20020aa7d8da000000b0051e3371a8bbsi3166460eds.2.2023.07.07.23.52.16; Fri, 07 Jul 2023 23:52:40 -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=A7TKcyKu; 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 S232986AbjGHFhg (ORCPT + 99 others); Sat, 8 Jul 2023 01:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232964AbjGHFhM (ORCPT ); Sat, 8 Jul 2023 01:37:12 -0400 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC1D82682 for ; Fri, 7 Jul 2023 22:36:58 -0700 (PDT) Received: by mail-qv1-xf36.google.com with SMTP id 6a1803df08f44-635e0e6b829so18899176d6.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=1688794618; x=1691386618; h=in-reply-to:references:subject:cc:to:from:message-id:date:from:to :cc:subject:date:message-id:reply-to; bh=v2wkHCwd4vm+IEtkc2nWyRw52RwR9sbRYqSY91RfFRQ=; b=A7TKcyKu/VPh1w1ZbiKg9Zg8sW+vFmOPtftfVKls4QKi1M9IgsF8i1dgygecNhfMRT bZZFCNiIqk77Dhtmm6iE2NgepkEBGBg8woAvioe8aSqCgRmg+4CALt4wUCcdM+OgLOTF tach2LhZStFkxdBYb+Ax/Cx4yB7i7LbshVj0UppsZAor1ljGkqBGcXcVsaD/nQQbASyX ttuPnodpcVGe9Bi/7EE50fSWAPJAnxSdR20LnmhWTIX1atn5eYqFd5X0F4udA5Ue37GS A86+hBiG20f6mEIa37Le0ZYAqWEnzIN2ZqZpg6/30pWeIxxIZpF7ZpkS/VmjEAx8+qgK nwQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688794618; x=1691386618; 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=v2wkHCwd4vm+IEtkc2nWyRw52RwR9sbRYqSY91RfFRQ=; b=jV6dWir8QAIhCEuv1Eqd5DRHK35b9+MBe+FJTSGZ2Mm1SmPO2FpF+i0U8sSCV8hPsX xR2h+CvDVTx4EciJ97D6pZJ0WLxLvBFGcg7sfRHcLa/ar6Qnnvk0+MjXZcI2+6UCSjDz REWb3I+oAugSaklYar+W53s6PNWjnbwwblKO6286UaSBmk8QWuDZYBtFZvDsdd1E9A33 1z9I5R39EzItfEwGDaJDJcnL0/+qlGyDKDxkgAuCrXB8UGo2zQsFYnN6Qkl4f/RF2gH7 wRhBKi5bMLKRlO4QeW4lRBEyEJQu0AkjA5f+51JrJ/LdrSVCgbWQ0j+3g9+fDD3c96Hm T3MQ== X-Gm-Message-State: ABy/qLawk7D4Aih2a34X9YKdYYYtfCAwHs/ZAPOJA3CUzXL3q3ctJQ76 q1bWcmlfyn0OHQUN/UwnnKAT X-Received: by 2002:a0c:b24a:0:b0:635:abf1:e93e with SMTP id k10-20020a0cb24a000000b00635abf1e93emr5908682qve.29.1688794617762; Fri, 07 Jul 2023 22:36:57 -0700 (PDT) Received: from localhost ([70.22.175.108]) by smtp.gmail.com with ESMTPSA id y12-20020a0c8ecc000000b006360778f314sm2940646qvb.105.2023.07.07.22.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 22:36:57 -0700 (PDT) Date: Sat, 08 Jul 2023 01:36:57 -0400 Message-ID: <007992aec442cda5d5866e89b0ed5c69.paul@paul-moore.com> 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 4/17] ipe: add LSM hooks on execution and kernel read References: <1687986571-16823-5-git-send-email-wufan@linux.microsoft.com> In-Reply-To: <1687986571-16823-5-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's initial goal is to control both execution and the loading of > kernel modules based on the system's definition of trust. It > accomplishes this by plugging into the security hooks for > bprm_check_security, file_mprotect, mmap_file, kernel_load_data, > and kernel_read_data. > > Signed-off-by: Deven Bowers > Signed-off-by: Fan Wu > --- > security/ipe/eval.c | 14 ++++ > security/ipe/eval.h | 1 + > security/ipe/hooks.c | 182 +++++++++++++++++++++++++++++++++++++++++++ > security/ipe/hooks.h | 25 ++++++ > security/ipe/ipe.c | 6 ++ > 5 files changed, 228 insertions(+) > create mode 100644 security/ipe/hooks.c > create mode 100644 security/ipe/hooks.h Adding the 'hooks.h' header allows for much of code added in the previous patches to finally compile and there are a number of errors, too many to include here. Please fix those and ensure that each point in the patchset compiles cleanly. > diff --git a/security/ipe/hooks.c b/security/ipe/hooks.c > new file mode 100644 > index 000000000000..d896a5a474bc > --- /dev/null > +++ b/security/ipe/hooks.c > @@ -0,0 +1,182 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) Microsoft Corporation. All rights reserved. > + */ > + > +#include > +#include > +#include > +#include > + > +#include "ipe.h" > +#include "hooks.h" > +#include "eval.h" > + > +/** > + * ipe_bprm_check_security - ipe security hook function for bprm check. > + * @bprm: Supplies a pointer to a linux_binprm structure to source the file > + * being evaluated. > + * > + * This LSM hook is called when a binary is loaded through the exec > + * family of system calls. > + * Return: > + * *0 - OK > + * *!0 - Error > + */ > +int ipe_bprm_check_security(struct linux_binprm *bprm) > +{ > + struct ipe_eval_ctx ctx = { 0 }; It's up to you, but when you have a fequently used initializer like this it is often wrapped in a macro: #define IPE_EVAL_CTX_INIT ((struct ipe_eval_ctx){ 0 }) ... so that you can write the variable decalaration like this: struct ipe_eval_ctx ctx = IPE_EVAL_CTX_INIT; It's not a requirement, it just tends to look a little cleaner and should you ever need to change the initializer it makes your life a lot easier. > + build_eval_ctx(&ctx, bprm->file, __IPE_OP_EXEC); > + return ipe_evaluate_event(&ctx); > +} > + > +/** > + * ipe_mmap_file - ipe security hook function for mmap check. > + * @f: File being mmap'd. Can be NULL in the case of anonymous memory. > + * @reqprot: The requested protection on the mmap, passed from usermode. > + * @prot: The effective protection on the mmap, resolved from reqprot and > + * system configuration. > + * @flags: Unused. > + * > + * This hook is called when a file is loaded through the mmap > + * family of system calls. > + * > + * Return: > + * * 0 - OK > + * * !0 - Error > + */ > +int ipe_mmap_file(struct file *f, unsigned long reqprot, unsigned long prot, > + unsigned long flags) Since @reqprot is always going to be unused in this function, you might want to mark it as such to help prevent compiler warnings/errors, for example: unsigned long reqprot __always_unused > +{ > + struct ipe_eval_ctx ctx = { 0 }; > + > + if (prot & PROT_EXEC) { > + build_eval_ctx(&ctx, f, __IPE_OP_EXEC); > + return ipe_evaluate_event(&ctx); > + } > + > + return 0; > +} > + > +/** > + * ipe_file_mprotect - ipe security hook function for mprotect check. > + * @vma: Existing virtual memory area created by mmap or similar. > + * @reqprot: The requested protection on the mmap, passed from usermode. > + * @prot: The effective protection on the mmap, resolved from reqprot and > + * system configuration. > + * > + * This LSM hook is called when a mmap'd region of memory is changing > + * its protections via mprotect. > + * > + * Return: > + * * 0 - OK > + * * !0 - Error > + */ > +int ipe_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, See my comment above about @reqprot. > + unsigned long prot) > +{ > + struct ipe_eval_ctx ctx = { 0 }; > + > + /* Already Executable */ > + if (vma->vm_flags & VM_EXEC) > + return 0; > + > + if (prot & PROT_EXEC) { > + build_eval_ctx(&ctx, vma->vm_file, __IPE_OP_EXEC); > + return ipe_evaluate_event(&ctx); > + } > + > + return 0; > +} -- paul-moore.com