Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3521265pxb; Tue, 19 Apr 2022 04:37:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOee9XEhJuzWR8kmtTr0RmAqJsqRHiR3oA0A+2Z49RmEyFpLaRZbfWbyTF2USWWp/7z8Oz X-Received: by 2002:a17:90a:fe8e:b0:1cb:8129:2509 with SMTP id co14-20020a17090afe8e00b001cb81292509mr18353167pjb.12.1650368222908; Tue, 19 Apr 2022 04:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650368222; cv=none; d=google.com; s=arc-20160816; b=n9Q2hAlJLcmowhLn13qLwkQMN/n6A4L2yyPh0WaPw5PQgfaLp3YCAwMeSVwgRi2nOQ f5zLfkz4UrLV+jcvyJo0IyNMGIyg6619VnUv3g0LtZg/SQOcIv5/h7Otk1Aul5PAyYmj 8zXFx84MYtAXBwBmnh/yj8XdGsEl8Yj7fv8HWt5EUqjQbepmgmRfY9RzByJPyLDfSygY 2DTleVgomHaBjar3HIwckgtbbHIhBLiy+pZEKhBpGo2577t38ctxJRZorQlMwRblgNon 2hnadFYSOVFR0OnrC8h167Dk7tmvFQHJjliwTapfqK4pzUfGJQuGMenFU3UwGs47XWt3 ThRQ== 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=FxMOPietULejA91xLFMdB5OOrsn00dr6TKgqrlqPo38=; b=fJjUw8Mv23Pp6wM01bAoxNwSFIHn/eJyc5dUW3ZJIj4tAQ3ZXEte1Tg9iDWiBGc/qS GwjK2d0D0Rb+UMBxZgCpINT5A2VUv7uB9qtZXTnFhAmZ15/+KTwCeCxiifsUbdqo1+Kq Q691KEYV7qzbvpoPbKpxrZLZPd2XjY94gH7sUhpFZ/MZ9Yycfp5VRT9LwY5G07y2RXis hOqGTGhvg1pNtGgEg6YD8xczOEKArmqjD5Vt0CpGyvTbuyjKc3VpwW8XkwOSrSY5vzyU mtAb5AtVPIxLkhoaRHHDL9un+nu8jMvqEJngx2c9aKd/OKpSwstlqb8dFI38rBoBs/qq Kifg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b="J/Hwp71d"; 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 e9-20020a635449000000b0039da598e9b1si11653087pgm.66.2022.04.19.04.36.48; Tue, 19 Apr 2022 04:37:02 -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="J/Hwp71d"; 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 S1345274AbiDRPlH (ORCPT + 99 others); Mon, 18 Apr 2022 11:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245431AbiDRPkc (ORCPT ); Mon, 18 Apr 2022 11:40:32 -0400 Received: from sonic317-38.consmr.mail.ne1.yahoo.com (sonic317-38.consmr.mail.ne1.yahoo.com [66.163.184.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF04610E for ; Mon, 18 Apr 2022 08:04:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650294286; bh=FxMOPietULejA91xLFMdB5OOrsn00dr6TKgqrlqPo38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=J/Hwp71dX42DIwJeGjm71xiV2GJx+EYuuZokmV1KZ/cz8b0RuhL7us9s3kfnFRY2HIRWLoayfSwXnAf9I+/pmDe0JmNsJKROJ/ux+yOPCNK3kW3MPhuqtzijMmWyY4LwzpPW0xFL9tIywlkkJBwwldixP7bWwn2W3pdsZ2WCjXr+oTV+x/ozjSWevU6m2R2gedd1j7FlZL8nzS2zl+h05eqNw1LlFXhnjfFsSqfKjNxoA1unpV7SnrmgTyEL3d3Q3xUr2UutWH2pK4a4t8TCmjySSPxDwFrrBRo7U6FTfCzgYiwVW//wsmwgJJyuzoJKDvXzTqKOw269pWUc8vPnfg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650294286; bh=9yIk+Qm6BIIHAxJFwk5rLSDGMqmmAKGk42vjiaaAjJv=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=ccOet5KytRjf5aIYZu/EKN8IniWGF2UKKuC2vPn8eZgaZP+iAkrqklZ2bH+xCA7FRGG+As+OheKJ3vdHfiPmgCCdEGyq97bHndPjY5HoaXR3+2wEo0Eiki30z0MhiVu1ojCzA0pQegnt67VnqcHp7oTQseQDDmyjnaNZqnaCxHWIROrWKEIPpqTlJP+uUhjWNg2Qk+KXvcEzJrrKhiY1nQpanBV58lEGhJ5eLrep89fUWW87PR3ZcGyzzuIqXoTPrE3YEtky8s4Q8w57gW8GKvHJee2GYOjye+SHuxeapZbmMivSI0JuURGZAgD2C6FwoBnantPXFsYkjsNsuMbBUQ== X-YMail-OSG: ORks0DwVM1nKwA4xRD1Z3FuPluCcCMu1rKKOSz3onlb.tqJrC57EqCF3rRekn91 iwhp7ylJ4bTCq2J5IvYaFf.RO83gWT8Xa0CH22Hp0I1UUnBlq.mzShqlViEmqSwYFUikBNWWr3BK NQcEwhGmS69LzUau3nsZxo6zBhGmBXgcpvk6Mg_fEm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2wC.2LKJN7FTyCMNsO Vryltb9KK0f4pG4b8O5yi2ORxE00zar3YpZAR6BiqwHA_BZrCJUgJ08RVqw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Mon, 18 Apr 2022 15:04:46 +0000 Received: by hermes--canary-production-gq1-665697845d-ftzwk (VZM Hermes SMTP Server) with ESMTPA ID e42a5033a868ecfd55a4e02ebf801990; Mon, 18 Apr 2022 15:04:45 +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 v35 10/29] LSM: Use lsmblob in security_ipc_getsecid Date: Mon, 18 Apr 2022 07:59:26 -0700 Message-Id: <20220418145945.38797-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220418145945.38797-1-casey@schaufler-ca.com> References: <20220418145945.38797-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=unavailable 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 6ce44b9ae464..4cfeb5eb29fc 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 10b9dc253555..d125dba69a76 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2662,12 +2662,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 6e6e44213d80..131c851dd681 100644 --- a/security/security.c +++ b/security/security.c @@ -2012,10 +2012,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