Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp21615934rwd; Thu, 29 Jun 2023 19:43:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlGVzGWPkpNJ0jKmyaJpODVXb1LlywLshPRoteYU5KemVWsGRnvNNxSWgYvYG5oeEYMQ6fJe X-Received: by 2002:a05:6871:4218:b0:1b0:7ef4:2a3c with SMTP id li24-20020a056871421800b001b07ef42a3cmr2344025oab.10.1688093011541; Thu, 29 Jun 2023 19:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688093011; cv=none; d=google.com; s=arc-20160816; b=F4ufyR+AtKA6t8wyuCquxvCRH+twJmSUtyquLG66rkiaJwruOUo3jAwwGk1rR+Bzgc sEnhjvIP6IYaRO24xhT2MWAX00/34SDjWWttfc9NK2wr0+KCq/MiqNrhwPUUL5QneR23 fWCBLmYkwVlZIWNW8oDvFvrhxQkh3vG/8xaJ1/evdBX+EuQtgCDPWp/te4LweVlPVAMJ QoSOJydi0dWXkVHf0crcWowR3EobagGpm/COT2I6cFH23OobM+1u8ssLD3a+ZoSrWzQh VgZQFScIP2rLApBsok3Y0hLBTSdMDRcL8/u98Ws0TNWSc6d3Lh8tlIvS78haKmCtfCji hDFA== 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=lUZYbjHCm+/YwbwkZOc0X7RCCacNSOU2rhmp+KGHioU=; fh=x6HGP9dmBZaLDiWzE7gNXvrhgjnMvMAq1x+7jRyENc0=; b=HUNJEUjANjRI6rOfqd+fB0Ljf63GEFkd+8lA/otmRsHYtMlu1vHXhdgVrzNQ757yak m5tKFHY0wdIwoAMSqljeJtCKOQyhuKYlBvezuoGZaRvs7trJLPKG3tylv6sTk7ZMByUF eqOfX5+aI0eJiU6csyqS9c5qow67ok5CEfwL0pWJlPO1OG3GncWaMPqI3JSRWpws/Y2S Wmkk5+gDbs3qOkXNZ2IiaaC7az7vhyWIHefqOkONRIoZZXbhU6LVbKAFLmjvSztLf6cS NnHwljeZfxdCzGxHJVnn3LCqVSvLIGrs76rXo5NBrqQI5gg401hoxA2W7VC2cG8ByKS/ 5iSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=dLXIZJEq; 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 x124-20020a636382000000b0054fd8114a7fsi12150254pgb.22.2023.06.29.19.43.14; Thu, 29 Jun 2023 19:43:31 -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=dLXIZJEq; 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 S232141AbjF3CPI (ORCPT + 99 others); Thu, 29 Jun 2023 22:15:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232454AbjF3CPE (ORCPT ); Thu, 29 Jun 2023 22:15:04 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0F9C3AB2 for ; Thu, 29 Jun 2023 19:14:45 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-40339da998eso6315821cf.0 for ; Thu, 29 Jun 2023 19:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1688091285; x=1690683285; h=in-reply-to:references:subject:cc:to:from:message-id:date:from:to :cc:subject:date:message-id:reply-to; bh=lUZYbjHCm+/YwbwkZOc0X7RCCacNSOU2rhmp+KGHioU=; b=dLXIZJEqsaltvVJWrk+DUxlcMCIWNkmtkM3z9QdWPyNSmxmGR6Sl4HS692Nz6fj2tF UFVqRL+aiiVUb8C+HIj0aAAVaojeZGy/1V8QzYd4dbS6LqBlpbfpw80kJAS7oDa9NeoB yTjXXJJJEBBQKzNOJy9zi08aVvlxLYguCjJqFkC2R6hJx8goyHHV9NEMm7JmFncINrNR 9jaKEqcYO+dqsK7zLcKWLkZ3/bwRA8FaFPF3+ccj5cYYoh/GHQQxAojmolY5OYJ1e1GP 7S6yVzzmnZx3hTksr3Tsn2HscCJfnfQoZ9/A70K8BU7ffdlFLHB+GtiPJseAwV0zQz7N aL0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688091285; x=1690683285; 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=lUZYbjHCm+/YwbwkZOc0X7RCCacNSOU2rhmp+KGHioU=; b=TVYFouK1A+Dl+rrHq4QBA4XcVSLN9BAfNTvSf7Dsgk1pw8GCXxwFR7Ka02pbIRtoUG rv7LSFLhOqsuQzl2mt1lmc61V3vnrC1j2efGaBi9LxuNGfknwZZyPioyHuMCudixZfTc eH/tydQGHsmI1ygGoUtoHB3CKOA1gRj9ivYEeiaTH7BNbuIUSxCoPyABvj7MjtxI1OCr jg1DYItNzIOm+NdB9dLfJZS5abNMhtC/XZKUFACNzRfIIIYcRFIqSoJxoMqAtI9RmcV6 xV04zKELJYX2txZEUghSCXV0osIqjbz5qwOtv97ZSEF5yd8cDuJj6dtcaFM/CSytCtd5 ReMg== X-Gm-Message-State: AC+VfDyDEa77nsC07sRSrlNzpt35uin3puoLK/n3l7OvTCEig3+os4qe fjji3Fv2mMeBYH2aKRCDh6oG X-Received: by 2002:a05:622a:492:b0:400:98e9:fd78 with SMTP id p18-20020a05622a049200b0040098e9fd78mr1697557qtx.40.1688091284833; Thu, 29 Jun 2023 19:14:44 -0700 (PDT) Received: from localhost ([70.22.175.108]) by smtp.gmail.com with ESMTPSA id m25-20020aed27d9000000b003f364778b2bsm7907170qtg.4.2023.06.29.19.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 19:14:44 -0700 (PDT) Date: Thu, 29 Jun 2023 22:14:43 -0400 Message-ID: From: Paul Moore To: Casey Schaufler , linux-security-module@vger.kernel.org Cc: jmorris@namei.org, serge@hallyn.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, mic@digikod.net Subject: Re: [PATCH v12 7/11] LSM: Helpers for attribute names and filling lsm_ctx References: <20230629195535.2590-8-casey@schaufler-ca.com> In-Reply-To: <20230629195535.2590-8-casey@schaufler-ca.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=ham 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 29, 2023 Casey Schaufler wrote: > > Add lsm_name_to_attr(), which translates a text string to a > LSM_ATTR value if one is available. > > Add lsm_fill_user_ctx(), which fills a struct lsm_ctx, including > the trailing attribute value. > > All are used in module specific components of LSM system calls. > > Signed-off-by: Casey Schaufler > Reviewed-by: Serge Hallyn > --- > include/linux/security.h | 14 +++++++++++++ > security/lsm_syscalls.c | 24 ++++++++++++++++++++++ > security/security.c | 44 ++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 82 insertions(+) ... > diff --git a/security/security.c b/security/security.c > index 199db23581f1..72ad7197b2c9 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -770,6 +770,50 @@ static int lsm_superblock_alloc(struct super_block *sb) > return 0; > } > > +/** > + * lsm_fill_user_ctx - Fill a user space lsm_ctx structure > + * @ctx: an LSM context to be filled > + * @context: the new context value > + * @context_size: the size of the new context value > + * @id: LSM id > + * @flags: LSM defined flags > + * > + * Fill all of the fields in a user space lsm_ctx structure. > + * Caller is assumed to have verified that @ctx has enough space > + * for @context. > + * > + * The total length is padded to a multiple of 64 bits to > + * accomodate possible alignment issues. We should drop the sentence above now that alignment is the caller's responsibility, but since that was largely my fault I can fix this up during the merge assuming you're okay with that Casey. > + * Returns 0 on success, -EFAULT on a copyout error, -ENOMEM > + * if memory can't be allocated. > + */ > +int lsm_fill_user_ctx(struct lsm_ctx __user *ctx, void *context, > + size_t context_size, u64 id, u64 flags) > +{ > + struct lsm_ctx *lctx; > + size_t locallen = struct_size(lctx, ctx, context_size); > + int rc = 0; > + > + lctx = kzalloc(locallen, GFP_KERNEL); > + if (lctx == NULL) > + return -ENOMEM; > + > + lctx->id = id; > + lctx->flags = flags; > + lctx->ctx_len = context_size; > + lctx->len = locallen; > + > + memcpy(lctx->ctx, context, context_size); > + > + if (copy_to_user(ctx, lctx, locallen)) > + rc = -EFAULT; > + > + kfree(lctx); > + > + return rc; > +} > + > /* > * The default value of the LSM hook is defined in linux/lsm_hook_defs.h and > * can be accessed with: > -- > 2.40.1 -- paul-moore.com