From patchwork Thu Mar 10 23:46:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12777065 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 59C2AC433EF for ; Thu, 10 Mar 2022 23:53:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234311AbiCJXyI (ORCPT ); Thu, 10 Mar 2022 18:54:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344575AbiCJXyH (ORCPT ); Thu, 10 Mar 2022 18:54:07 -0500 Received: from sonic304-28.consmr.mail.ne1.yahoo.com (sonic304-28.consmr.mail.ne1.yahoo.com [66.163.191.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D55DD31C4 for ; Thu, 10 Mar 2022 15:53:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1646956385; bh=tmh83u7osd4pu4GiZfbJMQrqUIl/l7Z9iBCkVV4+kWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=s1lmXJs7rvJDfkCZsOLglwFpIZZ3TMkRfYFcep3I+j48y9wwLRKHdEpaLauKKR/lUm9LBkvf4fs1NX+MqI5rvzl1DLyMxB0VEUllkvFh5a8Ur3jmpZSccJmoFHezEcB+lwp3NbCVZvcqpa43AtQNuVMfgoGx6dVZ/fIo9WWnknWVOJEmqV77/Nfkwtt3usk0Uv97FdJTJJma5d1yBCp5ldAsgf6jXZc17Udx1k4LWRt3n7WemxxDjcuLs4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2LIQZXQ.v_ViAutmNwgTvfjRRcMe6WYo.L7FZFZrpX.koHLJwlIJ8NMD9a G65TZDT90YRt7XLrwjFvFFgXUl_y1E5N_spQRScCYmO1RKVMpNTNXAFg1jxdunFm35s3xDoz.1V2 TkPEmzO2YVsCeyfwK105zK.PxJXtprhCkelWZsNsXglHrSuilP97o4L1IqROlgmU4UXXrcp83zhj KrJkce9bjZxCTWmzLeqspK9GvfIancm.qP7awfG.8yIbOqOrAwItYIg1vspSmle5JYyDLAIMx7By TpK_PABFtVI9Cw4BR87VWbtOyh.rbtGjGXFwPv8lSN90DNNyUQulbEJAOcySQxG7kzFDQXs6rudm tREAf5s97kpZ9HbfhmQwwC8D1t6h76hGnTJncPodHdFe5ZsiU8ZwLc5NVYCxIynB9hP5nKO6j0xM 5xiO_WXHzvsX1f0DaVfRmQxXEh4VCR.q2AOHHsb2y5X_mDVlcIH9nDI1RtTsoAnjM3wzwC_XwqFx itpV7M3XSgblZlp27Qpf8oWJFAET85gHUjCirz3pSwP_lCbLYDpizKoKB87WNgB4_U_PCburq1vX 84JRNspzxaJiJdWhe4AQx2zgIz0RVh9iF_MbbgT2YjC6c9caHIfhZkvQduckbWiyvLnxD9C.ZfEU ekqCwApWa0gmEr_HZFEkfCCGK90VYsOv4BZzGI2uCzOv4DB80qpBSXvBYxaTqq8G_agW1vIbyLGP _..4ena0rj0f1WuArghOy3ChpWLjDUhPAMwBOucL2hb4KJ5lILPzoyQnGA9iISiiDKsAF07hyqy2 P6qWvy2ho40QM7pZDdRVNR7EQrJLGd7SQ4rxNzmdLuTDoVdOV_FoL2WQ- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Thu, 10 Mar 2022 23:53:05 +0000 Received: by kubenode525.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 5fda70cf8d38a19ec9bc1b4fcf47812c; Thu, 10 Mar 2022 23:53:03 +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, linux-integrity@vger.kernel.org Subject: [PATCH v33 12/29] LSM: Use lsmblob in security_inode_getsecid Date: Thu, 10 Mar 2022 15:46:15 -0800 Message-Id: <20220310234632.16194-13-casey@schaufler-ca.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220310234632.16194-1-casey@schaufler-ca.com> References: <20220310234632.16194-1-casey@schaufler-ca.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Change the security_inode_getsecid() interface to fill in a lsmblob structure instead of a u32 secid. This allows for its callers to gather data from all registered LSMs. Data is provided for IMA and audit. Reviewed-by: Kees Cook Reviewed-by: John Johansen Acked-by: Stephen Smalley Acked-by: Paul Moore Signed-off-by: Casey Schaufler Cc: linux-integrity@vger.kernel.org Cc: linux-audit@redhat.com --- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 6 +++++- security/integrity/ima/ima_policy.c | 7 ++++--- security/security.c | 11 +++++++++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 5f20c0c68f67..6fc573d2c253 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -456,7 +456,7 @@ int security_inode_getsecurity(struct user_namespace *mnt_userns, void **buffer, bool alloc); int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags); int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size); -void security_inode_getsecid(struct inode *inode, u32 *secid); +void security_inode_getsecid(struct inode *inode, struct lsmblob *blob); int security_inode_copy_up(struct dentry *src, struct cred **new); int security_inode_copy_up_xattr(const char *name); int security_kernfs_init_security(struct kernfs_node *kn_dir, @@ -1002,9 +1002,10 @@ static inline int security_inode_listsecurity(struct inode *inode, char *buffer, return 0; } -static inline void security_inode_getsecid(struct inode *inode, u32 *secid) +static inline void security_inode_getsecid(struct inode *inode, + struct lsmblob *blob) { - *secid = 0; + lsmblob_init(blob, 0); } static inline int security_inode_copy_up(struct dentry *src, struct cred **new) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 2570bf5979e0..6cd15abb99c7 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2248,13 +2248,17 @@ static void audit_copy_inode(struct audit_names *name, const struct dentry *dentry, struct inode *inode, unsigned int flags) { + struct lsmblob blob; + name->ino = inode->i_ino; name->dev = inode->i_sb->s_dev; name->mode = inode->i_mode; name->uid = inode->i_uid; name->gid = inode->i_gid; name->rdev = inode->i_rdev; - security_inode_getsecid(inode, &name->osid); + security_inode_getsecid(inode, &blob); + /* scaffolding until osid is updated */ + name->osid = blob.secid[0]; if (flags & AUDIT_INODE_NOEVAL) { name->fcap_ver = -1; return; diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 22952efcc0b0..34ecdd7b01f5 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -625,7 +625,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule, return false; for (i = 0; i < MAX_LSM_RULES; i++) { int rc = 0; - u32 osid; + struct lsmblob lsmdata; if (!rule->lsm[i].rule) { if (!rule->lsm[i].args_p) @@ -637,8 +637,9 @@ static bool ima_match_rules(struct ima_rule_entry *rule, case LSM_OBJ_USER: case LSM_OBJ_ROLE: case LSM_OBJ_TYPE: - security_inode_getsecid(inode, &osid); - rc = ima_filter_rule_match(osid, rule->lsm[i].type, + security_inode_getsecid(inode, &lsmdata); + rc = ima_filter_rule_match(lsmdata.secid[rule->which], + rule->lsm[i].type, Audit_equal, rule->lsm[i].rule, rule->which); diff --git a/security/security.c b/security/security.c index e33fa677181d..0253c925a272 100644 --- a/security/security.c +++ b/security/security.c @@ -1553,9 +1553,16 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer } EXPORT_SYMBOL(security_inode_listsecurity); -void security_inode_getsecid(struct inode *inode, u32 *secid) +void security_inode_getsecid(struct inode *inode, struct lsmblob *blob) { - call_void_hook(inode_getsecid, inode, secid); + struct security_hook_list *hp; + + lsmblob_init(blob, 0); + hlist_for_each_entry(hp, &security_hook_heads.inode_getsecid, list) { + if (WARN_ON(hp->lsmid->slot < 0 || hp->lsmid->slot >= lsm_slot)) + continue; + hp->hook.inode_getsecid(inode, &blob->secid[hp->lsmid->slot]); + } } int security_inode_copy_up(struct dentry *src, struct cred **new)