Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp269740pxb; Wed, 4 Nov 2020 22:27:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsPclzRaz+0MHcRKSKGAFe3OnqxH4jMJLuKnXInvT8NtfYNl42eHtvWyaYXeC8EZ4o9f76 X-Received: by 2002:a05:6402:3064:: with SMTP id bs4mr1116199edb.258.1604557647019; Wed, 04 Nov 2020 22:27:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604557647; cv=none; d=google.com; s=arc-20160816; b=Lx+ZpnMohpcYdayPd/w0O1gDmHjwVTN++xryMk5bryeP/bu3MR0fOQ6di8bu+k97jU qHlRdk1p1b/6Dd+3fj5agYwfhz91ktjT6rVKcXqr2cZdAmiBUjd/nZgcPbP1d3xlHm/e 028QLBFNCDvgILW9GHCG4HAEYecZSHqcXqxIFQevfhGGpEYiuxP2kZC+WTlLfi5TwM79 LouM8X8pLVy9QCeF9MrSZ+eWnDmUxEwkGaNboHb45v6L9v8z+d6pAXtQzPa0DyBt5uHM BcSxREDGThFSF3Ld+KAwpOiMtQU9HSRRMhvY+XhOCiv538EbS87VuQoMV06KEWQG2Aau 1yaw== 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=31g/5HzX6krn+gOjEWAqS8zvx9XmSVzOa+BADnOe8TY=; b=OllrmRUxZ5fKGxNmyB/DZ6TyBjyblLV1BsWUcM31O0WGtFpYQL8KvzlXj4w1o73zJD pd0pRGf76HjvIOqPqUQHJkjMpnCex2oErC8mpjhlet1L40pNA5tksh79IMXdWPRi7Bl7 O3SGKS1wnCHMosC7x7qw8hxQQh0rXxkBN1kj/hJiplZpkOEyhDw7EFARALor6KWos7yP rCHHAWi9vuOs5SN+aBecdMsx/8HHzXK3QpN1aQCehlNh9DgaHUHvF4PdmrheDhdX5QmI gcIFv3Y75M63yKnrGdYDPWoLxHkUTcnOhtZztV37G6TAxWa6TcQ/P4jg7yPidmq1hQ9y n2WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=LjTcWGnE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si409882edj.601.2020.11.04.22.27.04; Wed, 04 Nov 2020 22:27:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=LjTcWGnE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387899AbgKEAyU (ORCPT + 99 others); Wed, 4 Nov 2020 19:54:20 -0500 Received: from sonic313-15.consmr.mail.ne1.yahoo.com ([66.163.185.38]:40425 "EHLO sonic313-15.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387893AbgKEAyS (ORCPT ); Wed, 4 Nov 2020 19:54:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1604537656; bh=31g/5HzX6krn+gOjEWAqS8zvx9XmSVzOa+BADnOe8TY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=LjTcWGnEtEN/RXTIPE0RyBMMZz/dxBJhkZSLDtfTi8PCjw/nKFg6i6GjNuKE1z7T2o9DhIiNoNYEsU1ntLpaSmCD1QcqdrCCPRTGJNB+Dfyn6VNTiqhPreB1w/WhhUWKYvauWkDUYzGy4NEO9uuAdQ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sILzDKp_Us8WUg42iaavVkLU8Zi2fgFoCjsjeWC wqH3YxH2Ll5qO_L5Oihyd.qinYY0NOHxoHSwpOywp.gEkIrPcrhaLlwUhz5ZTH6EVVCV1UWJAyZL e9zIvCYz76nInH4m0cljPUb7Diw9lVY7_BEG5QP2nB23An6Rmb8va6YPM9dC2vTzb8Tn9I_7sDY6 E.I8N8ao4cNnAYds3WMGuHD2UMdE1f_vZQv3OXKtNL52tgpPLGcZRV1K36ya77I42PmUJrLx4Rth Vhgau_jav96PWwGEZKg2PqNUpL6gPOfNmu9WBkahlbnFlLtGDeNRTOzGinc2q1wQekpETu7Myosv .ECUZh19yQxTFanhVoceTKp._6_LuUP.9Oz5WQlUEb1q0rAP079_Wc4MDiz4Vs9wsyHAxrhEpksi gFHxZfZz.g_ygsilJewDIQzCg1TBf_Ey4vJbYJqiLnI5X_DYI2._YXJVgRigUq2_pR2bOWvL1Gn4 1fxe1zmBLHPa30tufS0Nl7cOoSsSQgmJVCo5MNXkxJCwU0w70akSq042FO9Dfpt7hvZPlVFFrq8S 6gAPQ.p_O6Duk2WXiPWXve.Jmgh_i8UAse5GtAy3mDCYUYxaPX0IEwjFzjI_QYhUZEq_pSEqtxxy VbcldlwgoRmlLiQdhIHnyKScQX3IrY2.G4L4dsQ1n.5AhE_.clt5UetJgo6sUzBMFTO4kWsvjp1x qBweJlYXGFvqGf98SLuqeKLmEgNZTmTN4_MFakr2w7tMe89E7AsqkFP7938sKH1815Z1xXAUKwZg 9EbYmLCksgaQlQbZvbWjcpKp1gZRvMBBwr7VglTQs3iPp4GyGCqPK3DgHvI0bwnmEAllZR.RLSM4 LaEc- Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ne1.yahoo.com with HTTP; Thu, 5 Nov 2020 00:54:16 +0000 Received: by smtp417.mail.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 26c2d1be78d8ef90873d482e51baf52e; Thu, 05 Nov 2020 00:54:11 +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 Subject: [PATCH v22 04/23] LSM: Use lsmblob in security_kernel_act_as Date: Wed, 4 Nov 2020 16:49:05 -0800 Message-Id: <20201105004924.11651-5-casey@schaufler-ca.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201105004924.11651-1-casey@schaufler-ca.com> References: <20201105004924.11651-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Length: 5124 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 --- 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 18639c069263..03ae0182cba6 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 89c538aa283e..948d12a5eb25 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -443,7 +443,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); @@ -1061,7 +1061,8 @@ static inline void security_transfer_creds(struct cred *new, { } -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 421b1149c651..22e0e7cbefde 100644 --- a/kernel/cred.c +++ b/kernel/cred.c @@ -733,14 +733,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); @@ -756,6 +756,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; @@ -763,7 +764,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 4ecbef074809..3a88a90ddba6 100644 --- a/security/security.c +++ b/security/security.c @@ -1693,9 +1693,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.24.1