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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7049CC7EE24 for ; Thu, 11 May 2023 21:48:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231376AbjEKVsq (ORCPT ); Thu, 11 May 2023 17:48:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238966AbjEKVso (ORCPT ); Thu, 11 May 2023 17:48:44 -0400 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2F454690; Thu, 11 May 2023 14:48:42 -0700 (PDT) Received: from [10.230.83.65] (unknown [72.28.92.215]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 3722440026; Thu, 11 May 2023 21:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1683841719; bh=hjvm1zm7cWLOP+uGf76IIMlTIPMFKlV+xXfMnXyGB8Q=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Cjhg1vG0eHurLwCGA5RC85fFZHhbtKuQVMy4+k9XxNBIQ2RfNELgpNkVU2786iQeU EWeNhfVzikltesWaOsNXR8iVjzsuKOtRFjAqbHv2S5gyQt+bta974N+Z9gtor4AfPD dVSTc/GDABBZ5f2Fo9wphW+bkvJ475qR9CcgmYj/u7rOUWmZURzTCskLqVCdRj7uXw 3BnhIR0AsBqBsLyPIIz83GmU5vJqRz5gMZJYa9J/d3fYIOfpkv0IuavddN5LKNur7U +UheZL1FcyvGu6wfqcPKwdo1H4d2MuuTrzqDpzKEE4XP129oPMZeXOxU1oPUJ9DZEP 9q4Y5MdEPP25g== Message-ID: <7085879d-4d21-b90a-c08d-60450d1c7d38@canonical.com> Date: Thu, 11 May 2023 14:48:29 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] apparmor: aa_buffer: Convert 1-element array to flexible array Content-Language: en-US To: Kees Cook Cc: "Gustavo A . R . Silva" , Paul Moore , James Morris , "Serge E. Hallyn" , apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20230511213441.never.401-kees@kernel.org> From: John Johansen Organization: Canonical In-Reply-To: <20230511213441.never.401-kees@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: On 5/11/23 14:34, Kees Cook wrote: > In the ongoing effort to convert all fake flexible arrays to proper > flexible arrays, replace aa_buffer's 1-element "buffer" member with a > flexible array. > > Cc: John Johansen > Cc: Gustavo A. R. Silva > Cc: Paul Moore > Cc: James Morris > Cc: "Serge E. Hallyn" > Cc: apparmor@lists.ubuntu.com > Cc: linux-security-module@vger.kernel.org > Signed-off-by: Kees Cook Acked-by: John Johansen I have pulled this into my tree. > --- > One thing I notice here is that it may be rare for "buffer" to ever change > for a given kernel. Could this just be made PATH_MAX * 2 directly and > remove the module parameter, etc, etc? possibly. Currently the only use case I know of is for some stress testing where we drop the buffer size down really small to try and break things. This isn't part of the regular regression runs and could be handle with a config/compile time to a buffer size constant. > --- > security/apparmor/lsm.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c > index d6cc4812ca53..35eb41bb9e3a 100644 > --- a/security/apparmor/lsm.c > +++ b/security/apparmor/lsm.c > @@ -46,7 +46,7 @@ int apparmor_initialized; > > union aa_buffer { > struct list_head list; > - char buffer[1]; > + DECLARE_FLEX_ARRAY(char, buffer); > }; > > #define RESERVE_COUNT 2 > @@ -1647,7 +1647,7 @@ char *aa_get_buffer(bool in_atomic) > list_del(&aa_buf->list); > buffer_count--; > spin_unlock(&aa_buffers_lock); > - return &aa_buf->buffer[0]; > + return aa_buf->buffer; > } > if (in_atomic) { > /* > @@ -1670,7 +1670,7 @@ char *aa_get_buffer(bool in_atomic) > pr_warn_once("AppArmor: Failed to allocate a memory buffer.\n"); > return NULL; > } > - return &aa_buf->buffer[0]; > + return aa_buf->buffer; > } > > void aa_put_buffer(char *buf) > @@ -1747,7 +1747,7 @@ static int __init alloc_buffers(void) > destroy_buffers(); > return -ENOMEM; > } > - aa_put_buffer(&aa_buf->buffer[0]); > + aa_put_buffer(aa_buf->buffer); > } > return 0; > }