Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp92074pxh; Thu, 7 Apr 2022 15:02:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHfLvrLgx1GrIsYevBQam1v8fY5ZvaYUmQS4g5mLMY5ie0dNxpB8IoOVl5PTkdbZEUfGD/ X-Received: by 2002:a17:902:ab8b:b0:156:16c0:dc6d with SMTP id f11-20020a170902ab8b00b0015616c0dc6dmr16108465plr.147.1649368949010; Thu, 07 Apr 2022 15:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649368949; cv=none; d=google.com; s=arc-20160816; b=xrGDOrlpXAM1Xcj8iPEQqeCHTW5Q/zlCaTUSgtQCPcnFrYP9pYtXrX9BxMBWoIEZYP LIPrHLq8CDife3zWWE8ott/Q9IiaRVuc2wOo5Ch1tNL8IiURfjavk/1Fl+wBD1zJxMnM WHTqAxdRBPnJRDh9N4iQA3Eh4XO33Rvv6uCUCFX9PQn65rcIgUkaKwRqt8BtY63lIYv6 paFbGXQKN9WIj+zwhgBIy5vqjZ2801gOGDKnZmw5UilwOwpAKW1n0FchWA6AnWM8oC5p KKH4xeRu7gruJwn+83icUV7LdYxfGaBuhr5EkOkOf2mO6NT56J6JBONsAVQE7ZrKRPqS 4TtA== 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=6tvzPbUYER32tgoFjKl1mHuZU5CweXvTxDb5j027Opo=; b=YnXBC5yY8+vsSqfsaIkh4+4gKXC0G/LydFatwEvYKg+DKNDmLeaAMMI7xFUJbhYZEy pkPKgD7ySiLDe4vDAL3RxKszSQo3CpLhVJJPoOf0+WDeirNv6GPJ+wVOlTdhhFKyUR6C 0kWzm187811ugeO0VxqoKLlaq7cXUzc7Dtm0dZAH1vE15Sp0zFOPWl/lCkjeiFcDo4BA ZGJpZU3gz30coZuS7AexVKy6+xc2pe/1RCmv0MBC6h+l85HocNKsui1SulQx3f/T//MS WTbeE24pTRY5LYz2X79JkCPcXFufH4fOnw7xS9nRmvpChdLfyuLFeYXQfX0LLoL1zqWE zmng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=TAnv48AD; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 36-20020a630e64000000b003816043f0c1si20643303pgo.694.2022.04.07.15.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 15:02:28 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=TAnv48AD; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5F3FA19F46E; Thu, 7 Apr 2022 14:26:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231453AbiDGV2M (ORCPT + 99 others); Thu, 7 Apr 2022 17:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231424AbiDGV2H (ORCPT ); Thu, 7 Apr 2022 17:28:07 -0400 Received: from sonic305-28.consmr.mail.ne1.yahoo.com (sonic305-28.consmr.mail.ne1.yahoo.com [66.163.185.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAACF199530 for ; Thu, 7 Apr 2022 14:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1649366765; bh=6tvzPbUYER32tgoFjKl1mHuZU5CweXvTxDb5j027Opo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=TAnv48ADkDUrvujrtpMUSHAOvJINKjK73IMR+k1aXvtdFGCTRVAM9Co9+xk1QhYzlneOTNGoD2VKHEpujdLd1kZdgCDiJ8kzzWEP7Nj6UZwHZGnMVxhKbmfMHo4YFImpaATmRXVI1Dh/Yktla2G8CtiDSIVJXQXpkZP0zRLhHREcIE/aFXg/uFTp+jPnHri63kWE3xqDdMRzrk4tohtSU7LH556DZZNO/RHSq7njBTwvNorGEP/JSIrcbqw6N4/R4/syG2drgyFLB4L7PVv9sxN3kLPXsZMF98rREDQYK78pNsJXiiEGsbN+qxveAut78gzF5zklT/ya/+dLyY0PAg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1649366765; bh=ORKfbquBHDJwCT2u4GBOHeFgik/m75sYXaI84HBGqPO=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=GmlLq/++bN+Ank4WAtCuJanx2dN08uxBo1t0z1PI/PJKZZo+1c6vwkEzgqFJuvReH8dEgH5Lr/swEkNcWGMr6Uz4xgAmhDrfsKsV0VS4nAhzcZZP9PIxqf80yaly7PiYsiUFZnjUVJEG86Pxn5Qf/gC5i29cMhaXdVQNW+FNZJGUii/2NWe3yYS5X08ox0mIjwvXGmAeQmzZSXu6iyjxJ8JDClVRgXWg56Mz4GzMoClCBg7bRehIq41ZwxhI1AxPZQalm6mdHinTzGBgO4zM6knlG4DoLXaCui8j7ii/nI01NT4gf/4ZONp4KXZ0eUUteBKigZNB9rAR9ftzlrw/Gw== X-YMail-OSG: .kgncYAVM1ma9STGnm9yr0SbfqVtPNb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VJ.hTHX9 khPFNkjE6Dy54BUPwG3Hlf7ieIlclsh95hbxUVoSnToNY5zZpc2suStyVtLQkMwI81a67cP8cwjR CtGbh57lFBdKJpsGyton6z1a4ZjgnKNkgCTAXglQi2YuSWJATZUXqADgdgkJWkzZyLDYMFN3_l_Z OuiMByEf8sjowpMZZaT3MAkmX5fR5ug-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ne1.yahoo.com with HTTP; Thu, 7 Apr 2022 21:26:05 +0000 Received: by hermes--canary-production-bf1-665cdb9985-zm65g (VZM Hermes SMTP Server) with ESMTPA ID 1b8a787888cf9c0809abffd2a20a44f0; Thu, 07 Apr 2022 21:26:02 +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, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v34 07/29] LSM: Use lsmblob in security_kernel_act_as Date: Thu, 7 Apr 2022 14:22:08 -0700 Message-Id: <20220407212230.12893-8-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407212230.12893-1-casey@schaufler-ca.com> References: <20220407212230.12893-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,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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 9ed9232af934..610f70a99f60 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 8fc599317f79..e9f185e9162a 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -463,7 +463,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); @@ -1105,7 +1105,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 e10c15f51c1f..3925d38f49f4 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -767,14 +767,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); @@ -790,6 +790,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; @@ -797,7 +798,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 ced1c76a380f..e9f1487af0e5 100644 --- a/security/security.c +++ b/security/security.c @@ -1816,9 +1816,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) -- 2.35.1