Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1469280rwb; Tue, 27 Sep 2022 13:38:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM66vqukvpShgkkMiakGkdhNqKe1cZXs03Yv9IfCzlzmjs7tBAvJOH6TmGHXKNjlY+yewUqv X-Received: by 2002:a17:903:1cb:b0:178:4689:8f8b with SMTP id e11-20020a17090301cb00b0017846898f8bmr29521284plh.44.1664311104484; Tue, 27 Sep 2022 13:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664311104; cv=none; d=google.com; s=arc-20160816; b=XOCp/rRAYANtsAgVDxWmfNzu+qfYtbcu334KNid4204nOIdjVx4iAcMoffv7e6axzB eQRrqtn+QihQHanuQ6Eb7XqN292a2MtgQwPE2VM5T9v9whhP/hnG/pJ+tNDKg3BN9RCv uFLYReFiB2DGVz6zGXlwNAd+QXHIsEqHbTYxeV8CerjNi1Wkhz/ForpYQcyOCjW3Fhaf R+xajRAYjuu7C/yJ5nEv8r7grRmWwkF2AHBuYEL01hAg5l7lLsBIKf4HtYHaQVz+d5D0 CkbMaa+hT15IisFpDT3xn9qvkxRJH+GXVCf8lsSMg1c+Gu+BZPv7QafXaObv6smEB/AE MIoA== 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=ARvlGx7mZdnvkYbvCVi5OxetmM11nBSp/TfSq7uJPo8=; b=LPApW4SCj7Bt51RlJmNuPDBY2H08csyltJsFwPoWwfYd+KON/jYJS63iLphcsaxIi0 vwEWUK6UgeQGRkJTkjJGhX41+hHv+y4wAg1KaubopuaNIELelB/B1XAfzYzBwj9xSh2y 4SZTi8XUlTZ0OY9INemih+VpIKAHtD3GB/7GIcC02pmEeJvpMjg0XHhG0MKQRKoUxa9n EIQn6Hs/VixJZ4zh8Atq4W51ajFlSvJRzWUUQHuYWCy96USx3NJJ4tXCVfEuYUw6f+pG 12EHPoR8Zro3wDC1DW+Msd6ouV8834i98zxarqot37syojgYH5aC1PSzfTsizJklFO/z uGNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=ETnMQLYY; 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 u15-20020a17090341cf00b00177f5be8f6asi3166285ple.498.2022.09.27.13.38.12; Tue, 27 Sep 2022 13:38:24 -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=ETnMQLYY; 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 S232577AbiI0UEl (ORCPT + 99 others); Tue, 27 Sep 2022 16:04:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232525AbiI0UEA (ORCPT ); Tue, 27 Sep 2022 16:04:00 -0400 Received: from sonic306-27.consmr.mail.ne1.yahoo.com (sonic306-27.consmr.mail.ne1.yahoo.com [66.163.189.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA8DB1E0C6C for ; Tue, 27 Sep 2022 13:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1664308965; bh=ARvlGx7mZdnvkYbvCVi5OxetmM11nBSp/TfSq7uJPo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=ETnMQLYYZhr27mpQn/qG5T4Fgetrjqac7DaeBFe7pSa2GTctjhSCsLj7xVkmLQesdcmiwnREwa3jJdCrZq7MWCJryw+ulZGFONe85V74aXqWX8hPgwq+mudawCjco/Gv9a5CpB0cg82LsnTq20TizmlXSxAIgqbNplA2AnODjFvyheAXFOlUnFnwACW0iMiAfXw/KOV2jXDMISQiOzloM5HqmJn+rNAOspQ9gXylvS+YXi4N2KiaFpHMNBVa9O4VnmNkjSTvTJvbXUxVOi4qD20ibDAx/16Wuoteo0XOrdCo0s+nGr3Ryc+eIRDDcc9jcfYO0rX+NdYy/0T2jQu+eQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1664308965; bh=yte57HEQ4ImA3Y8jiYIuuB2LPOLKz5wNkPQK1eA7sgd=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=XWAISSpQTZdguyPisE7uAwXTrBwkFbsnkhNzcDWBf+TAIgt8HdBMq0G28q7c4Wd/C8AJxvr9/syk+syiFPHmhtXw0ohT/wYkY5YSAQ/hnsOCIaea7e42x458prxo5DCCfLJ0iUpewh5g62QTrVfjWrp1vif6oJRD1bMhOeEx1yYSChli/D8P5/vqxttSFrJZrwMLSxxWC2eBC8MchFhAp/ZIpQCPaRWV4lLJZgRx1s4qruGfNfZX7cFNATimRhYYOESEqLtU8pov4cQSdKUXoY8debg8iADSZ+q9R/X3AA2XsH9t5itoYCyj7CGYu5Exsu8Q2O7xTIzxWu9oMXYvPg== X-YMail-OSG: L.CEY3cVM1kU6n4Tk57aDEbhquTUHPlbRdYJp29gdf1ukV0yGRsnrD23fx.DkSv X7X0Uk6E2wT6UZD3vc0xqO7fF1ZcWmK.gxhGViT7Fkn3.H7XGKjoH0xVGD_EIEee8MZyKfy9VkET 4djR7XHCOuGUiPFtH6cvsqYoDEc3zW1SzUZn8eemQxnwk0Kglkka9RUqZ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OaissOWoStC 9Mmb3fuAotVVOoCyNOVOmNGJs0VvdszFLTKEuUwk- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Tue, 27 Sep 2022 20:02:45 +0000 Received: by hermes--production-ne1-6dd4f99767-97ndb (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 0896e936b45c39858cb958d2af309d20; Tue, 27 Sep 2022 20:02:43 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: casey@schaufler-ca.com, linux-audit@redhat.com, jmorris@namei.org, selinux@vger.kernel.org, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v38 16/39] LSM: Use lsmblob in security_ipc_getsecid Date: Tue, 27 Sep 2022 12:53:58 -0700 Message-Id: <20220927195421.14713-17-casey@schaufler-ca.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220927195421.14713-1-casey@schaufler-ca.com> References: <20220927195421.14713-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 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 d9ab76c909e0..bedb2047138b 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -541,7 +541,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); @@ -1304,9 +1304,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 d083c050d660..9eb2d84439da 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2643,12 +2643,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 9c49406e5ff9..afd6f6698fd7 100644 --- a/security/security.c +++ b/security/security.c @@ -2030,10 +2030,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.37.3