From patchwork Thu Jul 22 00:47:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12392643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E78EDC6377B for ; Thu, 22 Jul 2021 01:00:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCCF961263 for ; Thu, 22 Jul 2021 01:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbhGVATq (ORCPT ); Wed, 21 Jul 2021 20:19:46 -0400 Received: from sonic309-28.consmr.mail.ne1.yahoo.com ([66.163.184.154]:32870 "EHLO sonic309-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbhGVATq (ORCPT ); Wed, 21 Jul 2021 20:19:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1626915621; bh=88hEcSw0zf3tXzqlcfljipl307HiQH32cYtAYnCYsn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=cN0Qa7mzIXweUXMmKAqXBsF1/4cJ8stnR+Eqy+BgCKxz5SggIvLEnduUIKcvsXNXMPoemK5xEiuwwB89VEnD7Jpu0o1q+zCZw4kUBO29V35AQ0of4/VNfug5S7Rbta4gPDvF9t0vsAfttMqTScPUUs/gl1cMRnc5cxGaQRzXvUXSU0512GbPnbL8BFGl0x3fFcJ0kGUeU0FicoCKHHatAok4Bcln2Fo8n1BuloZuMi3NyLlwSE50/pQ7zMSk7DbHWFX6AuCRVB1+BEpKCPwefIknxsezquIwudXpWKP29igyrHNHDvqK50S6Gdtt2oOwfC9LFSzj4qiH3Ntba0DnFg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1626915621; bh=G42p36VJKtGITi4Op10/0IS+txiN/t1eb3RNsfIW0nA=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=DelmIf26oETyEPHBkFQRaQxemfWx79HFSaW7OWo5sXcJVPXyN3urrFq+LlH/ekXXKLt9wSAGJhiKMOcZyVUsnYGKyPDr8OjREhNASd4c1mrs8PVdR5szYhQAv8rS1u/TlDEkvq8hj1kpblPqX5QpS0j/BB1Pf32FLGWk5DjKGVkY5JmzVNUFw62esm+lvs7z20enFvjFhqwBL92DonP+NFUz/7hIk8OplGWBtAD4+nKfRdzzHWe18mnX8UXMYIlxlJ4bDykssBioGz638snPwgt0tjUB387bfVtRZfXiZwwJ17sLxl8xLA8DqSbOCLHJ2UxpJBV/wSeyPGyxKGYKog== X-YMail-OSG: m5UZ0fwVM1kgR4pN76wC._VUEt1RzvX1y97iJ.0ke2WD3n2tXeGqKqQOjEWOcXQ Ox8Ho7VoT5EisYr0zub4F9kGPCfI9EyHJQ5qzN2c5e2Lc5KIqqjeZmL1uKOoH4uDvmZUCMO1q0dO XM4E9yEfvVgU8_9lfFHlMMQ5MkCFTmaEBckEHVFxlbcwB7ieJA71ilTV4SKqzaRzvEs.UphHG6K9 lj7PFhf8WLXLcnIl7KdVB5VrVX_iKGwvo0Kpal0Xp02lUVXk64yL5LLPL1lwAFyV5.WYPknEudGQ eJp8DTywwUijfgVwWgb0qgixXxywLji60eba8XABDBL2CsR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0RDDRdZ0M 66GT8cVFM8vE9Y0D93PXLkqy3QKbc3VB5Lmc.cMlN0I31mTWKY3esVN96EdfAS3DG8nFIVN9tn6o sY29PmmUQvexoC6MR22nk3uCWlDT82ZTOYVyST_JS.9i4v2cGzRT_jvj3jTLG76If93_IL8gXWR_ PrYJD4FY9dg7h8XBE4.sHyUMdQfO54Y7B6KQEpb35u368K0Mr5Jer5Jux5WGzT9ROBo3FPIbV.DH wBfAPjT9LOC0zQokLR1ETEgVCav93Dsf0BJG79KDmpLfLNW1t1oiL_9okvOLBrxe0nO_GVs9LyUf Oqy_Xp14fUMfUahZK9xfWCdanBT6PhrEnsqsQAJFo81r1OHTGygwquLL4HhQ_zoyqvKKLxrumWBS 9zPhdErxZjM2RDnDoqfvS1wViZLdQMOSW10tJEogvHxBPu7i.tpjOgE8vPBqaU4e2lO3baqFB9X3 xkVXNO.a1bFQIqKKPAuIiOPVB0RMXVszfPkypke8y9gJs0eVRN0be6u2HVjI3Zf8ayHsQHaYsgV_ gTUw.MKy.Gqz3H_PVqI6jiG4panjgouUAl1mL4dk34b8LPPYaqu_jhqZSbrrHnZrJgFFl_0UMETh Ep6rrnZYxSnW0OlohWHKIdwj_BfWYBpaWqpYgXOSszbL9CwINgms2MaBUXVRfHbYNzLf8GTxTWgJ 2ZjxNmT4KaNm1TUMU8lSYyx.438WIZRgPXm2Y5wTp0qDoknwOTS96XRoTRbsYWQ1.boWpqyxnInb 0vfz4u_SnVvL5DD36MJhHCQZ.1yzcv9kvKD6iZsAP X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Thu, 22 Jul 2021 01:00:21 +0000 Received: by kubenode502.mail-prod1.omega.ne1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 018191927b598ade9ea45efd47ffb4fa; Thu, 22 Jul 2021 01:00:16 +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, linux-integrity@vger.kernel.org Subject: [PATCH v28 11/25] LSM: Use lsmblob in security_inode_getsecid Date: Wed, 21 Jul 2021 17:47:44 -0700 Message-Id: <20210722004758.12371-12-casey@schaufler-ca.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210722004758.12371-1-casey@schaufler-ca.com> References: <20210722004758.12371-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 4070cef152f7..aa19fa4a553f 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -454,7 +454,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, @@ -1005,9 +1005,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 af612a42eebe..6d112ec89c1b 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -608,7 +608,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)) { @@ -621,8 +620,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 458fded340ab..da85932a4d53 100644 --- a/security/security.c +++ b/security/security.c @@ -1548,9 +1548,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)