Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp871408iol; Thu, 9 Jun 2022 16:19:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwutYHafHxfOz1hU7643FPHdi0nCRGu2frokNXn7wowh5jw+kCSg8Enjb8IEI1UqghhGFiu X-Received: by 2002:a17:90b:314a:b0:1e8:5362:5620 with SMTP id ip10-20020a17090b314a00b001e853625620mr5727125pjb.9.1654816792562; Thu, 09 Jun 2022 16:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654816792; cv=none; d=google.com; s=arc-20160816; b=RTJBu0SpKVQ5zjgVczHW1rNsbPaeygJS91iUYLCtAf9W/Wta3TYIgufWfie72aWPHd yfPlY/WWEhGvxYUrwuZA8zdyD3bm8y5bYAUCBKaK0ALNmFdUMk4m9hoaQjfa9/Sev2qN rqak33KhQeFPJkyKeRvakg6zlTCgGdDgTPe3f64vHIxvCMhz6XswCbrSgJVZs9e09k/F 6BC9sfBwT9TjRze9YqFAbp3k43UKwngJiOAaVnlPWUrn5SmiYdxIOnBayncGPp0FVtnC Qj5v69fUFTKDgapsFIonkc80ix3owetLU7DoJUgo39FmaSxRIhNRcb4hWec6gMsR9M8u KAew== 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=nRFZTXyIqrr+BZnegUOXOgpXbav22Zr0lj00nScKgr8=; b=pDZGRNhJMP/mvViKWg5z9VxRmeA8EmXsK+n6vPsxGHdw+lOHGN1bLXa/lvKchYSHVm W/GWUvUX5442zoaQJn5E99UkgnpDIG9GM1WBMLFgXvjTA7U0pekQsxyGE0cYm8HenBAQ Bpw0d0SXvRk60vEDmluUQQe/CVAgu7b8Q/LvnNCVipU3nGn8IPDqNpM0L6YC3pv2tYVo cwWSeFBlPnlxLFWPYjozEHzDpPqSJ5ZYDVz2Y6gCuVeyvETEc5uLWqccLlRLs8VVd+df 0TUPxPL8MWbsagPzgrYLmsLgs+IfXfVup3Lh/dnjbAn3bj/ye0Hsj2eOBmWKTbrvA1nM Js8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=VnI12e4B; 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 ik30-20020a170902ab1e00b0015f371008edsi32005617plb.396.2022.06.09.16.19.40; Thu, 09 Jun 2022 16:19:52 -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=VnI12e4B; 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 S1346023AbiFIXQw (ORCPT + 99 others); Thu, 9 Jun 2022 19:16:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346019AbiFIXQp (ORCPT ); Thu, 9 Jun 2022 19:16:45 -0400 Received: from sonic308-16.consmr.mail.ne1.yahoo.com (sonic308-16.consmr.mail.ne1.yahoo.com [66.163.187.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1569F3C2DF7 for ; Thu, 9 Jun 2022 16:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1654816596; bh=nRFZTXyIqrr+BZnegUOXOgpXbav22Zr0lj00nScKgr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=VnI12e4BZsscREeXkc/BP3/GbELZh5T83hnOe0CBkwzV7D8hONHmPobwkHp4eGFTMj02/GciSKHFj/fKcoUDLG2ULu1pwts6rRC3NnWzy2iCWh6Y+QFNUR7oBr4+4FWzXJJ73+X9+okS4G5sJE1MwoaWL2kGNIXJZOJcOccvqVc1VeBj084W1DIU3/ReeV0fz/qvu5f1/C1N5veuOs+d/7nI1l1qrQq77FY1D6Bos5TI2VqZeuIjQvKp/4MJZO8dysMm8Sd9MUdn0spyWMRhlmVbwqJ82ChmZqJG6sJDGdUE5u6BqYzmLyeFTUL3BoGyeEiBlfyGFPtAzJgvjPU9jg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1654816596; bh=bXkyKIYf71OGeeF0ApxVhWpxXuQDIe0iFUVxhD0kb5U=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=FZu3XATlYj1+4lYfWGkqcAQRdfKgr6DmW+z8UrAmDyHSsmanFAjBts9EK9QzmDg35UQ3lWw6jdVQ54SnUSwmFD9w/PATCsWSN7bMzC0qHuwvVQL6zl4YcI57CEsIcXGkSBUoGTDWOYi2sKMYSMar6NBkPQc8Y06uAICKXh4opOfcah0daXQRAbBSHYv8AVUR9avgjkIh4Cx+NRYdbUg0geTLbBFxA6WDEMww78U/TkcFCtC6ZLiVp4HWP8wAYPt1eMkABIUtXB8/C9Q1boWEj6XndaK81+i/grWWipB2b1Ho5T4a3zS3YF3FHJ7fOf4nDzQ50l20qimPQjK3YN5igA== X-YMail-OSG: fUCF0FMVM1kzVm05geLlRy23AO2xpK1nnPParE0vvpawcAoHkbzr4Ahzimv7Wxx QEZi_sipHIri9m6EfEa.gsX0NscRrFuORPHXiUeTgOZZbUOR5jr7pBpsnykmCLQ900fuboDwDOQg PEMklR7moOifxwBpPTI5CEugqPY5VaMNZqFulhgiDzvtIYVyRs7M1YAejBp1l1bxwq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mail.ne1.yahoo.com by sonic308.consmr.mail.ne1.yahoo.com with HTTP; Thu, 9 Jun 2022 23:16:36 +0000 Received: by hermes--canary-production-ne1-799d7bd497-7lvgk (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 2d9a335cac260a86aa8227596f2c755a; Thu, 09 Jun 2022 23:16:31 +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 v36 28/33] audit: multiple subject lsm values for netlabel Date: Thu, 9 Jun 2022 16:01:41 -0700 Message-Id: <20220609230146.319210-29-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220609230146.319210-1-casey@schaufler-ca.com> References: <20220609230146.319210-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=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 Refactor audit_log_task_context(), creating a new audit_log_subject_context(). This is used in netlabel auditing to provide multiple subject security contexts as necessary. Signed-off-by: Casey Schaufler --- include/linux/audit.h | 7 +++++++ kernel/audit.c | 26 ++++++++++++++++---------- net/netlabel/netlabel_user.c | 7 +------ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/linux/audit.h b/include/linux/audit.h index a7226989d77e..de661c571401 100644 --- a/include/linux/audit.h +++ b/include/linux/audit.h @@ -190,6 +190,8 @@ extern void audit_log_path_denied(int type, const char *operation); extern void audit_log_lost(const char *message); +extern int audit_log_subject_context(struct audit_buffer *ab, + struct lsmblob *blob); extern int audit_log_task_context(struct audit_buffer *ab); extern void audit_log_task_info(struct audit_buffer *ab); @@ -250,6 +252,11 @@ static inline void audit_log_key(struct audit_buffer *ab, char *key) { } static inline void audit_log_path_denied(int type, const char *operation) { } +static inline int audit_log_subject_context(struct audit_buffer *ab, + struct lsmblob *blob) +{ + return 0; +} static inline int audit_log_task_context(struct audit_buffer *ab) { return 0; diff --git a/kernel/audit.c b/kernel/audit.c index 2333d7f59285..4ec86d696753 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2226,20 +2226,17 @@ static void audit_buffer_aux_end(struct audit_buffer *ab) ab->skb = skb_peek(&ab->skb_list); } -int audit_log_task_context(struct audit_buffer *ab) +int audit_log_subject_context(struct audit_buffer *ab, struct lsmblob *blob) { int i; int error; - struct lsmblob blob; struct lsmcontext context; - security_current_getsecid_subj(&blob); - if (!lsmblob_is_set(&blob)) + if (!lsmblob_is_set(blob)) return 0; if (!lsm_multiple_contexts()) { - error = security_secid_to_secctx(&blob, &context, - LSMBLOB_FIRST); + error = security_secid_to_secctx(blob, &context, LSMBLOB_FIRST); if (error) { if (error != -EINVAL) goto error_path; @@ -2254,15 +2251,15 @@ int audit_log_task_context(struct audit_buffer *ab) if (error) goto error_path; for (i = 0; i < LSMBLOB_ENTRIES; i++) { - if (blob.secid[i] == 0) + if (blob->secid[i] == 0) continue; - error = security_secid_to_secctx(&blob, &context, i); + error = security_secid_to_secctx(blob, &context, i); if (error) { audit_log_format(ab, "%ssubj_%s=?", i ? " " : "", lsm_slot_to_name(i)); if (error != -EINVAL) - audit_panic("error in audit_log_task_context"); + audit_panic("error in audit_log_subject_context"); } else { audit_log_format(ab, "%ssubj_%s=%s", i ? " " : "", @@ -2277,9 +2274,18 @@ int audit_log_task_context(struct audit_buffer *ab) return 0; error_path: - audit_panic("error in audit_log_task_context"); + audit_panic("error in audit_log_subject_context"); return error; } +EXPORT_SYMBOL(audit_log_subject_context); + +int audit_log_task_context(struct audit_buffer *ab) +{ + struct lsmblob blob; + + security_current_getsecid_subj(&blob); + return audit_log_subject_context(ab, &blob); +} EXPORT_SYMBOL(audit_log_task_context); void audit_log_d_path_exe(struct audit_buffer *ab, diff --git a/net/netlabel/netlabel_user.c b/net/netlabel/netlabel_user.c index 1941877fd16f..42812bdfc31a 100644 --- a/net/netlabel/netlabel_user.c +++ b/net/netlabel/netlabel_user.c @@ -84,7 +84,6 @@ struct audit_buffer *netlbl_audit_start_common(int type, struct netlbl_audit *audit_info) { struct audit_buffer *audit_buf; - struct lsmcontext context; struct lsmblob blob; if (audit_enabled == AUDIT_OFF) @@ -99,11 +98,7 @@ struct audit_buffer *netlbl_audit_start_common(int type, audit_info->sessionid); lsmblob_init(&blob, audit_info->secid); - if (audit_info->secid != 0 && - security_secid_to_secctx(&blob, &context, LSMBLOB_FIRST) == 0) { - audit_log_format(audit_buf, " subj=%s", context.context); - security_release_secctx(&context); - } + audit_log_subject_context(audit_buf, &blob); return audit_buf; } -- 2.35.1