Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1267577rwo; Wed, 2 Aug 2023 11:08:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlGKALHH9Ot2OKJdUzDff+eTWhCOLbBtQ/c013mKzTm4M4j5nlwxuR5RSx3AUScWR+0KVQvh X-Received: by 2002:a92:cd8c:0:b0:348:ddcb:127 with SMTP id r12-20020a92cd8c000000b00348ddcb0127mr17865189ilb.11.1690999735962; Wed, 02 Aug 2023 11:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690999735; cv=none; d=google.com; s=arc-20160816; b=ryBIz63KhY9Y6NINoMLqFjVXdChT9HByPePUS0ggYhvpjZhAxZW/VhDw0a04twCEuT G82UWsKGK2nqEQjfyyq6IlPvG9POFNFI/Y9sFlsy3k+ln+vmJq0qy/cEXu+vwPC/ov+K WS/MTnRCEDvC6HOq7k2IUdtMPZ37T2u17jVeqTJluQHS5rg+k0Lv0eSTmBaa6AoNNQeL mCd2rBy3r39pYO/ecUICTZC8OjFnPgmUkTS2eWPbVOgCB9Xj9jj/tE1FFSA/vfJvIFOo drVzj1Lg3hS6wCis4NSN+B52oTPT0+foHQ/vfgocB7eR79smnf6L4CrB6VKj4+CX5uVy DnOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bqvmvro4aAZS2a+tdLb2NZiYYDGjE4eh/yVeJTod7Ck=; fh=arL9UBRJHFsofiiQd44aZRxxzO7fu/grwMh4D2tbp88=; b=yIv1v2156HEl48Sc4aUld5ZYI441Q8wjrGDIKI/tB3Y3uBho6IPIuKMaMQak0x8AcI 1RmKs3ITb+5HpqQF/aqpVNFe6GmKR+NuV2kvSrjdtTGzWpV2WWzHOpwNFyGDv82biZGu Z6/2O7tXGgwygyD3T4ZV/8Jj3beyrgd5DFiNiaootxCRBNh4hJGucz7bRLG+kdln8E1C GjC6RAES8UUpIk6y7EUTnMi7R2xbLofomuEFhZ+mfNIr03DtFpKGF9wvW3Q1L7P9gta5 9brMVz8mXCmO/Ya9jXtiah7DOWRvAnBTlr5VJEY3jBDaCG6FELJpm1KWlzgYYw8bpQxn 8UTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=LufJ1UnZ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f12-20020a170902ce8c00b001b02e8d8976si4385886plg.300.2023.08.02.11.08.43; Wed, 02 Aug 2023 11:08:55 -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=@yahoo.com header.s=s2048 header.b=LufJ1UnZ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233957AbjHBRsm (ORCPT + 99 others); Wed, 2 Aug 2023 13:48:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233925AbjHBRsS (ORCPT ); Wed, 2 Aug 2023 13:48:18 -0400 Received: from sonic309-27.consmr.mail.ne1.yahoo.com (sonic309-27.consmr.mail.ne1.yahoo.com [66.163.184.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 702BC30C0 for ; Wed, 2 Aug 2023 10:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1690998481; bh=Bqvmvro4aAZS2a+tdLb2NZiYYDGjE4eh/yVeJTod7Ck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=LufJ1UnZzKL//NvLgIYAlaSrkAnt9MZhXKzoYo0RhQiG85ed82Bx/RJSKZwdkO30rHkdymvkqzUShTBVlqXC+5jKvmjKt8+3AmvNW9WHlRxRxb7SmnmKBBY/ctgfZwG4Tv2BiTqhRkG/vPzHzD0RmolRKaHsVezomSAllyxmLNTKbAuWeRpxDSn7N4rQ4GSgrUPc/4ms/4OGMglL+akTFZxECmxmpp3PsFhHNqEudg5T2JZV0t1AqpGQgTOyFubtr0l7BfMKFI6g+c2vHNj5LRaVtPOfS7WUHUu0fimihnEPk+y/aVlPj9Y1bIXgYQuflXF0ZO3+XXKB0P2imJsOUA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1690998481; bh=lUZEcSqoqsO3WJh39E6Hb3StZmsVIETByHfyb1nqeWG=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=exP97waVpyBY8RbhqUlKuQ9X6w8abrKe7cAX/ByLPohED5tvBavIgbYSIRAL4VOqzpzuj7tbHv1M6tfZrTOD1bJYK/RfCgInQqV0FSCkDINyAUEt76DG6JDwsQyTcC0B12FnLFVaeKjGz6WFaOD6YT2BHSyXnKF7679wLYJcl89S5XYSf8p1+Aihm5sg+1VTkdeEMl33pdh7iT3Fj0H5ha+inLjURBPi09se2jEgDTbTagJ+Nc5aKxH8WV0YfcA+x4ijBGBblqdyjeJPHAeXIPyf0WftR1Y+iBi+V9sF1S5UgsGpog35RuzltXcYS/sVtJ8vMTFdGTqy4VL9wqZZog== X-YMail-OSG: vFXWvg0VM1nRViHeKmrmN.eoSiakjOo6_aM5h4nh2m6SbNtiuGDSMApJK4LtnrF sZgd_aDQltT1atpYzePTdH44BTVeHpnktfQNGNxW35bn82AoNhAgP2aO_ZpVJnSkXtpF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0Ye14TdzKe6elMQ1hmw5hrNM7GFHtseQa4AxRbT5pTZWNcvyRDjJpHlbIgcDHwZhVj lkBn2Ts7U6WH1jgQW X-Sonic-MF: X-Sonic-ID: 6165fa16-f8ce-4019-927b-f4d96006686c Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Wed, 2 Aug 2023 17:48:01 +0000 Received: by hermes--production-gq1-7d844d8954-t8s9w (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 9cf20a3b1a5c807479089b2cf544b53b; Wed, 02 Aug 2023 17:47:58 +0000 (UTC) From: Casey Schaufler To: casey@schaufler-ca.com, paul@paul-moore.com, 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: [PATCH v13 07/11] LSM: Helpers for attribute names and filling lsm_ctx Date: Wed, 2 Aug 2023 10:44:30 -0700 Message-ID: <20230802174435.11928-8-casey@schaufler-ca.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802174435.11928-1-casey@schaufler-ca.com> References: <20230802174435.11928-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 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. Both 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 | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index 0d882cb221f4..817cf28dbf8a 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -32,6 +32,7 @@ #include #include #include +#include struct linux_binprm; struct cred; @@ -263,6 +264,7 @@ int unregister_blocking_lsm_notifier(struct notifier_block *nb); /* prototypes */ extern int security_init(void); extern int early_security_init(void); +extern u64 lsm_name_to_attr(const char *name); /* Security operations */ int security_binder_set_context_mgr(const struct cred *mgr); @@ -488,6 +490,8 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); int security_locked_down(enum lockdown_reason what); +int lsm_fill_user_ctx(struct lsm_ctx __user *ctx, void *context, + size_t context_size, u64 id, u64 flags); #else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier(enum lsm_event event, void *data) @@ -505,6 +509,11 @@ static inline int unregister_blocking_lsm_notifier(struct notifier_block *nb) return 0; } +static inline u64 lsm_name_to_attr(const char *name) +{ + return LSM_ATTR_UNDEF; +} + static inline void security_free_mnt_opts(void **mnt_opts) { } @@ -1408,6 +1417,11 @@ static inline int security_locked_down(enum lockdown_reason what) { return 0; } +static inline int lsm_fill_user_ctx(struct lsm_ctx __user *ctx, void *context, + size_t context_size, u64 id, u64 flags) +{ + return -EOPNOTSUPP; +} #endif /* CONFIG_SECURITY */ #if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE) diff --git a/security/lsm_syscalls.c b/security/lsm_syscalls.c index f03f2d17ab49..bc22f05e2d8c 100644 --- a/security/lsm_syscalls.c +++ b/security/lsm_syscalls.c @@ -17,6 +17,30 @@ #include #include +/** + * lsm_name_to_attr - map an LSM attribute name to its ID + * @name: name of the attribute + * + * Returns the LSM attribute value associated with @name, or 0 if + * there is no mapping. + */ +u64 lsm_name_to_attr(const char *name) +{ + if (!strcmp(name, "current")) + return LSM_ATTR_CURRENT; + if (!strcmp(name, "exec")) + return LSM_ATTR_EXEC; + if (!strcmp(name, "fscreate")) + return LSM_ATTR_FSCREATE; + if (!strcmp(name, "keycreate")) + return LSM_ATTR_KEYCREATE; + if (!strcmp(name, "prev")) + return LSM_ATTR_PREV; + if (!strcmp(name, "sockcreate")) + return LSM_ATTR_SOCKCREATE; + return LSM_ATTR_UNDEF; +} + /** * sys_lsm_set_self_attr - Set current task's security module attribute * @attr: which attribute to set diff --git a/security/security.c b/security/security.c index cde7f3a13e7c..f1038686ebd0 100644 --- a/security/security.c +++ b/security/security.c @@ -770,6 +770,47 @@ 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. + * + * 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.41.0