Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3499914iog; Mon, 27 Jun 2022 18:07:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uFKCSojifx2FpQahXNkKoei3eInVZtjKiKQEE+iBkJmBLDxl2UzzIuE/2r73bUnHg12Pe9 X-Received: by 2002:a17:902:ea02:b0:16a:57bb:d344 with SMTP id s2-20020a170902ea0200b0016a57bbd344mr988556plg.150.1656378473763; Mon, 27 Jun 2022 18:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656378473; cv=none; d=google.com; s=arc-20160816; b=fuc8/jmBTZ3VsskOAxIhXo12KZJhwZFL4A4qM3/EdMfITVIeOcGOmQWBCxMTMDwkq2 JTDZYUsPe5quz01N1d5Rg79rkmM3KHaqzwojRnlBrRFPKKv3uygBX3CBL8NgGy9XR10x +EfdGH8MZPBuWXhbEfYzpNYgq1Epc+H2Gd3Lwi9SN6W1dKTeg8ynVPuMnNXUx3MpcnxG Roj+IfSn4iHYq6arS5EZElR2V6vQ3OXqKhFifPL76n6zS0omgU8gx/V+fqOnemfZs6fd Clm/mkPjSo3hEn+6ZpKX3lDKuV4XYmoZr//nibouQYJA1UJB23/2axieb1jbMb2ZT65v lCyw== 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=K8xi7gp5M8pAmE3PRl0lN01LpeF0ik++w9GdYI+Fn+Y=; b=wJbzTrfz9Ezjieyh9xM0IlrhkDmFNT9E2eqh2noOjAu/CZILgLFk9qhg1IW8hQMk+0 OcSf2+u9rQ6sZysxAUqJlFFYr+xPMhdViR3NvXzM3uhuaUhZDKV+THUXrx5wfRq7/88R uFNY6XjIeMvnntQLAEOuLb8kPjL8MLysuZSxMp35p/ITZurwJziPDB6/EZnQOaAYD3LU nqD6H1EORYATqwWV/Bof3vXNZWcqmXTRFzQzOhPBo4wulfahAXFN4Wtw5ntqSoyvN+GM YhKsf5DL1KoVkFV8TA4LNwXsa9jeyAHmXVsa0aUnscZtst007I1Y7VZAOHKhDfFvfT8c oQZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=lr2Axwq+; 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 f6-20020a170902ce8600b001677fa2026asi16185365plg.609.2022.06.27.18.07.41; Mon, 27 Jun 2022 18:07:53 -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=lr2Axwq+; 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 S242925AbiF1BE0 (ORCPT + 99 others); Mon, 27 Jun 2022 21:04:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242737AbiF1BEO (ORCPT ); Mon, 27 Jun 2022 21:04:14 -0400 Received: from sonic301-36.consmr.mail.ne1.yahoo.com (sonic301-36.consmr.mail.ne1.yahoo.com [66.163.184.205]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC45E23157 for ; Mon, 27 Jun 2022 18:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656378242; bh=K8xi7gp5M8pAmE3PRl0lN01LpeF0ik++w9GdYI+Fn+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=lr2Axwq+TGtqUeZkGzlse/nk++P3Bc+IIxleu89pHS4W3FSLOwMSm+ySiEfGvWb5cjBaWeCK2mO31vMLDZFZpGtxki+5MfhsCiwdKiKa7agfWFP1ewjEuqotGqTT/ZU0mP1qPdN0GZesn46NwpKg9RxIM4O/6F6X0GQE3daVOYeawoYkpghvHoi9cAiOj8laJjZTmtDpTOn/HQZle/5VAYExRuXHemUBWwvcBn98yNfjBj5Ee/iWq47Q7aWyafWOqIR5a/mU4YXLAQ12Cw2vSZzNM8HL73B18Bmv/L6GWoEWoOz3Sw+akzc6qXOMvJu9xsNgwixsOECFMTG/gfc2gA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1656378242; bh=2B1rYmJl4N+Nm8yOhgrPK8zBOFBHrc/L7H3Qx5zTfG2=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=YM2oPyhhCUEiSormgMZiSRE4a+/Y4HH1nQAH6jWUViDdJcBdNot9hf8AD3mJ6xoR8YSYpFi1fSCXDF1bCEbZfPTrWqJ7qWc9L/mdxQE3SvmJuWpmNuW0/AkyxcfnunrzXfI2FEiWNEYkc1gA3Mi7lk8ECHUvJzbC3p/qFQ6R5/46kN9FwMllemA59eqetPy0QEZWk5zgCUXfSU400Bt4q2f+tPgiHAm8v7tyim0xUXwXI/Tjjl7QA6uVzHQK4RVedwHOJFLkwmEVSL+2WHUTj+h5uulLCqZtfM1THVbUX10oeT+IZp8e/vQ9JSqYrLvFp6OkyssvVWHZIGuWMJTHoA== X-YMail-OSG: M1xVGCoVM1n6dfteoX9V1izjn5HkOXDfGinY3b15x7_.O2PVCG7jwIX5_DEReOr .LL4bX_c34sX7DJczi4htMkDd.NRrQEIXla6ePV1MN8n4gzZ7EmH2vXvCgkz8WHMmokhflUea4Az hXHf2zSwDm4F1.E2l2tgEDbmgDtk2L9UOQ9SDHNM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Rh5sA_oP138ONgG0 X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 28 Jun 2022 01:04:02 +0000 Received: by hermes--production-ne1-7459d5c5c9-fdkvw (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 7521274ed3fde3701c40279c1a2b59fb; Tue, 28 Jun 2022 01:04:00 +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 v37 10/33] LSM: Use lsmblob in security_ipc_getsecid Date: Mon, 27 Jun 2022 17:55:48 -0700 Message-Id: <20220628005611.13106-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628005611.13106-1-casey@schaufler-ca.com> References: <20220628005611.13106-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 f2ba966c8838..94537d1feb9a 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.36.1