From nobody Sat Nov 30 10:30:32 2024 Received: from sonic311-30.consmr.mail.ne1.yahoo.com (sonic311-30.consmr.mail.ne1.yahoo.com [66.163.188.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A1C3195FF0 for ; Tue, 10 Sep 2024 18:44:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.163.188.211 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725993894; cv=none; b=R59GDYkbfCle5Irfxzyr/HfD0mhw953n+yFRlwa4313E+1C9k7AkbawrxtdaJIK96nHygrOWcNAzUdema9rHTqXdK1Q6UC3K/UdJSi5o0r2n09UsmCjzgqcEE68Bw2gyMhgAFEj4sWwyPy9U/4Ulk6JBKU/4I2/H8Pzt3nqfv7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725993894; c=relaxed/simple; bh=S46SS+R0nyCLxubgW8sJKqFsdTdpBILZWRQpPxgNBv8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kNCsITd+fTIFBA0hN+AfU+IWQITyNHL7eHs07s41kUVTLR/s0ar5eOKIPirSec0bBG7cY1briY6x/WB2ajJCsIf84aBwy3JkM4lNt0vHrOOYlZNma+en5OiGDz0IQ5enIWEaaVuvz2F+dMU5a0QY+PHFQtbXU83W6vzZ+jDbTSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com; spf=none smtp.mailfrom=schaufler-ca.com; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b=Qy+c/LwY; arc=none smtp.client-ip=66.163.188.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=schaufler-ca.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="Qy+c/LwY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1725993891; bh=YqNuSh7G2a8CxdUWt/MHjs+OoDWEq+Ghbbp+RwiCg94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Qy+c/LwY9CIPqKiY7PkOwV/CXbVu+95yCz+QeShHdYBx1E6PhHw1niU782R4mOd0AWtqy3lI3EQZR1lUUlr8WjExYJv9gZE57YyWBCQtBzd5SOqFaeYkyVDBDqzI64tJGo7tmG47M4yeZkKaJFn03JrazIlAd+dryOqIvaAMayS0TQSxUx9a61Ddcj+dYl1UQ2AD9uE3hkT01b5VbUyrZZM+6gtuNHxRyL3ij5SrpS42DPABVZJ6cJkux/1MX5yuOeLTQ/jzFPW38il/XAUEnCIhqAINgkMO7mqLsDq/ojLqDqCYny5ka17WppWJINDGO+I3ADhJzpqHe2dw6qKtPg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1725993891; bh=lklpdxNugB6jvdpRPRkah82wsa+46Km5W3J5Z7T5hUb=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=ZW6oXiMqfM5dXtVJdRMWuI8RJv7pwlbGfb1PP2Zk57PlHWvZmiuuULEghCdcFNKB0UTl/j4gO/Fw9iWTAuZOk5YFYdcg2UkbLQapGDYAet+B5HiFjz+vrLQVQb6yBPJOFDpuMHQ3h4QmHD4aLUR6SP/EB4Ve5GKc5AeRLtbgwBGUtpieo4DFMGvpNmJEUZzCVzEFgPkdN435vHI33Kmi8FTQ1cmE8FFBlF7I3fSCUcUT8hIFbyDJtbtFI68YDQPYUo0xOZCPmfa6sI9fBLJ53/cv98+kkSXeSp0T2llKAa1cxctcPWzYljbEALpt+2XmvkhTbABwbKq3+uvGZo9cnA== X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TS.u1fgjraOWp1OgvgD6w1WxswQiJOGNt.iiLA_XQk1VJk 21b3.CgkU8maoUqmvD_q8JtmfBGt6o18QuMMqcEl_kHk4s_ksiljBwzIjv5x0nqaKDukc3p6VCfl blcr0GT2x3hR_Ly6mCwvWs3w8lIDvBbiI9VtYBXkKruDU6KGJepPQ5ghMy8cYagg- X-Sonic-MF: X-Sonic-ID: a3b68d7a-0e10-4468-9641-d8e70b3343dc Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Tue, 10 Sep 2024 18:44:51 +0000 Received: by hermes--production-gq1-5d95dc458-s958r (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 52d00b93a233ef9d46e84b01a7384b7d; Tue, 10 Sep 2024 18:44:47 +0000 (UTC) From: Casey Schaufler To: casey@schaufler-ca.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: jmorris@namei.org, serge@hallyn.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, selinux@vger.kernel.org, mic@digikod.net, linux-integrity@vger.kernel.org Subject: [PATCH v3 08/13] LSM: Use lsm_prop in security_inode_getsecid Date: Tue, 10 Sep 2024 11:41:20 -0700 Message-ID: <20240910184125.224651-9-casey@schaufler-ca.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910184125.224651-1-casey@schaufler-ca.com> References: <20240910184125.224651-1-casey@schaufler-ca.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change the security_inode_getsecid() interface to fill in a lsm_prop 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. Change the name to security_inode_getlsmprop(). Signed-off-by: Casey Schaufler Cc: linux-integrity@vger.kernel.org Cc: selinux@vger.kernel.org --- include/linux/lsm_hook_defs.h | 3 ++- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 6 +++++- security/integrity/ima/ima_policy.c | 3 +-- security/security.c | 11 +++++------ security/selinux/hooks.c | 15 +++++++++------ security/smack/smack_lsm.c | 12 +++++++----- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index e53d29c3ca1c..75131153f89e 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -175,7 +175,8 @@ LSM_HOOK(int, -EOPNOTSUPP, inode_setsecurity, struct in= ode *inode, const char *name, const void *value, size_t size, int flags) LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char *buffer, size_t buffer_size) -LSM_HOOK(void, LSM_RET_VOID, inode_getsecid, struct inode *inode, u32 *sec= id) +LSM_HOOK(void, LSM_RET_VOID, inode_getlsmprop, struct inode *inode, + struct lsm_prop *prop) LSM_HOOK(int, 0, inode_copy_up, struct dentry *src, struct cred **new) LSM_HOOK(int, -EOPNOTSUPP, inode_copy_up_xattr, struct dentry *src, const char *name) diff --git a/include/linux/security.h b/include/linux/security.h index 07c0e635f124..6c50dfd70e81 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -440,7 +440,7 @@ int security_inode_getsecurity(struct mnt_idmap *idmap, void **buffer, bool alloc); int security_inode_setsecurity(struct inode *inode, const char *name, cons= t 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_getlsmprop(struct inode *inode, struct lsm_prop *prop); int security_inode_copy_up(struct dentry *src, struct cred **new); int security_inode_copy_up_xattr(struct dentry *src, const char *name); int security_kernfs_init_security(struct kernfs_node *kn_dir, @@ -1056,9 +1056,10 @@ static inline int security_inode_listsecurity(struct= inode *inode, char *buffer, return 0; } =20 -static inline void security_inode_getsecid(struct inode *inode, u32 *secid) +static inline void security_inode_getlsmprop(struct inode *inode, + struct lsm_prop *prop) { - *secid =3D 0; + lsmprop_init(prop); } =20 static inline int security_inode_copy_up(struct dentry *src, struct cred *= *new) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index b976b88c19c3..8302c8f44cd4 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2276,13 +2276,17 @@ static void audit_copy_inode(struct audit_names *na= me, const struct dentry *dentry, struct inode *inode, unsigned int flags) { + struct lsm_prop prop; + name->ino =3D inode->i_ino; name->dev =3D inode->i_sb->s_dev; name->mode =3D inode->i_mode; name->uid =3D inode->i_uid; name->gid =3D inode->i_gid; name->rdev =3D inode->i_rdev; - security_inode_getsecid(inode, &name->osid); + security_inode_getlsmprop(inode, &prop); + /* scaffolding */ + name->osid =3D prop.scaffold.secid; if (flags & AUDIT_INODE_NOEVAL) { name->fcap_ver =3D -1; return; diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/i= ma_policy.c index a96dc3ff6aa0..dbfd554b4624 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -649,8 +649,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule, case LSM_OBJ_USER: case LSM_OBJ_ROLE: case LSM_OBJ_TYPE: - /* scaffolding */ - security_inode_getsecid(inode, &prop.scaffold.secid); + security_inode_getlsmprop(inode, &prop); rc =3D ima_filter_rule_match(&prop, lsm_rule->lsm[i].type, Audit_equal, lsm_rule->lsm[i].rule); diff --git a/security/security.c b/security/security.c index 1e603e055c9f..2365626a3365 100644 --- a/security/security.c +++ b/security/security.c @@ -2622,16 +2622,15 @@ int security_inode_listsecurity(struct inode *inode, EXPORT_SYMBOL(security_inode_listsecurity); =20 /** - * security_inode_getsecid() - Get an inode's secid + * security_inode_getlsmprop() - Get an inode's LSM data * @inode: inode - * @secid: secid to return + * @prop: lsm specific information to return * - * Get the secid associated with the node. In case of failure, @secid wil= l be - * set to zero. + * Get the lsm specific information associated with the node. */ -void security_inode_getsecid(struct inode *inode, u32 *secid) +void security_inode_getlsmprop(struct inode *inode, struct lsm_prop *prop) { - call_void_hook(inode_getsecid, inode, secid); + call_void_hook(inode_getlsmprop, inode, prop); } =20 /** diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index ebab856c8748..1db4ecfea764 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3505,15 +3505,18 @@ static int selinux_inode_listsecurity(struct inode = *inode, char *buffer, size_t return len; } =20 -static void selinux_inode_getsecid(struct inode *inode, u32 *secid) +static void selinux_inode_getlsmprop(struct inode *inode, struct lsm_prop = *prop) { struct inode_security_struct *isec =3D inode_security_novalidate(inode); - *secid =3D isec->sid; + + prop->selinux.secid =3D isec->sid; + /* scaffolding */ + prop->scaffold.secid =3D isec->sid; } =20 static int selinux_inode_copy_up(struct dentry *src, struct cred **new) { - u32 sid; + struct lsm_prop prop; struct task_security_struct *tsec; struct cred *new_creds =3D *new; =20 @@ -3525,8 +3528,8 @@ static int selinux_inode_copy_up(struct dentry *src, = struct cred **new) =20 tsec =3D selinux_cred(new_creds); /* Get label from overlay inode and set it in create_sid */ - selinux_inode_getsecid(d_inode(src), &sid); - tsec->create_sid =3D sid; + selinux_inode_getlsmprop(d_inode(src), &prop); + tsec->create_sid =3D prop.selinux.secid; *new =3D new_creds; return 0; } @@ -7211,7 +7214,7 @@ static struct security_hook_list selinux_hooks[] __ro= _after_init =3D { LSM_HOOK_INIT(inode_getsecurity, selinux_inode_getsecurity), LSM_HOOK_INIT(inode_setsecurity, selinux_inode_setsecurity), LSM_HOOK_INIT(inode_listsecurity, selinux_inode_listsecurity), - LSM_HOOK_INIT(inode_getsecid, selinux_inode_getsecid), + LSM_HOOK_INIT(inode_getlsmprop, selinux_inode_getlsmprop), LSM_HOOK_INIT(inode_copy_up, selinux_inode_copy_up), LSM_HOOK_INIT(inode_copy_up_xattr, selinux_inode_copy_up_xattr), LSM_HOOK_INIT(path_notify, selinux_path_notify), diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 03d0ac37b210..8c362fe2871c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -1649,15 +1649,17 @@ static int smack_inode_listsecurity(struct inode *i= node, char *buffer, } =20 /** - * smack_inode_getsecid - Extract inode's security id + * smack_inode_getlsmprop - Extract inode's security id * @inode: inode to extract the info from - * @secid: where result will be saved + * @prop: where result will be saved */ -static void smack_inode_getsecid(struct inode *inode, u32 *secid) +static void smack_inode_getlsmprop(struct inode *inode, struct lsm_prop *p= rop) { struct smack_known *skp =3D smk_of_inode(inode); =20 - *secid =3D skp->smk_secid; + prop->smack.skp =3D skp; + /* scaffolding */ + prop->scaffold.secid =3D skp->smk_secid; } =20 /* @@ -5127,7 +5129,7 @@ static struct security_hook_list smack_hooks[] __ro_a= fter_init =3D { LSM_HOOK_INIT(inode_getsecurity, smack_inode_getsecurity), LSM_HOOK_INIT(inode_setsecurity, smack_inode_setsecurity), LSM_HOOK_INIT(inode_listsecurity, smack_inode_listsecurity), - LSM_HOOK_INIT(inode_getsecid, smack_inode_getsecid), + LSM_HOOK_INIT(inode_getlsmprop, smack_inode_getlsmprop), =20 LSM_HOOK_INIT(file_alloc_security, smack_file_alloc_security), LSM_HOOK_INIT(file_ioctl, smack_file_ioctl), --=20 2.46.0