From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16814C433E0 for ; Thu, 30 Jul 2020 22:23:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 917572083B for ; Thu, 30 Jul 2020 22:23:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 917572083B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=schaufler-ca.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-audit-bounces@redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-T3YTuVlYN2O7tATn6LKNLA-1; Thu, 30 Jul 2020 18:23:03 -0400 X-MC-Unique: T3YTuVlYN2O7tATn6LKNLA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D55FC19057A0; Thu, 30 Jul 2020 22:22:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81FA910016E8; Thu, 30 Jul 2020 22:22:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9EE391809554; Thu, 30 Jul 2020 22:22:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06UMMu1P021896 for ; Thu, 30 Jul 2020 18:22:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 51A2C111145E; Thu, 30 Jul 2020 22:22:56 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CFC9100BC9E for ; Thu, 30 Jul 2020 22:22:53 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3BE72857FAE for ; Thu, 30 Jul 2020 22:22:53 +0000 (UTC) Received: from sonic314-27.consmr.mail.ne1.yahoo.com (sonic314-27.consmr.mail.ne1.yahoo.com [66.163.189.153]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-182-rb6NremTOR67p8cbeEAsPQ-1; Thu, 30 Jul 2020 18:22:50 -0400 X-MC-Unique: rb6NremTOR67p8cbeEAsPQ-1 X-YMail-OSG: 4plBhRQVM1lbyp3LLNF6A3_ESt0vectOzYucNmDPZebaUAzBMvhNSv7_IW1WB6C G5dmlbtwbt9Fh_J5boBwqfoaWEJJB2GHTzLbqPhjdAGrGdowczc7Ux5LBZy7XT6OOm62IuDkjqAH BNtXrR6HvN0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WjIltyaKwcpDkpm0srYO2PQvRqi9ZLefE AxZHDWVuB_zRC.5o_RqoT2DH0MSLCPxY54N5yY5QwZ.8PZKWJkCHe6xIGO4Dub3_yQ9sAsSyxFc3 9ONS3yrl2lJQPkGNaA6.j7uLLqOg.W.Sqr6serqLtDgOKzlnZnkwLK3wsycjOAQ-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ne1.yahoo.com with HTTP; Thu, 30 Jul 2020 22:22:50 +0000 Received: by smtp410.mail.ne1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 4ac6482c02314194467082833f946851; Thu, 30 Jul 2020 22:22:48 +0000 (UTC) Subject: Re: [PATCH v19 22/23] LSM: Add /proc attr entry for full LSM context To: John Johansen , casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org References: <20200724203226.16374-1-casey@schaufler-ca.com> <20200724203226.16374-23-casey@schaufler-ca.com> <705fb82d-ad7a-2874-59ed-ba6bc7ae3722@schaufler-ca.com> <97330b2d-5447-cfef-b6d0-444249e671b7@canonical.com> From: Casey Schaufler Message-ID: <18fcf6b1-3ef6-bb8b-d2b2-e0fd45bdb68c@schaufler-ca.com> Date: Thu, 30 Jul 2020 15:22:47 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <97330b2d-5447-cfef-b6d0-444249e671b7@canonical.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: linux-audit@redhat.com Cc: linux-api@vger.kernel.org, linux-audit@redhat.com, sds@tycho.nsa.gov X-BeenThere: linux-audit@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Linux Audit Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=linux-audit-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On 7/30/2020 1:57 PM, John Johansen wrote: > On 7/30/20 1:44 PM, Casey Schaufler wrote: >> On 7/30/2020 3:03 AM, John Johansen wrote: >>> On 7/24/20 1:32 PM, Casey Schaufler wrote: >>>> Add an entry /proc/.../attr/context which displays the full >>>> process security "context" in compound format: >>>> lsm1\0value\0lsm2\0value\0... >>>> This entry is not writable. >>>> >>>> A security module may decide that its policy does not allow >>>> this information to be displayed. In this case none of the >>>> information will be displayed. >>>> >>>> Reviewed-by: Kees Cook >>>> Signed-off-by: Casey Schaufler >>>> Cc: linux-api@vger.kernel.org >>>> --- >>>> Documentation/security/lsm.rst | 28 +++++++++++ >>>> fs/proc/base.c | 1 + >>>> include/linux/lsm_hooks.h | 6 +++ >>>> security/apparmor/include/procattr.h | 2 +- >>>> security/apparmor/lsm.c | 8 +++- >>>> security/apparmor/procattr.c | 22 +++++---- >>>> security/security.c | 70 ++++++++++++++++++++++++++++ >>>> security/selinux/hooks.c | 2 +- >>>> security/smack/smack_lsm.c | 2 +- >>>> 9 files changed, 126 insertions(+), 15 deletions(-) >> >> >>>> >>>> /** >>>> diff --git a/security/security.c b/security/security.c >>>> index d35e578fa45b..bce6be720401 100644 >>>> --- a/security/security.c >>>> +++ b/security/security.c >>>> @@ -754,6 +754,48 @@ static void __init lsm_early_task(struct task_struct *task) >>>> panic("%s: Early task alloc failed.\n", __func__); >>>> } >>>> >>>> +/** >>>> + * append_ctx - append a lsm/context pair to a compound context >>>> + * @ctx: the existing compound context >>>> + * @ctxlen: size of the old context, including terminating nul byte >>>> + * @lsm: new lsm name, nul terminated >>>> + * @new: new context, possibly nul terminated >>>> + * @newlen: maximum size of @new >>>> + * >>>> + * replace @ctx with a new compound context, appending @newlsm and @new >>>> + * to @ctx. On exit the new data replaces the old, which is freed. >>>> + * @ctxlen is set to the new size, which includes a trailing nul byte. >>>> + * >>>> + * Returns 0 on success, -ENOMEM if no memory is available. >>>> + */ >>>> +static int append_ctx(char **ctx, int *ctxlen, const char *lsm, char *new, >>>> + int newlen) >>>> +{ >>>> + char *final; >>>> + size_t llen; >>>> + >>>> + llen = strlen(lsm) + 1; >>>> + /* >>>> + * A security module may or may not provide a trailing nul on >>>> + * when returning a security context. There is no definition >>>> + * of which it should be, and there are modules that do it >>>> + * each way. >>>> + */ >>>> + newlen = strnlen(new, newlen) + 1; >>>> + >>>> + final = kzalloc(*ctxlen + llen + newlen, GFP_KERNEL); >>>> + if (final == NULL) >>>> + return -ENOMEM; >>>> + if (*ctxlen) >>>> + memcpy(final, *ctx, *ctxlen); >>>> + memcpy(final + *ctxlen, lsm, llen); >>>> + memcpy(final + *ctxlen + llen, new, newlen); >>> if @new doesn't have a newline appended at its end this will read 1 byte >>> passed the end of the @new buffer. Nor will the result have a trailing >>> \0 as expected unless we get lucky. >> @new will never have a newline at the end. The trailing nul comes >> from the allocation being done with kzalloc(). This function has to >> be considered in the context of its caller. >> > ugh, sorry not trailing newline, I meant trailing \0. The problem isn't > the kzalloc, the target has the space. It is the source @new. It is > dangerous to assume that the @new buffer has a null byte after its > declared length. Which is potentially what we are doing if @new > doesn't have an embedded null byte. In that case strlen(new, newlen) > will then return newlen and we add 1 to it. > > which means in the memcpy we are copying an extra byte beyond what > was declared to exist in @new. You're right. Good point. Fix coming. ?? -- Linux-audit mailing list Linux-audit@redhat.com https://www.redhat.com/mailman/listinfo/linux-audit