Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp988088pxb; Fri, 15 Apr 2022 17:31:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtF8X2eAndso/P4bFdN5rRkxLq5KQE/y1A4x72VfbhJNJDsSW0ZV+8faLMmpMFPQ+l19De X-Received: by 2002:a17:902:e743:b0:158:a11f:6d20 with SMTP id p3-20020a170902e74300b00158a11f6d20mr1227203plf.140.1650069114765; Fri, 15 Apr 2022 17:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650069114; cv=none; d=google.com; s=arc-20160816; b=v8SqeY/ecmBzGJa91PXy0+GyjbvXwALZdJh7UtydxOpNtBZw7+aRG9018jDWRnR+FV cZB+GVhg5xHP0ighvp8Ag6wt8HW7aJ7XeZRAN/GtoknvAsPyLQTr9kbUUJrNpsPRoOg6 rwDY+YeYwvefuRPWfMZOnkc7EONalyaiu6O4Pr6VTfplYM95m1VGObA28LCLRsK/jJfb +p9hCL3j6JToV+ErICb7ZFLKez5EDH2VvRZvqBkODYYauVCCdvOIFglzIez9i/veeWpW fs6c4/r/hOWrim1/41Qfzty6QnN0lb1DLOZgOLCnnwA/jLHyzJ+kZdCVKuW2oA+r5jVY W5aw== 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=BtHo1QSoNl0+JSUijRm0h7RCZJK8XQ8GDtQ9CbzS1Bo=; b=vyZnMXYJxZ+m9ihIX7TSyq8DUi4PAmyMaIyi71nbM0U0xROzG7rYpnQRy/Sw8sonSg XZlCfgHrUmYDoOaJGlSZJS71lhv1xR2oM1yIA1MCOPtj6qPNf1v9b5AGJ2nUTwsqyP5D ZU8HkbHSwLjuta07NDMhiB8W6tWipsMlUILHdSMoQlVL764Hv2DGv3BkuhGOqaK5+O4R r9S1ia0eEA14AV/dh0ndVpv7kf3GO7NnqsP6EXfr3TCompRi9stF7X+9T1AuWwQi/J8I TETZ6NqDJY4y5TQdVeUTdQlMxQ/HtPILV/00kThS02q8I4BqX1LvLgQY5hHZPvK0QLV0 VaKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=Sr+OvD4o; 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 u16-20020a63df10000000b003816043ef0dsi2781934pgg.258.2022.04.15.17.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:31:54 -0700 (PDT) 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=Sr+OvD4o; 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 B34F3EF082; Fri, 15 Apr 2022 17:28:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354825AbiDOV1U (ORCPT + 99 others); Fri, 15 Apr 2022 17:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353902AbiDOV1G (ORCPT ); Fri, 15 Apr 2022 17:27:06 -0400 Received: from sonic305-28.consmr.mail.ne1.yahoo.com (sonic305-28.consmr.mail.ne1.yahoo.com [66.163.185.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDA68DFDDF for ; Fri, 15 Apr 2022 14:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650057794; bh=BtHo1QSoNl0+JSUijRm0h7RCZJK8XQ8GDtQ9CbzS1Bo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Sr+OvD4oxptIE5XVv2dS9J1hmkRl6mszXO4tHK5HsPLSNjVUN6SBc63Nx7CPL11eiaVKv1o3jwfd9iMCPVS6SqFCTVBdDop/PX3sm+r5HFCVkkwFpeIgTjJQerJ09i9b50zpLnwtfx1Nh0wKPBux+jL14q2MOkEtfQcbsN8XA7SI+4d+Q04pRb7Dbnk5FCxLxqrPSz6d7MnMzCYdP+U2L0CozAxffsf83Xm7KhHoXKsLu25MPJwf9Kc+pObS6FKzSfqKJE1Ojy1C0kBpsL0QTEmNUsJYCn6gbPeTljcbr8B9N+zUYMGpcyeoDbmaTRlPrg+suqGDzQey9Q5tL+KqhA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650057794; bh=zGUVlSW2BazDaoRCe5/ddaJe6wt10DJvcCkeAC8qviP=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=j579KO0H8ZJjh0gK3C9zEYlm/IRarOTjXvrddqz1Geq1h+QUcvAIxv9g9/Nm+PNqRTCUF+A7DMYcB6+pkL99ST9ab9WtcgFpWYAIG3xsBetw5IxpFSt/JXcOTIeTBcnPaIANEvZcNT/1x1PIDYkqHF8QT8/o0gzid7zOwHozJ88nUmbYsxODaAvOfPf2EqLJ2IOgSb5VK1u1pbKocWAAFmVS1/enVaeZ8WIywbsHzMVxDxGVLQKPImZWL1DjBuEypshfR/Ea4nddNmjx5b0iJ3NdYzMWRKDWWAntNmRfaJUXTLjTN063XZPZosFYHsqHGT6/stkczhTHogHUErqIoQ== X-YMail-OSG: ES2H3FwVM1l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.ULOXBX32rBhNF_ydKnJERSbXC llvU4uKJPBWowl2_mkYRLJ66e6Mi1T48n8EPEmb7tJh4jyCILBWjekKq8n6Pcrdh7nGEO8pmtKBJ TmeBWeh0l5_wq2Fp8NIfUEQf9Uw7F52ZWyI9qroL.eyJFek9XLqZV_esZH4DE3ljZVLpmSK2PMz2 3N94hAF5JksLUYfjtOB8u5kzvaCWi5bFTbsDnhzsO.OTnJHCxNRuu1FEa X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic305.consmr.mail.ne1.yahoo.com with HTTP; Fri, 15 Apr 2022 21:23:14 +0000 Received: by hermes--canary-production-ne1-c7c4f6977-9gvrn (VZM Hermes SMTP Server) with ESMTPA ID 0aa251bda2fc204a3bc01b852774ce09; Fri, 15 Apr 2022 21:23:09 +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 v34 10/29] LSM: Use lsmblob in security_ipc_getsecid Date: Fri, 15 Apr 2022 14:17:42 -0700 Message-Id: <20220415211801.12667-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220415211801.12667-1-casey@schaufler-ca.com> References: <20220415211801.12667-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 4f940ef06e51..4646ca90f457 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