From patchwork Thu Apr 7 21:22:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12805731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88514C43217 for ; Thu, 7 Apr 2022 21:27:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231466AbiDGV3s (ORCPT ); Thu, 7 Apr 2022 17:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231441AbiDGV3p (ORCPT ); Thu, 7 Apr 2022 17:29:45 -0400 Received: from sonic311-30.consmr.mail.ne1.yahoo.com (sonic311-30.consmr.mail.ne1.yahoo.com [66.163.188.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BDFC1A395E for ; Thu, 7 Apr 2022 14:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1649366863; bh=BtHo1QSoNl0+JSUijRm0h7RCZJK8XQ8GDtQ9CbzS1Bo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=L5/tabTZHLYxoHwIhJH3sxIC6GxQ6/JovdjnGvJeJbu92BX2QCdtKAkCETyopZGF0VkOHd/pyBTi8TN32b9L1GRMsfbEOwJwYZYpRuT3IkqaXcwD74DE4wmfwvePnjkn8naimo2Ad5CdTECTfXIHkBYTRQniBea/GoIIZmzSE4v2DSupRMq2nWTSJzAt9Fg0vqwoTTF5mFs2hsgJakzKkrB9T3c++6zyL4m9PXt0YTuRgwYAUd3CSNnlp2kTUv+jCD5sWT4HKs7v7H95vUh896h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oOncsW0 OPBrCwImCL6RvN63BScuQqXWitl7Ndx2nkd5.GnOpyCOJ4PaEzTvPQDjsHIgP6IKP.Fsh_XbLpbx H.jv.gNzEHb1ZDnlsJiVTcb58k1UzYjkl_0sR.R7ZI0_rbrg6ZTBVvLExjGccOkjz4QfBHqGRqyk tyGeILjs.1Z3EwIh7a1QSi1wXAgw_0kIZAAAYFdo1GBHgB3Wx.qjevKOfsDYb25sOKewqErYXCKl XcoUzKQw0y4D3aW6IhnMjzj4TI1bJr1Vpkx8I4yw1Io9tK44xTW6HU8Etr5LCCaEwuG0scD.9eSY znRA339w0fS9e_xcIV1MTOWonQlEPDgYXrS3z4bPwm27LgWqTi.eZpswVcYcjOk1bk3fcqYPBnqr kBihAvqasBGmVrea9eLyORJPIogkizEuznBslNzCFVP_MreJX3ul0fFqe5aGU4E4YKIq5Z9gBJZy fKHTn1L_GkYfRbWRTlqScLUSse3ZUssjzkX8gVSu5JSZlXgmfPSnoikVllnikD8xvE0y7.2Veil2 Tajo6Z7KSyA5SsGaX9QemwH9g2M0jXrIYI.9yXhUveYdxMZ3RhxbWVnkkDOOzEaOWCVTvu5t85p9 Q2gp26tikvJhBswa5hxIs7lhzgyeMdX2iMLef1tIZ_kkXXwMqEle7fYvXl5wkWhbdr.N_TnIcvSd 9bIzhSDlVwlLoGOlwSLVOL8nYFOl1AaFqyC1ioFyzdavd9CqH7H5PnseiDtvdO.I55zKCUnS1BAV pgasvDai6F1_E8H1.RrwesjvsZo.dEIA- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Thu, 7 Apr 2022 21:27:43 +0000 Received: by kubenode522.mail-prod1.omega.ne1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID cdeff4c1363a36af98b9100857bab95c; Thu, 07 Apr 2022 21:27:40 +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, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v34 10/29] LSM: Use lsmblob in security_ipc_getsecid Date: Thu, 7 Apr 2022 14:22:11 -0700 Message-Id: <20220407212230.12893-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407212230.12893-1-casey@schaufler-ca.com> References: <20220407212230.12893-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 4f940ef06e51..4646ca90f457 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -520,7 +520,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); @@ -1277,9 +1277,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 10b9dc253555..d125dba69a76 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2662,12 +2662,17 @@ 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 6e6e44213d80..131c851dd681 100644 --- a/security/security.c +++ b/security/security.c @@ -2012,10 +2012,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)