From patchwork Fri Sep 24 17:54:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12516425 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 205F4C433EF for ; Fri, 24 Sep 2021 18:07:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BBB061107 for ; Fri, 24 Sep 2021 18:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345715AbhIXSIk (ORCPT ); Fri, 24 Sep 2021 14:08:40 -0400 Received: from sonic308-15.consmr.mail.ne1.yahoo.com ([66.163.187.38]:40355 "EHLO sonic308-15.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347877AbhIXSIj (ORCPT ); Fri, 24 Sep 2021 14:08:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1632506826; bh=NSFipKtBBIm45/MDEef6cClsYrf6QTE77Xh6yL0FpFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=fNknNLA3lYmvdhxrqDKdQ8a7wO8Fob0lhCAnyCbKy9hvdT9UoXbQwoLRC70BoVC1pWxFZzx9mPLssi9kEn+oirXgwE+LH3UfrIjtl1Mt1+oTrwY7ISlll6GdTkjchyJnD7cWgzOufd93NIOhWd+Cp8rMXpuSa1cEfQQWrpP1Fzlg+6EmkwVjlbb2iT30h7G4I45J/l1Nt+0d+4TqI3spkG5ipmlCSFt+DllEcvrXRZ10vCldQ2uWlJxxpD4GGlj+c75Ksi1qRUFG+gTOWGlffGgTxzogQI0/UDy1sPolaOcQodfaKQrWOgG6dyzzboH/Qh47SfxbuH50km9YmWRUJQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1632506826; bh=4msa18yrZDHcDr/ysBzWkUKn3IVXkXJ7gsCnm4heKIi=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=cWilWyRLSyoXeLsGI7PWptmQyVjO5Cwp9pnsuJiPG56sr06Z9qjQkrN0fVYBSAo3xa2R36Ru/DykxvZ4o9Rggn8Ise9YNKxOnxUGq/KlhxfLqOWDCblHPGXJZPIovPbSodep6Te+Dvx8WwVa32DUZv5WgOFLaUigxHY8Msm8V/zIeHxbzTwaYrzOwchMCKcbIGtWZK0Voq/+91ESSEF7+zlE+SGDnExZ0kEA4i6YLbEBs3aYAwHvX7XTvDqJzo2TfFl++QAZBBMBcOULd5hcLFIkh/jKsQci/vsF+Ofge4mpBAfefziUugAuLgd+OWSL4hK3t1t5ZxDMtiqjZk13Zg== X-YMail-OSG: S4r3spoVM1nia.7i3N9a0pMdtqHJYFsvhlN8i7XfNsveKkChgEGcecLCLJDu0x0 Sd6bHKFLrd5G1B7_XlS_jvZdygAR8HAKllBvs_e1FduCcdNzqdzYXnKUvNWmFOuvBGoAOp6r5grv y.3Rntsz2789Sfub24lSoI7XrYNJv5ShQOWDiGEBOuJbI6MlNFzU3siTqCO6GcIhKOpux0_1KPGi O9rtxXLTNGr6gUihZnSalqjm1jIwISfLrtNI.KlHoGip5WDuTyX9pLoJ1mcv94zeoekXuWks0NIE vA1.Acyk8fbWWFkhcQjoEVTNnjAwU9G7LZQjAkSTsNbJlzrU5oB0jQ_4Q0w3UyNNidaqHmgoT4GU MJC4Cm70obEO1AAjH7HZZ5czLv4w_CjapVYV7dSP6bytMS0y9BKnfdIxMDNV3r1A_VxlTeogapuw QEQHeu1.t8vncxTnmWnt.X9rHebklKhwsg6USy5HxbEPzCPOIJ8osk5NWK.orulrzYaC0l9kPkJh wx56ShyST4V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nBgZ3DWJWuPapVwR7HnAA25QrTv2L8NWDwEhsj42NUlW2p_EYyuooHXZ EsXruqYIeGOkjjW3ltOp4eP8.mumRcb9yPusb_JB0dDSuSG5X0U1Z_aSEj1bKBjFOBxzfbloOZFn mZjcqaTiCgmzfquUUU6GXZO5thpXLVzRqVnkpbVepTXFK.FosunC_ADE0i7tpm73HZx7OWGXJCzO vpZ_X4norddkOIMEjTFJVmN8c8zXeuL4frgO8pD8lSAHMZULtXMP8k4ushoZpJ_0ZUlRNnTm60WM WVRDBb4Sek4xtYTUMYgxBZJqhk.bLW_YNFxQQgj5o1l8WcV9XD4uZduU2LeCyCg8AbT.b4ncAXpS scgSJiTJxuQq6v0tv2es8XywkXxrgrm1uS2drwVnlhs8C1q2QPknbI.qjVvNf1X1Ipk.EGW3UNb5 LOS7KEEQIwKj5e_zHFaRKVplR5Uc6A2Y4lMim1RXf6qXsB63tmFKT7XWH_Aq9f6qWmgVTy5UzwUV WUYs.CSJ9xdoYQrfK1V5.ik4ezNeFS8P.2muYI..r14Pcp.UB.TadrMubkkwryfGjctz_BLRaO1P MD0M.AkUTPRzznCP.PqDrWi4skXLe_y_D_k61rb8wCs93X5mJCkm5LG4eLM_Zzr_tvNG2V44w8zy YELP9WbW.FQ1ms17WujNV0MkfwkghROoBHSg2Z.lU.lsZCd3rCPNZgXsFFZOrsZyMq6xjSkmJZgr LCawIHnSfE_zKLECGksNdu9jaIPzPJyytJBTQnwBBAxZPZTGoLsxy X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ne1.yahoo.com with HTTP; Fri, 24 Sep 2021 18:07:06 +0000 Received: by kubenode586.mail-prod1.omega.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 6a336e70ce257ef3e6f73420e83310a5; Fri, 24 Sep 2021 18:07: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, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org, Stephen Smalley , linux-integrity@vger.kernel.org Subject: [PATCH v29 11/28] LSM: Use lsmblob in security_inode_getsecid Date: Fri, 24 Sep 2021 10:54:24 -0700 Message-Id: <20210924175441.7943-12-casey@schaufler-ca.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210924175441.7943-1-casey@schaufler-ca.com> References: <20210924175441.7943-1-casey@schaufler-ca.com> MIME-Version: 1.0 Precedence: bulk List-ID: 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 | 4 +--- security/security.c | 11 +++++++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index de70742c30d6..5a336fa10818 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -455,7 +455,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, @@ -1006,9 +1006,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 50e3f2f4cb49..dcd1b988a2d3 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -1975,13 +1975,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 3d9f051edd20..67c7762b2533 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -620,7 +620,6 @@ 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 (!ima_lsm_isset(rule, i)) { @@ -633,8 +632,7 @@ 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); - lsmblob_init(&lsmdata, osid); + security_inode_getsecid(inode, &lsmdata); rc = ima_filter_rule_match(&lsmdata, rule->lsm[i].type, Audit_equal, rule->lsm[i].rule); diff --git a/security/security.c b/security/security.c index 74a7fb981904..5fbcccbdbccd 100644 --- a/security/security.c +++ b/security/security.c @@ -1549,9 +1549,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)