Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp705742pxp; Fri, 11 Mar 2022 12:53:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLttU3tOF6sQSFV8sx1A9l7jECsSF3IhSV+B9cWOc3C6UFqs9bY/wt+6xUhe7l9IngKgTd X-Received: by 2002:a65:654f:0:b0:378:b8f6:ebe4 with SMTP id a15-20020a65654f000000b00378b8f6ebe4mr9780593pgw.399.1647031991163; Fri, 11 Mar 2022 12:53:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647031991; cv=none; d=google.com; s=arc-20160816; b=VDbTEAt9IjUqeKEVdrbyCIExsNZrCb9a0QbNjkbBV66Qs7tXd+6+ND+mDGUKhOzuVj plfpEhbDR2z2z141bEKADPk9z5MJdESdLpk6WP1TRLTNZ9kQQdux7EZaA9lBUar3f9X5 8BOfDw11Ls3W2yFd7LPpZ+PY2i34ekXMufxfBPYa9RNchw7NJv7XeR6G1jOZUvTvm4+s CvXVHSShLh3INGV+3yPjsYxHmUDO9uRLH4C4iOqtA5EFSbsQyGzjZkXLxgY0j5D4K88g BhtYmlJJHW2m8NNyj0goZimDpwsZ3y38eN1I4Yye9OHGuuogpduUGGWDQuHOgNm/Vd7P D4LA== 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=j5PSxx7pxMuUob08WR476BkBCAlorDOEyvyzPeGaYoA=; b=eWiN4ZpDLQxBr0PKxvHoNlYmQKmpFJXnF3pty559uVwRB2DLDynJIx1XEfp7vUv00i Pp993K8cs8MtFtbkvT4JSPo0oNuw1CUbehQscx3RJate9y505hbPm7AzoVilk2ovMGwL 0CGoA43eDw4ccOeT8zZsDDjGkSAPHChU2pHLkTV4ufgw/u4sGH1pOqzbXZGpp6cv8+Ft uNNyOOLerhxjfAmWh9U0VfMuZiK9VTwYBCa3P3XUfdgfe9UK1Nzpzh7JVNlUA1aDAG71 afixkWBDg0TP7YP5oPEhwqLJsUQijZ+oWBGPR4ybUECKYwi5VKjgV9kr+vHlBdViz28L cjQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=iTdfDZ8e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x17-20020a170902ec9100b00151d9f62e91si9400512plg.187.2022.03.11.12.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 12:53:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=iTdfDZ8e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D5BAE1DED6D; Fri, 11 Mar 2022 12:45:03 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344950AbiCJXwi (ORCPT + 99 others); Thu, 10 Mar 2022 18:52:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244209AbiCJXwf (ORCPT ); Thu, 10 Mar 2022 18:52:35 -0500 Received: from sonic315-27.consmr.mail.ne1.yahoo.com (sonic315-27.consmr.mail.ne1.yahoo.com [66.163.190.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCE4719E738 for ; Thu, 10 Mar 2022 15:51:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1646956292; bh=j5PSxx7pxMuUob08WR476BkBCAlorDOEyvyzPeGaYoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=iTdfDZ8eI4pr+BhOrRpsZKPRbRKowKfHlxXR7D1YDdYl4tgmNhj+4b7h/oIOBYq5MFQXg650eV6zg+pF3GD56NEH0VGkz0RDBnX7d4Rwffbj3AXugKqhPUnpKaI1MlmdE1MElEPSJxggGBjx+H0bXd6q1AuspdSz7ZZfhEuNvCWw7GiVCKft0K40zPcmFiNtC00ZDA9VZEHD+zQstdG73NkAZiuOX5rc1jGLiHlBz+mv2mJlv+huGp1Gm7DABHtOTm7V38kccapJgkJDJuBqrFb0qnp2Rf0G2H6nmu5CbQYWwysjQC+NbIzjunW3uknmFqlpPTdJ+Co78HY2MnDWTw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1646956292; bh=DptinqG2ColU012LyJkUEyjlm8zZSqkDFpan41FTMsY=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=X656Ei2rV5uPy4DNbOhu99IUXqSqXhgmHfXxnhqfZgZOzhTWjARbV+6rgjqTCNT59rIDA2iekPjW4zgakdNXyd+ixa0A2m5fiVM6W0eif6AvC2pTPzC9LdS7h6uZTQtxif/IIXTjNYPNgzarIecekTTbcXVry+Wd4iJ7g84aZo4grcGcntwF29XlAvpunAmGosADsnhYbVr1zxA4NHu5BWai/t7bpagaUziuo2aj9Y11OrgSNaw8D/jikuT179xs+2Qv+5HRXlc5GWG8GwPCZap/T0UG1eYDhGWnmzhvZtJu9/H9xCMNrO2gNtgxp1EAhpKA+HXc3GGqAkTjgb4xvw== X-YMail-OSG: .jbe92UVM1k2UuecCC1FC4xDqNgz00Ua_AT_g0exjcVYmn.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iO_902E7ItY7N7OlXs7wXj_5pUOsCarEe.SV33FlvZUBAhCo01u5 B.tFxFDwbfCpF4DmyNfZygjXCmTJNXS4S38LAAYPq3KdylmMNkOND7.loNOfq4u1ZY8NvIXQ8ubn cTqBPzjwQrS2WuaQmi7DzdSu6YRgQ X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Thu, 10 Mar 2022 23:51:32 +0000 Received: by kubenode514.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 02d0d7342d647b4cf843030be84eedee; Thu, 10 Mar 2022 23:51:28 +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 v33 10/29] LSM: Use lsmblob in security_ipc_getsecid Date: Thu, 10 Mar 2022 15:46:13 -0800 Message-Id: <20220310234632.16194-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220310234632.16194-1-casey@schaufler-ca.com> References: <20220310234632.16194-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,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 a104ec0759c2..1814516509ec 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 5edb16cb12e0..598e0de45b04 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2610,12 +2610,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 ffdd366d2098..815200684bcf 100644 --- a/security/security.c +++ b/security/security.c @@ -1999,10 +1999,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.31.1