Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp92202rwl; Tue, 11 Apr 2023 15:01:36 -0700 (PDT) X-Google-Smtp-Source: AKy350bOq2+x6bbHoCR8EhI1gryx3LvzEJ0/S4SPI+g0QL3b/1E4vq4RP1cAAP9KO6aMX239I9LS X-Received: by 2002:a17:907:84c:b0:94a:7da2:d339 with SMTP id ww12-20020a170907084c00b0094a7da2d339mr9416626ejb.26.1681250496302; Tue, 11 Apr 2023 15:01:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681250496; cv=none; d=google.com; s=arc-20160816; b=vk0ROilTLD8z0kcpoOLL9kwJ2teA4BIipmXF+etrtmjJls/zB1HMHvs1wUWYiMLW8S pg1ngi1KV3AqPuSLjnEMEGFMVluKZnYlhBInwk0TSUyv/Ir9J3RpaZqi6vmWLINzeok7 Mq9vfAIduV80RI1nY/P0u21fpEcILfcEi3gxvBP9Gk9olJ6oBPwohOAlETg8wm6MD2n1 P4XBo15typHWLrVVdFXGsegmIrHOBFOvZfxCADTmUZyzFsryzCnAT7/4oYvSiI23XjgP o+cv0mO8WeMa2QZLo5Y7ohZW2Pv8/J1FYka79cDW7Ez0v7vsChoY5JqNlpxNh3BU/JmH /m2Q== 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=QJHIYVc0csC12SHK/J/mtXalsO4pjHKd97C3GIyBGPs=; b=Vc8neQkWgcCzTpdg5Eq1KPQJWzpoD2fL3SjJVKinhfr4zaY/z4Q9UM75EUZiHFX2FY PFYC9i5BBM5n9D94rn5dFi7L5L+hqfxNkXPLedUIgJtDjBnT2FOkSo2EymUM0fBsVkrJ vs0A2reOP7ggZSEXtGriTioCL00OLt+dalnssZcs+i09gs8pao+e5uhzkExYu8vADNIM Z2R9McIHRNCgsyRpaC/9fTETDmaf5mWyLEX5mL9kJfbVc6qxElyqOEO1PIDr/JNlYS2o MUR8iXlBwT2g+OaVwbqN39pywwA90qEN9i8MXlMr03MGiqzxY+kYrGWKPVODFq6yyNRS azZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=DBlz2vm4; 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 ss8-20020a170907038800b0094a9fae749bsi774727ejb.618.2023.04.11.15.00.44; Tue, 11 Apr 2023 15:01:36 -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=DBlz2vm4; 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 S229786AbjDKVp6 (ORCPT + 99 others); Tue, 11 Apr 2023 17:45:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjDKVp4 (ORCPT ); Tue, 11 Apr 2023 17:45:56 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1057349F0 for ; Tue, 11 Apr 2023 14:45:53 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id e127so9769693ybf.8 for ; Tue, 11 Apr 2023 14:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1681249552; x=1683841552; 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=QJHIYVc0csC12SHK/J/mtXalsO4pjHKd97C3GIyBGPs=; b=DBlz2vm4moCxBbqcz1weaSasKWcg+Y71F5kVhWN7HJXD/ZN7d3htDBV70rbXGYWU3t CXxT9fxqT9/QnzXL5Nd4wWfo4F0S9G27/nnohdAdRRK+4bONsmM4BvVBIzpOCbcwAeha Xy/3h3dUEkfQn6vXeo0795aMl3/fNibaNdnltb95zNJoMMc7l+XJgqL5yZzvzIEqaHpF HuYAWlfZWOnEM+Wye80CUORh4piSFA7w5AQbxTd97rqexAdvf8c6ZT1rwMrsR9PEU/VP HGzyfkBtzRsmynNQmymKhDcCzgTJ+xjIpLPiLBbn6PV++RgHBtfpqB4xyg2F/X6/HjlC QQ/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681249552; x=1683841552; 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=QJHIYVc0csC12SHK/J/mtXalsO4pjHKd97C3GIyBGPs=; b=d2FLk41JbN39dJpVPr1ptHGKCfS5wik6AsfpnfwoCXac7ksg0ypMqIoviAcy9nOGS9 3EXnT+LF1dQW8h9b2bsBRezBlTm4GutY1YSioJi+WB/qdrr2wB4PnLMNAWZM22Vo43Om CBJTJJtyrVYcUqsgF2kBYOPn4U5jxVCqn7iy9fd0ddpaWYNFsspM2nUYFtuyFW/0btuc vNd+6POu5QllS0S85AePkaOadb/nwiaQ164DAo1YRJGMqa7V4tobVEuAkthI+lwzGfqC xYIJ6UEY60vqcgXD4+88S1r3HC0sYK11HZ3BQhnWV4PJmV/KkC0NA9hlbzeJvaFoPMZu 7RAQ== X-Gm-Message-State: AAQBX9c1dBr+Jva5xzJip+MPTCc2PcYnaGLePz5USVbve7q4vwM5z6hx KC+y5eKD0c30XEAVrZgL9kTLLJH+uFCoPhLRGvuE X-Received: by 2002:a25:e0c5:0:b0:b8b:fd23:5028 with SMTP id x188-20020a25e0c5000000b00b8bfd235028mr2609635ybg.3.1681249552097; Tue, 11 Apr 2023 14:45:52 -0700 (PDT) MIME-Version: 1.0 References: <1675119451-23180-1-git-send-email-wufan@linux.microsoft.com> <1675119451-23180-6-git-send-email-wufan@linux.microsoft.com> <20230410191035.GB18827@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> In-Reply-To: <20230410191035.GB18827@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> From: Paul Moore Date: Tue, 11 Apr 2023 17:45:41 -0400 Message-ID: Subject: Re: [RFC PATCH v9 05/16] ipe: add userspace interface To: Fan Wu Cc: 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, 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, linux-audit@redhat.com, roberto.sassu@huawei.com, linux-kernel@vger.kernel.org, Deven Bowers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 Mon, Apr 10, 2023 at 3:10=E2=80=AFPM Fan Wu = wrote: > On Thu, Mar 02, 2023 at 02:04:42PM -0500, Paul Moore wrote: > > On Mon, Jan 30, 2023 at 5:58???PM Fan Wu wr= ote: > > > > > > From: Deven Bowers > > > > > > As is typical with LSMs, IPE uses securityfs as its interface with > > > userspace. for a complete list of the interfaces and the respective > > > inputs/outputs, please see the documentation under > > > admin-guide/LSM/ipe.rst > > > > > > Signed-off-by: Deven Bowers > > > Signed-off-by: Fan Wu > > > > ... > > > > > --- > > > security/ipe/Makefile | 2 + > > > security/ipe/fs.c | 101 +++++++++ > > > security/ipe/fs.h | 17 ++ > > > security/ipe/ipe.c | 3 + > > > security/ipe/ipe.h | 2 + > > > security/ipe/policy.c | 135 ++++++++++++ > > > security/ipe/policy.h | 7 + > > > security/ipe/policy_fs.c | 459 +++++++++++++++++++++++++++++++++++++= ++ > > > 8 files changed, 726 insertions(+) > > > create mode 100644 security/ipe/fs.c > > > create mode 100644 security/ipe/fs.h > > > create mode 100644 security/ipe/policy_fs.c ... > > > +/** > > > + * ipe_update_policy - parse a new policy and replace @old with it. > > > + * @addr: Supplies a pointer to the i_private for saving policy. > > > + * @text: Supplies a pointer to the plain text policy. > > > + * @textlen: Supplies the length of @text. > > > + * @pkcs7: Supplies a pointer to a buffer containing a pkcs7 message= . > > > + * @pkcs7len: Supplies the length of @pkcs7len. > > > + * > > > + * @text/@textlen is mutually exclusive with @pkcs7/@pkcs7len - see > > > + * ipe_new_policy. > > > + * > > > + * Return: > > > + * * !IS_ERR - OK > > > + * * -ENOENT - Policy doesn't exist > > > + * * -EINVAL - New policy is invalid > > > + */ > > > +struct ipe_policy *ipe_update_policy(struct ipe_policy __rcu **addr, > > > + const char *text, size_t textlen= , > > > + const char *pkcs7, size_t pkcs7l= en) > > > +{ > > > + int rc =3D 0; > > > + struct ipe_policy *old, *new; > > > + > > > + old =3D ipe_get_policy_rcu(*addr); > > > + if (!old) { > > > + rc =3D -ENOENT; > > > + goto err; > > > + } > > > + > > > + new =3D ipe_new_policy(text, textlen, pkcs7, pkcs7len); > > > + if (IS_ERR(new)) { > > > + rc =3D PTR_ERR(new); > > > + goto err; > > > + } > > > + > > > + if (strcmp(new->parsed->name, old->parsed->name)) { > > > + rc =3D -EINVAL; > > > + goto err; > > > + } > > > + > > > + if (ver_to_u64(old) > ver_to_u64(new)) { > > > + rc =3D -EINVAL; > > > + goto err; > > > + } > > > + > > > + if (ipe_is_policy_active(old)) { > > > > I don't understand the is-active check, you want to make @new the new > > active policy regardless, right? Could this is-active check ever be > > false? > > Actually this is needed. Policy updates can be applied to any deployed > policy, which may be saved in two places: the securityfs file node > and the ipe_active_policy pointer. To update a policy, this function firs= t > checks if the policy saved in the securityfs file node is currently activ= e. > If so, it updates the ipe_active_policy pointer to point to the new polic= y, > and finally updates the policy pointer in the securityfs to the new polic= y. Ah, okay. I must have forgotten, or not realized, that multiple policies could be loaded and not active. I guess this does make me wonder about keeping a non-active policy loaded in the kernel, what purpose does that serve? --=20 paul-moore.com