From patchwork Mon Dec 13 23:40:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12674963 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D062C433F5 for ; Mon, 13 Dec 2021 23:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244284AbhLMXvr (ORCPT ); Mon, 13 Dec 2021 18:51:47 -0500 Received: from sonic301-38.consmr.mail.ne1.yahoo.com ([66.163.184.207]:36098 "EHLO sonic301-38.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244133AbhLMXvq (ORCPT ); Mon, 13 Dec 2021 18:51:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1639439505; bh=uLkiUf0AkXJu5UKLkfjJMYGyH/G9ehNWKG8YUmHWv1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=qfu0i4e6AhKu1FxDvHXhIFOUeHlZs/zYbk77pmmd7H7U+oswgChDVp7dlthf+RJLnGDtKHDGZERqebMXQzbvI4sdHX4V20Re8cbMojrw8LX19TWG8YAXX7WczyxM8BGgyqqD0yQRLngIBMokJuE+m7lJwE+hokxtxPtxB/Jsm1OtVGrFiS+TuPK00XO3BqpMHTcXjlbemshrvq62BaTHVQQ4at/UkahdFATGwt9sC5A7nmDJ3iM/Mpyb1K7Wqe98rvqSauPQDC4KJPRSjaWjaed1hl73EHg/7aFL5mx4Qs4IyoKW9LUd2mX6zyFGraSvck23qhQUy+hBeEGD2TIhiQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256;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imd3rkWtZIUXKeyoetnV2xplaVPRw4E4KbTWwnDg.uNzSO1T13p7WhRpiHqjUef6TbSGyM .1S6kXhKRLyqcqXxcjqViQID1D_zPhFhmgcISpch07NHEJO0eFVHAzk4tzR3tVRjv9h0ve7ZMrXU ibIvfr8UGnb_dKDMvgPUhnaNwpNbu4lyHVEb4wAe1q3modqDad_KqZsx.EEjGsaI.g_JWRC04nKG 9d9A_uMhzdqjEvA2S9asZNFqE54FsPcRQs8FMu3aHZv17bSbt8ZAGtEoEEyKa3dt4D0n2Wv9UkRa aA5nhAuv492mlNyT3B6DZbshzDOVia0WjfWViSpUa3Bq51Zh1U4bQu.3HoYkv3MPAGaRizowVcOS lPBtUd1jcGj88zDmxYPa8GgZ9qRyqAaHZaTaaNW8Gwcp69Sij5SXa9b8HxkTxkZhJKl2jYb7GSOX lTPGmCrixQcYDEJMesArGY3kGEm_oIk.Md6yQCxLejBc2kaOaMfAJ9usnBwxnbZnVA22wAUZr7x9 VRLqwKToeu0w7vbl4mnvbNvFKfIAAsZc2RLn7gIzRIlnS329UNQD6dXJelkXTtrSGKfNhpv7tteR REuFnyxxmnl_6kwxU35e0EZa90wzwmE7sx5nX.DEefjQ3_rybNuxaRkEHrFiCIFELef35c4NvI5h GhVz.XPcV9s1fHnp57GJw X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Mon, 13 Dec 2021 23:51:45 +0000 Received: by kubenode548.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID d4d0e09ffbe12f593b23adee924909bd; Mon, 13 Dec 2021 23:51:44 +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, Stephen Smalley Subject: [PATCH v31 10/28] LSM: Use lsmblob in security_ipc_getsecid Date: Mon, 13 Dec 2021 15:40:16 -0800 Message-Id: <20211213234034.111891-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211213234034.111891-1-casey@schaufler-ca.com> References: <20211213234034.111891-1-casey@schaufler-ca.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: selinux@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 669eff47737a..a0b9bf48a60d 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -521,7 +521,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); @@ -1284,9 +1284,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 b28e2cbcc92c..c469368818fd 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2601,12 +2601,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 a0612afefc24..f8b5e2fa37a0 100644 --- a/security/security.c +++ b/security/security.c @@ -1996,10 +1996,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)