Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1513258rwb; Tue, 27 Sep 2022 14:24:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7j2gy4M1DZ9dEqEjGtxsX5NddGuHjeGrlmwOmF9t224YYAYgz3Un2QyUihN4cMpXeVxJed X-Received: by 2002:a17:902:6b8b:b0:178:7cf5:ad62 with SMTP id p11-20020a1709026b8b00b001787cf5ad62mr28515843plk.13.1664313857875; Tue, 27 Sep 2022 14:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664313857; cv=none; d=google.com; s=arc-20160816; b=hwhUyNR4zbifDXEXDjxmTKGtpeD5Iv+b4u9A4xWdtZMs80s0775alEDm4oBhTVuL6/ 5zH96nEEW6PDD1iFT9VE+5ygqy6lHhqDiXJ2Tu3Pz7z36ePYg+qY1P9FE1A1U/kYJfNP 7aAE1m3Pz77ZpLMTjbFk6Otolx0yOLpK9PEXm8jDYdIYwnmE2bjgkSTxPFkL67zh3h2z WMnP2B0/+FVVCFR9y1SzPIsnDH4Y9jq8pvoXk85RAstEu53e3Kyh57VJqvVDaZxsC8vl A1EiyMEgnBJJFsRn+T1IAaisw/7+aG0JZ7G1n6GPYi1NU8fhojFvZRIx79HZWSWREEb4 HWOQ== 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=T0E+UFRQrcA1QKsW6qs9h7Wvvr9EMKuLo4zA/XijVtA=; b=S+vNBHFC8mr3qD6G7Er5S9P9yd/efHCcbt85Ieud8INV0bky/0WQTpqNDIuzKp26XY M3pFaKmquUNEdIz8cVrJCtDlCmNy8cnOxRMaAfiuuvPKFZUhe5y/pRO1MVuCaki/5EZ7 c+wwEZFIs1n1QbCHoUXQ3e+z1YBvhvb5k7AC8VJe3+C955NX1orwctLQy6ax8G0xgHCl ekt+DVTLgvSoqPBlJJ4wmUjNrOZaRMFTk07XEDKXFj6GX2/tJou/7tuM5JJEObBS831x 6zEhPZuz6KZbJI9rJLlLEVLfhM9iSQX80L458Fub/i95pzrfGfFLBZQxcYDghSIIrCMm s+Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=dONweSBt; 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 k31-20020a63ff1f000000b004392a933465si2967774pgi.315.2022.09.27.14.24.07; Tue, 27 Sep 2022 14:24:17 -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=dONweSBt; 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 S232851AbiI0UOE (ORCPT + 99 others); Tue, 27 Sep 2022 16:14:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233017AbiI0UNR (ORCPT ); Tue, 27 Sep 2022 16:13:17 -0400 Received: from sonic302-28.consmr.mail.ne1.yahoo.com (sonic302-28.consmr.mail.ne1.yahoo.com [66.163.186.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BD051EAD68 for ; Tue, 27 Sep 2022 13:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1664309547; bh=T0E+UFRQrcA1QKsW6qs9h7Wvvr9EMKuLo4zA/XijVtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=dONweSBtuFbiuP4aHpROblUDLdhWIq4qqpPM3u3kMdERCFFq9tvW9u65Clw0IkLuYClZx8/FB++15aq6spuLqEpHdtbjrT0jBkPkIYkgYrmh7vGo1kSadnlbYWN4rChSTzdrwHSgXN1fNOCYl7W/StkpDn0cK0CZa/WdreL3O+acjVf5H+ZQ0X5mCO5VB4UgAT2vYs02tpBUpNQa88VZKf9ulFLdjVvNXumCsRHqCg0qnIrcPC2nnWdqVKGRTpB4Ejryh3KZyOpgb+K6hPYqQmzy0Be6gNvBxSIDFE3frOh+M9YWDGMUl/kzA4oG+f/l2P/VUYHMrFDm2MtsTeedgg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1664309547; bh=GIQpcfsF3JbEQ9m2yt59Bvv8zj7/OX/JdjxEAfeQUZV=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=c5qBcqoIN108V5RO1EkD2vv2hZjNTvYSd+fALM1wZw1EFiwQhKrr/meIRv0kaBWT0rGZgpoq0p/H5vZimcQC46uwyBvBPoROnXaZC97os2J78jkNQRIGmMY/CDTxaxQTStiyK966BIQU3F+efoyHuc/zvqWVekUiz2WqJA4w+YPkDoU2pBrPIhvim521W9Bx8GpIIHt6NM1HnQb4ysA56j4xsWFMSwPxevtjxZVOE3vrPrgTteteC8CY+X1BFadEYoH0a/MQxBo+MD8+GKZPYKzz7D5BOHUbyX0yOrTNMoa/SiWtUuq9AmEVOa+SMXNXsQ1j/h58HuUe9U9vorc5IQ== X-YMail-OSG: D1kw7foVM1lONcrQdrjrhsLeXMpBgiu5KoFcpHyOcTEZhM2__uzGDDisDu5at47 LXB5bsR33WsRz46k.FIKdZo6.vwm6UVqe3A5pB6zCRBf8mnpIhrM3wMKjidf9uY4ppr2zU3t4DcK R.kq1znBhsp.JZuWkVUDiwyqhSNmoFSeNpr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kRp1B2jUSqYsbJNR376LTY3_Mv a72VLKapO2X5hOIbEK4uFUwetFviqroUNcQF0 X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Tue, 27 Sep 2022 20:12:27 +0000 Received: by hermes--production-gq1-7dfd88c84d-nfz27 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 1d976fe2ee917226e6d7cc50e923ce4f; Tue, 27 Sep 2022 20:12:23 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: casey@schaufler-ca.com, linux-audit@redhat.com, jmorris@namei.org, selinux@vger.kernel.org, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v38 33/39] Audit: Add record for multiple task security contexts Date: Tue, 27 Sep 2022 12:54:15 -0700 Message-Id: <20220927195421.14713-34-casey@schaufler-ca.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220927195421.14713-1-casey@schaufler-ca.com> References: <20220927195421.14713-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 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 Create a new audit record AUDIT_MAC_TASK_CONTEXTS. An example of the MAC_TASK_CONTEXTS (1420) record is: type=MAC_TASK_CONTEXTS[1420] msg=audit(1600880931.832:113) subj_apparmor=unconfined subj_smack=_ When an audit event includes a AUDIT_MAC_TASK_CONTEXTS record the "subj=" field in other records in the event will be "subj=?". An AUDIT_MAC_TASK_CONTEXTS record is supplied when the system has multiple security modules that may make access decisions based on a subject security context. Acked-by: Paul Moore Signed-off-by: Casey Schaufler --- include/uapi/linux/audit.h | 1 + kernel/audit.c | 42 +++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index 7c1dc818b1d5..7a5966b46f38 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -143,6 +143,7 @@ #define AUDIT_MAC_UNLBL_STCDEL 1417 /* NetLabel: del a static label */ #define AUDIT_MAC_CALIPSO_ADD 1418 /* NetLabel: add CALIPSO DOI entry */ #define AUDIT_MAC_CALIPSO_DEL 1419 /* NetLabel: del CALIPSO DOI entry */ +#define AUDIT_MAC_TASK_CONTEXTS 1420 /* Multiple LSM task contexts */ #define AUDIT_FIRST_KERN_ANOM_MSG 1700 #define AUDIT_LAST_KERN_ANOM_MSG 1799 diff --git a/kernel/audit.c b/kernel/audit.c index ef6b2d38e38d..fb182f7e9d18 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -2228,6 +2228,7 @@ static void audit_buffer_aux_end(struct audit_buffer *ab) int audit_log_task_context(struct audit_buffer *ab) { + int i; int error; struct lsmblob blob; struct lsmcontext context; @@ -2236,16 +2237,43 @@ int audit_log_task_context(struct audit_buffer *ab) if (!lsmblob_is_set(&blob)) return 0; - error = security_secid_to_secctx(&blob, &context, LSMBLOB_FIRST); - - if (error) { - if (error != -EINVAL) + if (!lsm_multiple_contexts()) { + error = security_secid_to_secctx(&blob, &context, + LSMBLOB_FIRST); + if (error) { + if (error != -EINVAL) + goto error_path; + return 0; + } + audit_log_format(ab, " subj=%s", context.context); + security_release_secctx(&context); + } else { + /* Multiple LSMs provide contexts. Include an aux record. */ + audit_log_format(ab, " subj=?"); + error = audit_buffer_aux_new(ab, AUDIT_MAC_TASK_CONTEXTS); + if (error) goto error_path; - return 0; + for (i = 0; i < LSMBLOB_ENTRIES; i++) { + if (blob.secid[i] == 0) + continue; + 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"); + } else { + audit_log_format(ab, "%ssubj_%s=%s", + i ? " " : "", + lsm_slot_to_name(i), + context.context); + security_release_secctx(&context); + } + } + audit_buffer_aux_end(ab); } - audit_log_format(ab, " subj=%s", context.context); - security_release_secctx(&context); return 0; error_path: -- 2.37.3