From patchwork Wed Oct 12 14:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 58700 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E9A33851170 for ; Wed, 12 Oct 2022 14:03:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E9A33851170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665583386; bh=71/748JmjytqYl8KIo+kOdLwUiT4iNGT2+jafYIWBEQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=it9pz+9JlOBxdO8UemBC7cSuB7S4bAUb5IZeQypGPylS/A6LQ8egA+i12IAQqGozj ApRTFeoZ1s/CpjcJfDCsU8waPJU9lUOxMfOWDuzbeLNJTcMuoGLC+AQSoO7v8tCs7f N9nb7X2oktiZ3xbbjjAhAzPyqBQcDF/qboNyX1PM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 19EC738582BC for ; Wed, 12 Oct 2022 14:02:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 19EC738582BC Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-657-KzFDQvZaPX-Zfz331mbxSA-1; Wed, 12 Oct 2022 10:02:15 -0400 X-MC-Unique: KzFDQvZaPX-Zfz331mbxSA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4859F19705A8 for ; Wed, 12 Oct 2022 14:02:15 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0F29429832 for ; Wed, 12 Oct 2022 14:02:13 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] malloc: Switch global_max_fast to uint8_t Date: Wed, 12 Oct 2022 16:02:11 +0200 Message-ID: <87bkqhywbg.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" MAX_FAST_SIZE is 160 at most, so a uint8_t is sufficient. This makes it harder to use memory corruption, by overwriting global_max_fast with a large value, to fundamentally alter malloc behavior. Tested i686-linux-gnu and x86_64-linux-gnu. Reviewed-by: DJ Delorie --- malloc/malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 264db94040c463d9bc356101595d89335586875e diff --git a/malloc/malloc.c b/malloc/malloc.c index 953183e956..2a61c8b5ee 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1757,7 +1757,7 @@ typedef struct malloc_chunk *mfastbinptr; #define set_contiguous(M) ((M)->flags &= ~NONCONTIGUOUS_BIT) /* Maximum size of memory handled in fastbins. */ -static INTERNAL_SIZE_T global_max_fast; +static uint8_t global_max_fast; /* Set value of max_fast.