Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp870525iol; Thu, 9 Jun 2022 16:18:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXCosMfDPpAlwDIEhJbPMJEAentzJcnhvSTkOsiI4ytp5YlOFfC6QnCd7SqtaNvTGm22tL X-Received: by 2002:a05:6a00:170a:b0:51b:d4f5:cac2 with SMTP id h10-20020a056a00170a00b0051bd4f5cac2mr38037988pfc.59.1654816711728; Thu, 09 Jun 2022 16:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654816711; cv=none; d=google.com; s=arc-20160816; b=N+MAQT66xf5YstuJdCQwDTnQIV+MTrBHTHHM+2JCMk9umct4mE9+KvFvkOyHzkOhii AHa7hPDUmKxJObEa6WxVRqjs6u+2zSa8vQqJC71Tdysv9/GzEZp0LZTSjhMjXsYBBUwm UImgqc2o0DPaW1JE4MB1LWL8hKh49tjkQ4alw7Rk0wM0rCxNLFY1uPEdji7odcWiyC7w TE0exaeTJoKmSoo+fRw5DgelKdl1USf4gJ6q8NbMicitgN6IVNyrCBlDB98+bTHrQZ3l IOTxJmcWzInwhEBq6JqGRJ+eQwNUiPJN3yQN0cVbtFUg3m2Otcpf5oTiRYYlqsY/3H6X 3R8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tUCJ/kOy69U6y+seycCErXJBdtaMYUhJx4dUkjd6VCs=; b=lBiRsqjsqqY91g11ItXwMmqts+1WF5+UMsv5+sBaNQH9HKOMuFBc+1QLGJoH7aaUoy A5qwjMbT62ygChH0Tv31jkNvBhkigE07xNhQKPr3vj6TWDpwdhKp/1+S2EajZssXlCv9 +pfN0XoQI9+icpt/urE+OjPvC4rIiRNB6dU7orVjv5sWF7tjIFM2LqgVAoXOIwTIajKN KgXygvMVG9lKjQtq9wD3E7dMmNK2JIRR3uSqOsH6TubCxAN4S5Ore6z9Dv9Am53p2U4N anUZnsgBJkGidlD/MQ6ptM2VmnK5zVm/uG95dLRDoyZHStJXNgd/k+Cxo+ehLsjQnPjF MrsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=jcfDUpqG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e62-20020a17090a6fc400b001e2818ea430si826215pjk.86.2022.06.09.16.18.17; Thu, 09 Jun 2022 16:18:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=jcfDUpqG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345881AbiFIXHI (ORCPT + 99 others); Thu, 9 Jun 2022 19:07:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245571AbiFIXG4 (ORCPT ); Thu, 9 Jun 2022 19:06:56 -0400 Received: from sonic301-38.consmr.mail.ne1.yahoo.com (sonic301-38.consmr.mail.ne1.yahoo.com [66.163.184.207]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 394C026CE7A for ; Thu, 9 Jun 2022 16:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1654816013; bh=tUCJ/kOy69U6y+seycCErXJBdtaMYUhJx4dUkjd6VCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=jcfDUpqGR/1du2i+a0NvpQQqrsOc9E7p/vtm8SAs2l8uW4q8JzGSexl+CER7SI+x/O3KMEv/H5AXrcIxoRDsyqVu7Sio2ueh5j9H+Fps4qNiB9PJBVjSWiTiizusllIxrs0478Uswo0JcWaJKoi1lz4Nzvb1f6qVgC5flaSEvtPlti2jLRtdOSoxaZYPUH3xaaTk5wxNng+pTZJ/Z/P2/wOagZeZUpse5Y17bb2x+ypsA9wOFgiZKYCSop9PGcGWQkP57OWHxlZ5goZ3geIlbHdgCtDkzaDqgqpqcu4w/f4/5yhlT/j2Om/phJnkD0okTMv9Et4Xj4bOwnjBYTL6dA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1654816013; bh=OjBxQK6ED+V8nIrLEGt6qmEvE7ROyI/Bd6snOGwRepa=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=X0NTJDToS09m51tWOf8mGZjxjlc9l7kH2gcNghyTxdcFcMgco76WM2ixF05JY3R3nlXpzweohw9sTxiemjjF5aVtco1CuqaQKfxYb8V2ybIUb47cf/tto9iB8HlAJAPFsHRULjO+VfwhIWbeVZJqrBPAml5Xh+jH4NMK0oZEIYyJ4mO6O7bETc5ber7sUB8SYmeNCjAyyiXgigrp7S2hDf47sC7gAMxe8src6kfgHhcpaSwATCBlD86QDayy6dYV5pO+u/CjujEef70b3MnGldOf7tanlFJqNbz/ZfC+mqStJwgIrlkctjxDJMl83H6ln893exq+MVMw3x9XbgKiAQ== X-YMail-OSG: szfutXoVM1mboMjdGNApmTElysmZfRtlohF68cZlam6iEaC4pNdYxtgalCyme1G KvADI1V4tNpbkd55a1Vdi7osSg3CgWanBLIoO1WX4bSz3zGHqWkstXKg7ju1attctiPAOXQd1YY5 bb2YMI63Y5gNAbV5ez6QVUQ.I4Uop1T4YdLtybKITvxe.dg5B54vgZHqgW_l0Rdyy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pGEMVKN8zFBJTCY8BJR4FPlB9KbyqENrsydOxfxq_LxA-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Thu, 9 Jun 2022 23:06:53 +0000 Received: by hermes--canary-production-ne1-799d7bd497-2pzdr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID b20ca8b25547b2b344a65fa8c4e3e611; Thu, 09 Jun 2022 23:06:48 +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 v36 10/33] LSM: Use lsmblob in security_ipc_getsecid Date: Thu, 9 Jun 2022 16:01:23 -0700 Message-Id: <20220609230146.319210-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220609230146.319210-1-casey@schaufler-ca.com> References: <20220609230146.319210-1-casey@schaufler-ca.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 e8e4a7a1029b..029c23719a5c 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -522,7 +522,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); @@ -1279,9 +1279,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 58e3f39f47ab..0986ded8e798 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2668,12 +2668,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 552a08750843..1e9c06607c39 100644 --- a/security/security.c +++ b/security/security.c @@ -2006,10 +2006,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.35.1