From patchwork Mon Dec 13 23:40:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12674927 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9360BC433EF for ; Mon, 13 Dec 2021 23:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241775AbhLMXse (ORCPT ); Mon, 13 Dec 2021 18:48:34 -0500 Received: from sonic306-28.consmr.mail.ne1.yahoo.com ([66.163.189.90]:45038 "EHLO sonic306-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236475AbhLMXse (ORCPT ); Mon, 13 Dec 2021 18:48:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1639439313; bh=WqTilqDGcIu+1yT7DKcfjayEylLcsuo2HVtuuRvXH5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=jsvYivaPXDu+wKTF4Vo9e0+zu5C0gV1mhLegloQ/iAVIvGvTof5n0dKSj/sSDsKw/o93sT8OkKABdVJ/ckcMZO6DpYhx/wtRZfIj7AQ3WFyMCvMTsLiNPAG4/1RhxlbBZoR3KBZh01woB5rS8AYaRZayetdeqcTC1A12Ah/jiKU7HOXSyGlL9JPWLxF++g3oQssg2c8z1MocO6X66Hd9k3qJ7ao4z5cj8rjGEWJwwhXKy7ZgEaa1zeAt2hQNJYM7h8jiPhgsoEU29z4Vxt1CYe/7V+rvr2KSuMl8Z2hQ71Mmi5zVhF8/vfD739bISvfbNL/Ibqbro5ZWUe9eNBNA/w== X-SONIC-DKIM-SIGN: v=1; a=r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Dn3qEUWAC5.NfDI5hngTK_TyMD7PL1PVkej416doiGuDYlc1mP3exTL93zCA.JnDcvist.w 2qHHHsQqlEn_PRfx2TxwZwf1sy8QP4CMw4rV8uL0374gGKkjbwAoHLepedVfxuK0RfE7UCVaP3EQ DRnLAXMvkU4Xl6nxcB.bPPTW4FvouuDWZuKLpQVqNV3.jg6PFEO4rVP.FafA_Olrg4mIaPaOvZ3v CNHdtv8PvjalBEM_Qos1PXnoPTMce0oKICZGrdAg9uyzauyf9GEISa6f6D3Jo9j.seyEFjcShLMM Bh1jxyQ6wL2de4eyfFApurj6J4UHPzQg6JpHzswHBPW2xglefdXH9dYKRwcuGT.2Xx8t9.lx_QVl R_szFo2m1Edx2yqvM6XrG6Jiv0piXAMsgeZV6CnH9wuk3vhA9brNbPMycNEiKHtxF8p_QIuBmXTk ueAvOmKDmjKbLYRLrTFa1MwcAI.bisnoE9UCghhGNpcdyangIUL5WL6QoM8dPtikSGIUy6_2zDPH 5RC73SptOYNCMJdEC.KrLKU6_0ggrjsRGJ1xozxNUbkIB0.HPK.GId0JQmPjqbDJfaAhO3pjE1yI TkoUhFIfEnDBSk5turGQ1K85Ohn8Xd8UBCVb12AM1u702RuTFt_G_oDfBPjwhRnlxBIq6.Ti9cAM VMHJp4cjL8kI- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Mon, 13 Dec 2021 23:48:33 +0000 Received: by kubenode545.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 2e021ae071039d083444738cca3c5d3c; Mon, 13 Dec 2021 23:48:27 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org, Stephen Smalley Subject: [PATCH v31 07/28] LSM: Use lsmblob in security_kernel_act_as Date: Mon, 13 Dec 2021 15:40:13 -0800 Message-Id: <20211213234034.111891-8-casey@schaufler-ca.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211213234034.111891-1-casey@schaufler-ca.com> References: <20211213234034.111891-1-casey@schaufler-ca.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Change the security_kernel_act_as interface to use a lsmblob structure in place of the single u32 secid in support of module stacking. Change its only caller, set_security_override, to do the same. Change that one's only caller, set_security_override_from_ctx, to call it with the new parameter type. The security module hook is unchanged, still taking a secid. The infrastructure passes the correct entry from the lsmblob. lsmblob_init() is used to fill the lsmblob structure, however this will be removed later in the series when security_secctx_to_secid() is updated to provide a lsmblob instead of a secid. Reviewed-by: Kees Cook Reviewed-by: John Johansen Acked-by: Stephen Smalley Acked-by: Paul Moore Signed-off-by: Casey Schaufler To: David Howells --- include/linux/cred.h | 3 ++- include/linux/security.h | 5 +++-- kernel/cred.c | 10 ++++++---- security/security.c | 14 ++++++++++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/linux/cred.h b/include/linux/cred.h index fcbc6885cc09..eb02e8514239 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -18,6 +18,7 @@ struct cred; struct inode; +struct lsmblob; /* * COW Supplementary groups list @@ -165,7 +166,7 @@ extern const struct cred *override_creds(const struct cred *); extern void revert_creds(const struct cred *); extern struct cred *prepare_kernel_cred(struct task_struct *); extern int change_create_files_as(struct cred *, struct inode *); -extern int set_security_override(struct cred *, u32); +extern int set_security_override(struct cred *, struct lsmblob *); extern int set_security_override_from_ctx(struct cred *, const char *); extern int set_create_files_as(struct cred *, struct inode *); extern int cred_fscmp(const struct cred *, const struct cred *); diff --git a/include/linux/security.h b/include/linux/security.h index 5a29b9bfdeda..aaa63bf5026e 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -464,7 +464,7 @@ void security_cred_free(struct cred *cred); int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp); void security_transfer_creds(struct cred *new, const struct cred *old); void security_cred_getsecid(const struct cred *c, u32 *secid); -int security_kernel_act_as(struct cred *new, u32 secid); +int security_kernel_act_as(struct cred *new, struct lsmblob *blob); int security_kernel_create_files_as(struct cred *new, struct inode *inode); int security_kernel_module_request(char *kmod_name); int security_kernel_load_data(enum kernel_load_data_id id, bool contents); @@ -1112,7 +1112,8 @@ static inline void security_cred_getsecid(const struct cred *c, u32 *secid) *secid = 0; } -static inline int security_kernel_act_as(struct cred *cred, u32 secid) +static inline int security_kernel_act_as(struct cred *cred, + struct lsmblob *blob) { return 0; } diff --git a/kernel/cred.c b/kernel/cred.c index 473d17c431f3..e5e41bd4efc3 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -772,14 +772,14 @@ EXPORT_SYMBOL(prepare_kernel_cred); /** * set_security_override - Set the security ID in a set of credentials * @new: The credentials to alter - * @secid: The LSM security ID to set + * @blob: The LSM security information to set * * Set the LSM security ID in a set of credentials so that the subjective * security is overridden when an alternative set of credentials is used. */ -int set_security_override(struct cred *new, u32 secid) +int set_security_override(struct cred *new, struct lsmblob *blob) { - return security_kernel_act_as(new, secid); + return security_kernel_act_as(new, blob); } EXPORT_SYMBOL(set_security_override); @@ -795,6 +795,7 @@ EXPORT_SYMBOL(set_security_override); */ int set_security_override_from_ctx(struct cred *new, const char *secctx) { + struct lsmblob blob; u32 secid; int ret; @@ -802,7 +803,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx) if (ret < 0) return ret; - return set_security_override(new, secid); + lsmblob_init(&blob, secid); + return set_security_override(new, &blob); } EXPORT_SYMBOL(set_security_override_from_ctx); diff --git a/security/security.c b/security/security.c index 3ad3aa74c59d..171e2fe66e5e 100644 --- a/security/security.c +++ b/security/security.c @@ -1800,9 +1800,19 @@ void security_cred_getsecid(const struct cred *c, u32 *secid) } EXPORT_SYMBOL(security_cred_getsecid); -int security_kernel_act_as(struct cred *new, u32 secid) +int security_kernel_act_as(struct cred *new, struct lsmblob *blob) { - return call_int_hook(kernel_act_as, 0, new, secid); + struct security_hook_list *hp; + int rc; + + hlist_for_each_entry(hp, &security_hook_heads.kernel_act_as, list) { + if (WARN_ON(hp->lsmid->slot < 0 || hp->lsmid->slot >= lsm_slot)) + continue; + rc = hp->hook.kernel_act_as(new, blob->secid[hp->lsmid->slot]); + if (rc != 0) + return rc; + } + return 0; } int security_kernel_create_files_as(struct cred *new, struct inode *inode)