From nobody Sat Nov 30 10:45:37 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 96AFF1A4F25 for ; Tue, 10 Sep 2024 18:53:23 +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=1725994405; cv=none; b=kQsXJm2sJVTA6uPtJ7trfy80vuS0ji40oZ1gp0hZrQcu0arNS7hMafAg19CM2R+RgSyGBF439N+apu4mVdz2jaK+lKmDaWqFNHrIFpYaOUtJ/XrN9vRbZ0IcgloePAMsLlePWMwZjwmXsy3HdnkJrpE4xp9hKSvX4OOcgIefJFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725994405; c=relaxed/simple; bh=IoX9nQjI2oP0imTJJZDHPStaBUxY820d4vgsxZmjUYo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UGvOn7zAiW4uYO+sWTCRleT2I/S3IFTUeNxWWcSYQ0++nRPMRNLDmfIqqZnGMzeY6T7xcaK8l6aJ38R22qKJYTaMBUMIboOYXToGSmemdVArM5UfoetLcqX8Wf17imtM+jGNBnVg2DIeBpRF4U72Zmek7SBpvFvLJkAMzddKq4k= 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=BkVxSMKZ; 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="BkVxSMKZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1725994402; bh=snRkCW1CoQhwTkFHaGmHmPb0/0EzthT9FmZrwfJIwtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=BkVxSMKZKXeVo2Zqj/ZrDy8064QucMXIU6a05eaBjTWDtgmScGZWhcjX5AJHup4kZgy7FFyCj8R5tBJbJKvBGSzJJd0jJxBPDwmr7xdpLPy4Znlrl4T+0tVzKuMWCyE9HN1ANQMgPGwYNSUFBtCtLuq0DHf/ZxzUEnBpzT9uVuTMyQ/UIqThGAMPfBYTW/1oeHOk9A3CTqi6nc5q6Ca/n2ZwwvE965JR4YNbG2ZOAyNXrVUqAOz6xjyyg7UyVlRmk3ArgINagYLkXUTX+DKE0rq7OOgHIJB8UkZ3bi3lHpUDYdYgiHOgqiuYhEiS1lo4GbIrCISs8IlIVzE4ckYjqA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1725994402; bh=BlycUwdOnb1m2nimtfebdN2x1gkgraVjxrHy/ZYvjk6=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=MVvG7iOqEEhWrBmbDM+OroXNZlD/Wi6BShgK3yzVbUXFekRv0weRH5xU3iU/fSn9c0oKA8udtlkulWbZzE/3TYtpzYUXG852v6+CtuCzZ//YPhaNS5slOoJbwiUNgZWGOKPX750dDdFLiOPBaPclq7adtawabtfTfY4BGIjw0qNAM7JyOpMFNfBbUU6PKB003Gr5XBPW/pb9kCm2V4ASdp+QYSXHv0+FBOUMSalZIl6IwSUlQSeRHNC0O3948O7+99h4eVhO9DKlUY90i+SRQVUdtcmdooGTUBQUVEIwvY/2NMGgs5bNMj75CqE96ElwPSmMMXU8iWKqbaLrx6muXA== X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vid0Bz5sXPEg0KVu9KoML_QAEyyBCD8_zZt0_xIsIzcd BlcdP9U5KZmlQMMdf_jlHnsk3dDRyvp0Ok9JYmMftJzZsE1N8nYb1Lx5RmmBLpbmVoS4XsfW69Lq yBNr0nOxaf8X9HA8gnk7hgSbxtb2ixEzLOJHW0WrbS7nA5MsX8jKYSAxqAE77MHAaSwRzM7TISP9 hVUlf5_UIuNopGkl3vHB61Bw_VTmHveOymXcuL1Q- X-Sonic-MF: X-Sonic-ID: 5dba500b-dbef-4d20-9d04-e54cd028f336 Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Tue, 10 Sep 2024 18:53:22 +0000 Received: by hermes--production-gq1-5d95dc458-4tw7n (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID bfec55394db9c3ecf7e1196118de0a4c; Tue, 10 Sep 2024 18:43:10 +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, audit@vger.kernel.org Subject: [PATCH v3 05/13] LSM: Use lsm_prop in security_ipc_getsecid Date: Tue, 10 Sep 2024 11:41:17 -0700 Message-ID: <20240910184125.224651-6-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" There may be more than one LSM that provides IPC data for auditing. Change security_ipc_getsecid() to fill in a lsm_prop structure instead of the u32 secid. Change the name to security_ipc_getlsmprop() to reflect the change. Signed-off-by: Casey Schaufler Cc: audit@vger.kernel.org Cc: linux-security-module@vger.kernel.org Cc: selinux@vger.kernel.org --- include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 22 +++++++++++++++++----- kernel/auditsc.c | 5 ++--- security/security.c | 14 +++++++------- security/selinux/hooks.c | 9 ++++++--- security/smack/smack_lsm.c | 16 +++++++++------- 6 files changed, 43 insertions(+), 27 deletions(-) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index f53323e52fe1..315bbe1f63fc 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -253,8 +253,8 @@ LSM_HOOK(void, LSM_RET_VOID, task_to_inode, struct task= _struct *p, struct inode *inode) LSM_HOOK(int, 0, userns_create, const struct cred *cred) LSM_HOOK(int, 0, ipc_permission, struct kern_ipc_perm *ipcp, short flag) -LSM_HOOK(void, LSM_RET_VOID, ipc_getsecid, struct kern_ipc_perm *ipcp, - u32 *secid) +LSM_HOOK(void, LSM_RET_VOID, ipc_getlsmprop, struct kern_ipc_perm *ipcp, + struct lsm_prop *prop) LSM_HOOK(int, 0, msg_msg_alloc_security, struct msg_msg *msg) LSM_HOOK(void, LSM_RET_VOID, msg_msg_free_security, struct msg_msg *msg) LSM_HOOK(int, 0, msg_queue_alloc_security, struct kern_ipc_perm *perm) diff --git a/include/linux/security.h b/include/linux/security.h index d739a4cf43d3..c8f020cf2a84 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -277,6 +277,17 @@ static inline const char *kernel_load_data_id_str(enum= kernel_load_data_id id) return kernel_load_data_str[id]; } =20 +/** + * lsmprop_init - initialize a lsm_prop structure + * @prop: Pointer to the data to initialize + * + * Set all secid for all modules to the specified value. + */ +static inline void lsmprop_init(struct lsm_prop *prop) +{ + memset(prop, 0, sizeof(*prop)); +} + #ifdef CONFIG_SECURITY =20 /** @@ -285,7 +296,7 @@ static inline const char *kernel_load_data_id_str(enum = kernel_load_data_id id) * * Returns true if there is a value set, false otherwise */ -static inline bool lsm_prop_is_set(struct lsm_prop *prop) +static inline bool lsmprop_is_set(struct lsm_prop *prop) { const struct lsm_prop empty =3D {}; =20 @@ -500,7 +511,7 @@ int security_task_prctl(int option, unsigned long arg2,= unsigned long arg3, void security_task_to_inode(struct task_struct *p, struct inode *inode); int security_create_user_ns(const struct cred *cred); int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag); -void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid); +void security_ipc_getlsmprop(struct kern_ipc_perm *ipcp, struct lsm_prop *= prop); int security_msg_msg_alloc(struct msg_msg *msg); void security_msg_msg_free(struct msg_msg *msg); int security_msg_queue_alloc(struct kern_ipc_perm *msq); @@ -551,7 +562,7 @@ int lsm_fill_user_ctx(struct lsm_ctx __user *uctx, u32 = *uctx_len, * * Returns true if there is a value set, false otherwise */ -static inline bool lsm_prop_is_set(struct lsm_prop *prop) +static inline bool lsmprop_is_set(struct lsm_prop *prop) { return false; } @@ -1350,9 +1361,10 @@ static inline int security_ipc_permission(struct ker= n_ipc_perm *ipcp, return 0; } =20 -static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *= secid) +static inline void security_ipc_getlsmprop(struct kern_ipc_perm *ipcp, + struct lsm_prop *prop) { - *secid =3D 0; + lsmprop_init(prop); } =20 static inline int security_msg_msg_alloc(struct msg_msg *msg) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 014d23370384..3e051014484c 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -1397,7 +1397,7 @@ static void show_special(struct audit_context *contex= t, int *call_panic) from_kuid(&init_user_ns, context->ipc.uid), from_kgid(&init_user_ns, context->ipc.gid), context->ipc.mode); - if (lsm_prop_is_set(&context->ipc.oprop)) { + if (lsmprop_is_set(&context->ipc.oprop)) { char *ctx =3D NULL; u32 len; =20 @@ -2638,8 +2638,7 @@ void __audit_ipc_obj(struct kern_ipc_perm *ipcp) context->ipc.gid =3D ipcp->gid; context->ipc.mode =3D ipcp->mode; context->ipc.has_perm =3D 0; - /* scaffolding */ - security_ipc_getsecid(ipcp, &context->ipc.oprop.scaffold.secid); + security_ipc_getlsmprop(ipcp, &context->ipc.oprop); context->type =3D AUDIT_IPC; } =20 diff --git a/security/security.c b/security/security.c index 859b37e51796..410bf69af427 100644 --- a/security/security.c +++ b/security/security.c @@ -3611,17 +3611,17 @@ int security_ipc_permission(struct kern_ipc_perm *i= pcp, short flag) } =20 /** - * security_ipc_getsecid() - Get the sysv ipc object's secid + * security_ipc_getlsmprop() - Get the sysv ipc object LSM data * @ipcp: ipc permission structure - * @secid: secid pointer + * @prop: pointer to lsm information * - * Get the secid associated with the ipc object. In case of failure, @sec= id - * will be set to zero. + * Get the lsm information associated with the ipc object. */ -void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) + +void security_ipc_getlsmprop(struct kern_ipc_perm *ipcp, struct lsm_prop *= prop) { - *secid =3D 0; - call_void_hook(ipc_getsecid, ipcp, secid); + lsmprop_init(prop); + call_void_hook(ipc_getlsmprop, ipcp, prop); } =20 /** diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index a2da81d0d5f5..10c7fc61a786 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -6328,10 +6328,13 @@ static int selinux_ipc_permission(struct kern_ipc_p= erm *ipcp, short flag) return ipc_has_perm(ipcp, av); } =20 -static void selinux_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) +static void selinux_ipc_getlsmprop(struct kern_ipc_perm *ipcp, + struct lsm_prop *prop) { struct ipc_security_struct *isec =3D selinux_ipc(ipcp); - *secid =3D isec->sid; + prop->selinux.secid =3D isec->sid; + /* scaffolding */ + prop->scaffold.secid =3D isec->sid; } =20 static void selinux_d_instantiate(struct dentry *dentry, struct inode *ino= de) @@ -7252,7 +7255,7 @@ static struct security_hook_list selinux_hooks[] __ro= _after_init =3D { LSM_HOOK_INIT(userns_create, selinux_userns_create), =20 LSM_HOOK_INIT(ipc_permission, selinux_ipc_permission), - LSM_HOOK_INIT(ipc_getsecid, selinux_ipc_getsecid), + LSM_HOOK_INIT(ipc_getlsmprop, selinux_ipc_getlsmprop), =20 LSM_HOOK_INIT(msg_queue_associate, selinux_msg_queue_associate), LSM_HOOK_INIT(msg_queue_msgctl, selinux_msg_queue_msgctl), diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 1f478bb08779..7926f40bc7db 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -3442,16 +3442,18 @@ static int smack_ipc_permission(struct kern_ipc_per= m *ipp, short flag) } =20 /** - * smack_ipc_getsecid - Extract smack security id + * smack_ipc_getlsmprop - Extract smack security data * @ipp: the object permissions - * @secid: where result will be saved + * @prop: where result will be saved */ -static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid) +static void smack_ipc_getlsmprop(struct kern_ipc_perm *ipp, struct lsm_pro= p *prop) { - struct smack_known **blob =3D smack_ipc(ipp); - struct smack_known *iskp =3D *blob; + struct smack_known **iskpp =3D smack_ipc(ipp); + struct smack_known *iskp =3D *iskpp; =20 - *secid =3D iskp->smk_secid; + prop->smack.skp =3D iskp; + /* scaffolding */ + prop->scaffold.secid =3D iskp->smk_secid; } =20 /** @@ -5157,7 +5159,7 @@ static struct security_hook_list smack_hooks[] __ro_a= fter_init =3D { LSM_HOOK_INIT(task_to_inode, smack_task_to_inode), =20 LSM_HOOK_INIT(ipc_permission, smack_ipc_permission), - LSM_HOOK_INIT(ipc_getsecid, smack_ipc_getsecid), + LSM_HOOK_INIT(ipc_getlsmprop, smack_ipc_getlsmprop), =20 LSM_HOOK_INIT(msg_msg_alloc_security, smack_msg_msg_alloc_security), =20 --=20 2.46.0