From patchwork Fri Jun 11 00:04:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12314365 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,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 1557FC48BE0 for ; Fri, 11 Jun 2021 00:14:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2A7D613AE for ; Fri, 11 Jun 2021 00:14:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230265AbhFKAQn (ORCPT ); Thu, 10 Jun 2021 20:16:43 -0400 Received: from sonic314-27.consmr.mail.ne1.yahoo.com ([66.163.189.153]:45675 "EHLO sonic314-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbhFKAQn (ORCPT ); Thu, 10 Jun 2021 20:16:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1623370486; bh=4CSwNt8cX8Ya250gpC4XKc9j/Fty1srcfnNURtXicmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Yb3YTsroJkwuq2PTZyFo4kkNSPbiGj5vPw0lgRaHBDBqbeTcwS3qb/3QUaXG4oK0867MaOK4/bn6yLosEp6HYYqw+uXEJUcR/yqYbLLiu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gVEjSpNDxj159EdYeQ7hIBt_RVuO1J5eQ2joy 6i8.s0duT0xULV5vj_5R3Y4DjksR6ep8eT2dHJqawiWzNw5o7sOVx7sWa3qysFIWud7G21L_fTVT IGHxd6gDnvbVs96FIspHw_zmp6NFxyxZN4xAnWfb8qhw4U2cQTzu3ZlzUjj7HsvdRwZusoCeUcY1 AwSWbMJr5xMYiS31VIFGjbvgUJgvUMRCZ4nGgFhLK6dCHzrW4QM_Ab9zC1BFdqqZp4_oCzPpjFsW nZxg87WpzDIDaw9xxxC_evegU4UBpZr9Rf_sHQ6tAALcwpeYIa1eAOAuRUjvuV.Lk3vrfu1Yh7zI 95_3wa.1kxyFG0w2X3gKeG43SmpCGPbtggJ__Avmfi1SYJkRBpCzh_5T1Uz7UhqkSNpD3.xZG_zV s4rm2osHsu8HjLVcSrDZ0quUJnN.nw1sDu8kSuN2Qgi2_2vz2hrdfb0pCm2R9axEY73qvahkDKFh 0jUdoB.XlWfXlTVp_MenWsyXSf8Xs2io2BjqF6acMwrE_NmVIP_RSBjajLcvbAIBoHf45J2mLkMB Uxa2MWjxAuaUDsuuhG505ZT9nWJ3RFp_HHa98.iBJo.blaRkOBWW_bpAesRT1G813l90Nsy3DXHd wzVot5BPVuJkBapacFwpP5.PW7OxUwCNn2J.xtAtbN_oDKe.lNqmdcVp.2UOkjlQqb.KnSnHRvLj 4NkxibQKQgI_3sywXlMtOVh4hw6anLKmmE7E- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ne1.yahoo.com with HTTP; Fri, 11 Jun 2021 00:14:46 +0000 Received: by kubenode502.mail-prod1.omega.ne1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID e5bd28fb5138e5dfab52d7da1cc4d427; Fri, 11 Jun 2021 00:14:41 +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 Subject: [PATCH v27 09/25] LSM: Use lsmblob in security_ipc_getsecid Date: Thu, 10 Jun 2021 17:04:19 -0700 Message-Id: <20210611000435.36398-10-casey@schaufler-ca.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210611000435.36398-1-casey@schaufler-ca.com> References: <20210611000435.36398-1-casey@schaufler-ca.com> MIME-Version: 1.0 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 Acked-by: Paul Moore Signed-off-by: Casey Schaufler Cc: linux-audit@redhat.com --- 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 5a8c50a95c46..bdac0a124052 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -518,7 +518,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); @@ -1275,9 +1275,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 6e977d312acb..9aeddf881e67 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2323,11 +2323,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 b0faeee91d02..7f722ac04d99 100644 --- a/security/security.c +++ b/security/security.c @@ -1994,10 +1994,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)