Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp961818pxp; Wed, 16 Mar 2022 22:44:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpeoIZ4dywK/WVl3hAuVlC8f2lczPQnFo550DNn9GDi58FF+sfjO4fFssekH+U9cxQbYZT X-Received: by 2002:a63:5145:0:b0:381:4051:1f5a with SMTP id r5-20020a635145000000b0038140511f5amr2449860pgl.300.1647495896377; Wed, 16 Mar 2022 22:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647495896; cv=none; d=google.com; s=arc-20160816; b=LNKsNpmRp1+6WzpYkVM2rt+VNdXTrqnWqs9TZoYNiOzT93vwT2Chn8U9mkWkOkeizZ RnzdnxM4ONARG9aTz76zbnw6rr7SENhvMo0l5jGJpocENhgyNBa4qZq+kd5NgWD8hs0h SeS4gMmKgsH0weGfq3yui61SOQvNdxoOtxNjwQqRrfErinBiAwhxFqDiurBlPCYoc8lJ nmSxvv9/ffk72KeqiZ2aEE9UnohX3LyCGTi8QN/CM+Oj8AT4VQoCwtokG7aB5xHmXjVf jc00QnksoJHCMXfR9O4kOy4OK4v0hyku777BLhVTxPsTUJCgIgGd+yW6HG+HxkOP5lpf StQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=pKH+3mIFp+umBQDsSMTqPOceUhO1uzZlZ864UKbjcnE=; b=Fdvji37zG24D0+SIEGa2TR8RyzGgytqeyebI0TzoTY1iEIf01tqKYmNKJozIC0BCHz yVQDALNNCDciIAJ01y3Ozb54vUt/0wQFmRIbV7GEJ1EjHVdPkWCyHnIPEl4sOzqeL6nD ZLyIIly9tSXhmhXze5WRIXXoE18T3mEiHffGlKiqhW79ErC2zFf5w4i8MNXbObZxWN9W 1ZWWhBpOFrk88KHMYFbGmnuHg4qnTj0ykuOuCvF5KVhvGO0/UopcNCu71nKyxFCv/yvg h9vDY2DbHfE5vy46WZTdg95vE2i8pA8BIYfKECiRPDAOI2BIA/C9j0znF7V9UHQByBcb 81Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=gAbPkWH4; 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 p3-20020a63fe03000000b003816043ef2dsi1165067pgh.290.2022.03.16.22.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:44:56 -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=gAbPkWH4; 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 4F973118F5F; Wed, 16 Mar 2022 21:39:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352766AbiCPAS2 (ORCPT + 99 others); Tue, 15 Mar 2022 20:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352762AbiCPAS0 (ORCPT ); Tue, 15 Mar 2022 20:18:26 -0400 Received: from sonic306-28.consmr.mail.ne1.yahoo.com (sonic306-28.consmr.mail.ne1.yahoo.com [66.163.189.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E2EA4DF6A for ; Tue, 15 Mar 2022 17:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1647389832; bh=pKH+3mIFp+umBQDsSMTqPOceUhO1uzZlZ864UKbjcnE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=gAbPkWH4JeZRi+ZaLSRDbF6UoAKUkySKoDtmjUz1wetWqcGGQ3wBSiAdb2uXFhrJQVVru/2cmw2BZrsTrw6AupZ5ieZOeOhpzo/FUJc7T5BBk5IUYebKzFli7cWcgJTZ/ExwgYdBLpXfEFmdsryJmxtJU7Ne6nTcaOuQyscKptWuekZpRaQX0BmNmCDy3wYDSht/lMNNKfBz1dRLYzHC6SwGI9m9HVHq8K2XkrdDskzsBj8aAaxg/Y1y2HxTf8MLtM05Yzj2B8UbGBcj6fGglXX3omYMOvK3cNvWxo+itjwfydY9WR4CNOlSHq4y/rF6K25wcMPWdq1GkJwlmgW0dw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1647389832; bh=zpLnl9ycIt2/i1RvAe0diDhXGKeFZz299sE4EMVtMtG=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=sekgNdroAlcCXKYp5lakkTK8hijD6SrV9XbtV2wMemPb7WYXb9fn8iLRnV9aF3OcjH8eVbMivKoXvJSQn1LIjLbr6XG8S3s0PPMb0f0lcdhmawhDJGN/yIMAfVdJw47Gki0Em4Uw63GPVy6GJSaRM5Oqhyy5s/Is1TNBG0Cx4UzAhszm4wnFGm6p2HdeQ5Em9vLGZf20DMxWPiqr2gMLULE0AQaIbHxhLJe7nnCoVXbvWVC+yFnVIof6jPvU4VbIoQ7ahW430SvImFvd6m5dAOvkFxT2U/uFf16Z/mRb4oe346FMckCT3cLwPaz9MXcGCamaRu36G7Z+11limHiepw== X-YMail-OSG: VOCQbaQVM1mfpvP80ZeI5KR55K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ImbSDVVJGPOgOVX8nxjWWvj0hRTtJeTL c4QJCX5jTLGY51suWkp1KLI7aR.P8_YT82Jqu1usiS.QRBclws_D8iMz.YzwsE89YojKzoI0iPFh 2aK0wOnI8sXafwnYOEge15umesWVgVHh5jhlDglkd7r5amgysdfzM7wEi2y4wmbCuTiTGHeNXw.R WI5pEDw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Wed, 16 Mar 2022 00:17:12 +0000 Received: by hermes--canary-production-bf1-766d6d57f5-z4vf2 (VZM Hermes SMTP Server) with ESMTPA ID 05dfc940f855908b22d83beeb4c6787f; Wed, 16 Mar 2022 00:17:08 +0000 (UTC) Message-ID: <8be54cd7-61e1-5534-5f27-e3c24c6ad8fa@schaufler-ca.com> Date: Tue, 15 Mar 2022 17:17:06 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v33 26/29] Audit: Add record for multiple task security contexts Content-Language: en-US To: Paul Moore Cc: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, Casey Schaufler References: <20220310234632.16194-1-casey@schaufler-ca.com> <20220310234632.16194-27-casey@schaufler-ca.com> From: Casey Schaufler In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.19878 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,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 On 3/15/2022 4:47 PM, Paul Moore wrote: > On Thu, Mar 10, 2022 at 6:59 PM Casey Schaufler wrote: >> 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. >> >> Functions are created to manage the skb list in the audit_buffer. >> >> Signed-off-by: Casey Schaufler >> --- >> include/uapi/linux/audit.h | 1 + >> kernel/audit.c | 104 ++++++++++++++++++++++++++++++++----- >> 2 files changed, 93 insertions(+), 12 deletions(-) >> >> diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h >> index 8eda133ca4c1..af0aaccfaf57 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 4713e66a12af..ad825af203cf 100644 >> --- a/kernel/audit.c >> +++ b/kernel/audit.c >> @@ -2147,8 +2147,65 @@ void audit_log_key(struct audit_buffer *ab, char *key) >> audit_log_format(ab, "(null)"); >> } >> >> +/* >> + * A brief note on aux record management. >> + * >> + * Aux records are allocated and added to the skb list of >> + * the "main" record. The ab->skb is reset to point to the >> + * aux record on its creation. When the aux record in complete > ^^ > "is" >> + * ab->skb has to be reset to point to the "main" record. >> + * This allows the audit_log_ functions to be ignorant of >> + * which kind of record it is logging to. It also avoids adding >> + * special data for aux records. >> + */ > It might be good to move the above comment into the > audit_buffer_aux_new() comment header (below) so it does not get > misplaced. > >> +/** >> + * audit_buffer_aux_new - Add an aux record buffer to the skb list >> + * @ab: audit_buffer >> + * @type: message type >> + * >> + * On success ab->skb will point to the new aux record. >> + * Returns 0 on success, -ENOMEM should allocation fail. >> + */ >> +static int audit_buffer_aux_new(struct audit_buffer *ab, int type) > ... > >> @@ -2157,16 +2214,44 @@ 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 (!lsm_multiple_contexts()) { >> + error = security_secid_to_secctx(&blob, &context, >> + LSMBLOB_FIRST); >> + if (error) { >> + if (error != -EINVAL) >> + goto error_path; >> + return 0; >> + } >> >> - if (error) { >> - if (error != -EINVAL) >> + 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) { >> + if (error != -EINVAL) >> + audit_panic("error in audit_log_task_context"); >> + audit_log_format(ab, "%ssubj_%s=?", >> + i ? " " : "", >> + lsm_slot_to_name(i)); > I wonder if it might be better to record the "subj_smack=?" field > before checking @error and potentially calling audit_panic(). In > practice it likely shouldn't matter, I feel better if we at least > record the subject information before we call the wildcard that is > audit_panic(). Not a problem. Easy enough to fix. > >> + } 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: >> @@ -2382,13 +2467,8 @@ int audit_signal_info(int sig, struct task_struct *t) >> } >> >> /** >> - * __audit_log_end - end one audit record >> + * __audit_log_end - send one audit record > If we want to be very nit-picky here, "end" is more correct than > "send". First, audit_log_end() doesn't actually send the record, it > just queues the record for the kauditd_thread which then attempts to > send it. Second, there is no guarantee that the record will actually > be sent at this point, although it would be nice if that were true :) My bad. I thought I had deleted the 's', so I fixed it. >> * @skb: the buffer to send >> - * >> - * We can not do a netlink send inside an irq context because it blocks (last >> - * arg, flags, is not set to MSG_DONTWAIT), so the audit buffer is placed on a >> - * queue and a kthread is scheduled to remove them from the queue outside the >> - * irq context. May be called in any context. >> */ > This should probably be moved to patch 25/29 as it has more to do with > the __audit_log_end() introduction than this patch. > > > -- > paul-moore.com