From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 90F26C433E0 for ; Fri, 24 Jul 2020 20:41:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66569206F6 for ; Fri, 24 Jul 2020 20:41:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.b="f8+lrxTW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726562AbgGXUle (ORCPT ); Fri, 24 Jul 2020 16:41:34 -0400 Received: from sonic315-22.consmr.mail.bf2.yahoo.com ([74.6.134.196]:37664 "EHLO sonic315-22.consmr.mail.bf2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726503AbgGXUld (ORCPT ); Fri, 24 Jul 2020 16:41:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1595623292; bh=vzP9SVfl+eOo9JpynABEKPSlrd4gSJq7mZo/Plj+bqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=f8+lrxTWXdxkjF6LDgxbwxeET6XmsXOkVRPNBceRJWM7nPE4Tukt1y0EoAw89bmH7tbpManTT8kxwNKlt654eKqNAKYYRSG56iRdZVeF8LiAlb3Ve2N+06CYPOokb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z4AjwCVuY.g7EL.kSagG10lQoXA1PBUCX9fVQkhqu3WS.oqG.ZJk6.i5lUqwB8Vci kbp3vvmzHSeOWhfI8Tp2NvMcfEaSE.3nryijpsjNnunUjGp_fcaHqEVZRxh9Eh21xlRNhGa.u1I8 k6zx43PJG0Ar2nABAyLa9yed5W6H1s_ZuP0VtnFIRv3lPZgOwkBirfDDKnISvvnRtHGDFWya5q9y RIyAPdYAe2N51PoXexkxndg.hDqh71BjOhBwM7rMejrgjYF0IfKkVB9mztsagbp7YtSvCmJsd6Lq 2KvYDBGs.IqdoYFY3etvH6GYD._4T5YB1qz0zJ5SVVF0P6u2iW9MT4pQPKrJbupdbghTS60_bOG4 vNq4zxlTR6cQ4b0RSVDNR8Ku4l1bkCWnqZQYm0w5jpHua8Q8TPPppFk_Q8qYSKZUxKsp1Qx84nRn orkB.dv5tF30oxKw5gGyHiQ35IExKRov07dGUUMx6rW5uTE59Lp6abUjQBNMEoQ3hdm608vYcxcd x.sVWz6qU9B6U8n5tYaGYiW3vz.eWSAb7Kd1x5HqTiSa6HsUiSRVnk8PzJlcLSX4rFHcFhGGtPBa OXoYkyB1CqPGho2wxy7z071HwhLFpENA- Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.bf2.yahoo.com with HTTP; Fri, 24 Jul 2020 20:41:32 +0000 Received: by smtp418.mail.ne1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 006a0575bffb1524bcd8a8c621c1f5ce; Fri, 24 Jul 2020 20:41:28 +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 Subject: [PATCH v19 08/23] LSM: Use lsmblob in security_ipc_getsecid Date: Fri, 24 Jul 2020 13:32:11 -0700 Message-Id: <20200724203226.16374-9-casey@schaufler-ca.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200724203226.16374-1-casey@schaufler-ca.com> References: <20200724203226.16374-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: There may be more than one LSM that provides IPC data for auditing. Change security_ipc_getsecid() to fill in a lsmblob structure instead of the u32 secid. The audit data structure containing the secid will be updated later, so there is a bit of scaffolding here. Reviewed-by: Kees Cook Reviewed-by: John Johansen Acked-by: Stephen Smalley Signed-off-by: Casey Schaufler --- include/linux/security.h | 7 ++++--- kernel/auditsc.c | 7 ++++++- security/security.c | 12 +++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index df5e4e8d8e2c..7883975ea6b0 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -493,7 +493,7 @@ int security_task_prctl(int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5); void security_task_to_inode(struct task_struct *p, struct inode *inode); 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_getsecid(struct kern_ipc_perm *ipcp, struct lsmblob *blob); 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); @@ -1214,9 +1214,10 @@ static inline int security_ipc_permission(struct kern_ipc_perm *ipcp, return 0; } -static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) +static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, + struct lsmblob *blob) { - *secid = 0; + lsmblob_init(blob, 0); } static inline int security_msg_msg_alloc(struct msg_msg *msg) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 3c9525c72c89..ff30714c89dc 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2307,11 +2307,16 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat) void __audit_ipc_obj(struct kern_ipc_perm *ipcp) { struct audit_context *context = audit_context(); + struct lsmblob blob; context->ipc.uid = ipcp->uid; context->ipc.gid = ipcp->gid; context->ipc.mode = ipcp->mode; context->ipc.has_perm = 0; - security_ipc_getsecid(ipcp, &context->ipc.osid); + security_ipc_getsecid(ipcp, &blob); + /* context->ipc.osid will be changed to a lsmblob later in + * the patch series. This will allow auditing of all the object + * labels associated with the ipc object. */ + context->ipc.osid = lsmblob_value(&blob); context->type = AUDIT_IPC; } diff --git a/security/security.c b/security/security.c index ce0934395c53..c74c7722e5f4 100644 --- a/security/security.c +++ b/security/security.c @@ -1866,10 +1866,16 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag) return call_int_hook(ipc_permission, 0, ipcp, flag); } -void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid) +void security_ipc_getsecid(struct kern_ipc_perm *ipcp, struct lsmblob *blob) { - *secid = 0; - call_void_hook(ipc_getsecid, ipcp, secid); + struct security_hook_list *hp; + + lsmblob_init(blob, 0); + hlist_for_each_entry(hp, &security_hook_heads.ipc_getsecid, list) { + if (WARN_ON(hp->lsmid->slot < 0 || hp->lsmid->slot >= lsm_slot)) + continue; + hp->hook.ipc_getsecid(ipcp, &blob->secid[hp->lsmid->slot]); + } } int security_msg_msg_alloc(struct msg_msg *msg) -- 2.24.1