From patchwork Thu May 13 20:07:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12256475 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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 419D2C433ED for ; Thu, 13 May 2021 20:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04FB7613CB for ; Thu, 13 May 2021 20:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232560AbhEMUT2 (ORCPT ); Thu, 13 May 2021 16:19:28 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com ([66.163.184.49]:46324 "EHLO sonic317-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232503AbhEMUT2 (ORCPT ); Thu, 13 May 2021 16:19:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1620937097; bh=Ve4ALtoFmy9R8CyWffJ7m4ih0LsnI6GwrPudCc/yRhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=bdT83/q9vZu2qsh5dW8faYjNcQYTRkqaZwDvyDTXtXlDwt6jAZ4UOR/uL1LSfHxmLlWv21Pyl1r9DG3hjd1WHWd0zQ/Tw5m04jZxmURzzBYiIA0lOv4PpLmRqI1qVWokJoVeGVVRIrs3NIqneyjb4PgCanF7JByxlw4RTCniw2hzF0FpMwTlZcpRPVP81W+AxzDRgSUcYkY1N1xD/45Y+j0A5FYMlrDr4w3Qe43s2yfzqaoDMgW72shDyg5gtBYgqup9+61ownAeYyLjZSA9cZw7rs7PllDVAUJE2fyO4ZhVYeNHKqSrwlwQzHcRyh1TC8gKmfA7lZTbtLUDh69FKg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1620937097; bh=+SH6x3rDbBj5vk0f9T1wUAaDH4sKVPXfrjFBoxxCfyS=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=VtjV69oV43EtwlSC/GwmQnxtkBbPISZ7pZ9/cIOfzgFgdV5IkUfxx6BaH2le7wvkyxjO8KLjUGns26MkvNEAFdNfOcp/d4J8RCI47L5fi5APLAP0up5IIAT00jmSVhVjwZOflGynpID3rbVsx3jm0Eql1EeVKZAmvwRWtUgpWbgw9ztV7RlxfY9KHmHJa3JMVDdFBGb2uuD4Jq+pGgF3FadgDYiiLaBOI56TEcvN3dYST36f/TVWIEtE6F2Zjj1w7504YV7j7GsI1bHiLuhzOtF33u7K/6JjXoYZUrfQFjQgT0Obut9FDu3qZ2WiunQnVVjc8PYxlQSQ4crLrUglaA== X-YMail-OSG: mZi93_MVM1l4bb2HCmkFg47zP7qEf51UygyeMwm6bOp0J7YRuYBgSZuEJDshlvg y_WuPPLL898z_JAF8BJFzc6eXe8HEBUyWd7dpbwF4fDZ1XisVMF9qfUEAA3OVUXHt47YUV4BlYSf AnwBYuHqb9F5LA0lIw0JJvrN336N_5g2xQUXMAD_PWt4O8a._U.T3QeUXjxCy4MfLjU.NrUcagd4 UnUsUK8_VlMKmRxzL0EEaYpz92NrqLdLmbt8Jpii4Hr1EXRQni8XFtpjthDS8nVqdHr5aAtldtza WSG0VaB.k9X7SifL4OUfJFoOhtJDxoFGKetS4cv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BIf.yRT8n7SsUPVQUY.Pi4BTZSt JRnigCq30hT6apoSTDNm71YZfNIorWawaqp8yqGPKaBORlmffZ6azZ.FC.jDA4tJ.ezjzmjwN.w4 Gl0cklyNCyW5u3CX86oVm7y2pO4Lx_S13NxhMG2TUani57PPv6f9gagd71Z7gzfPwzozP0GViZOz lJe3VsKzGt2qTf_r2vXJEOOgHhSJVobbQO80QfjFd.wy6y70mKHUgwcUaCuAc3KwLIZwa2FVhWfH VdcJbyFsOHnbuMs1F6_elwB29P.2RZFM4HzrLb0iwOOmxkUzI7Ckf0bOryuThJYjajy9IvMmbwzK ymXEEE501bduhS1tsZvE2l_dU8ZbTth4n2jKrdDZVsPZ.YsJ4hiaHvBJm6CWG67MvmRKpLRAvIwN cu3HGLbL9DNubh60cJaJGAJJ9T92Dw6soorDptEwji6o8XR9jm0rj40RXghZvOHOQPhLIt4Vd4Gp 8UN6O1MAMNuwXXgnn7ozj9H68AddgyXhd46_BwH_zAxKeNZ1Ee4KZJIboaoKaXJUlsu1Q0979Z3f Giwbsal4V4KbYOS5RkiwrVbG5B2vnVG9NNwwShuZcNQJXscePoRUW6Xw0LILT_Lr9bBK63mSMNia BmpuOYP15QSQnFS_E07ar9rYf81tjM2JfsdGn_TfK5blBUJr9rso230cIc9NeJMoEeE9pRais3rE vgBUQmXTR2EnHu2oq73eTyEnkfBvJr1zLVtNs X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Thu, 13 May 2021 20:18:17 +0000 Received: by kubenode512.mail-prod1.omega.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID d77a90177361f3e159594f3c8e3bbc3c; Thu, 13 May 2021 20:18:14 +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 v26 09/25] LSM: Use lsmblob in security_ipc_getsecid Date: Thu, 13 May 2021 13:07:51 -0700 Message-Id: <20210513200807.15910-10-casey@schaufler-ca.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210513200807.15910-1-casey@schaufler-ca.com> References: <20210513200807.15910-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 67140d6c17a2..0364531d92cf 100644 --- a/security/security.c +++ b/security/security.c @@ -1992,10 +1992,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)