From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 5487D385DC1A for ; Sat, 4 Apr 2020 16:10:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5487D385DC1A Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-438-5CCCtgsiMiem5V5XUTGqaw-1; Sat, 04 Apr 2020 12:10:47 -0400 X-MC-Unique: 5CCCtgsiMiem5V5XUTGqaw-1 Received: by mail-qv1-f70.google.com with SMTP id v4so8757836qvt.3 for ; Sat, 04 Apr 2020 09:10:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=3Nj8c23eSxV+vyapFg1CC14RupoZkHzofmegsOqbu8I=; b=U2EnKXWwdhkZIz3Zl5w3RtJKWTNIWihisqNYkF5wp6Qtwvs2QQyABY+Tg04VhBXLQ1 sIUf64mxP09ClB8lYLjvmXKCIZzDNjnb+rmZt184uqmXggfjL8sPaxV/xSh6DsyTqZ4r F0nJEJL60tW/ZyUWK++5k6jH4+49Z0ccQWP7Ghy3g1VVh1Amaj2BjkIl2G1hyGsRcoYO +1uhCJBcz3v/Yw3k7DHdsgjnW38C/TPNvm7MDfV6n3bRS/calZKZhBwReO7w0i3si3Fq LkbYu1MRbKyVVFMIm7CSXsOIhVrRRqoZ+FB8IlUfaFxJJKA5dSa6bTadSUrM2Cg50q8Q 2PaQ== X-Gm-Message-State: AGi0PuZ9J8zY6GAX/urXhGpqbP3xUqzqjlxXYKMIMI1mlmPO/mYDKYxY 350otLixyFH7V8h0NLXeYkkuK2lppRcAXeIXHyNEx+2eue7SPZYAPpAfwJHbtcbdVthfo2brIiT vvgR7M6uHD988qq7UW7ZI X-Received: by 2002:ac8:1865:: with SMTP id n34mr12699166qtk.93.1586016646726; Sat, 04 Apr 2020 09:10:46 -0700 (PDT) X-Google-Smtp-Source: APiQypKuPE1JFFi6mHg50zS0Q2AFc28z1vuhNshSdwOTABjbTF5sZk4crX+dWMs4AyfO9h0oUWH7jw== X-Received: by 2002:ac8:1865:: with SMTP id n34mr12699159qtk.93.1586016646512; Sat, 04 Apr 2020 09:10:46 -0700 (PDT) Received: from [192.168.1.4] (198-84-170-103.cpe.teksavvy.com. [198.84.170.103]) by smtp.gmail.com with ESMTPSA id d19sm9616289qkc.14.2020.04.04.09.10.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 04 Apr 2020 09:10:45 -0700 (PDT) Subject: Re: malloc: ensure set_max_fast never stores zero To: DJ Delorie , libc-alpha@sourceware.org References: From: Carlos O'Donell Organization: Red Hat Message-ID: Date: Sat, 4 Apr 2020 12:10:44 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-21.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Sat, 04 Apr 2020 16:10:52 -0000 On 4/4/20 1:52 AM, DJ Delorie via Libc-alpha wrote: > > The code for set_max_fast() stores an "impossibly small value" > instead of zero, when the parameter is zero. However, for > small values of the parameter (ex: 1 or 2) the computation > results in a zero being stored anyway. Agreed. > This patch checks for the parameter being small enough for the > computation to result in zero instead, so that a zero is never > stored. Right, because (1 + SIZE_SZ) & ~MALLOC_ALIGN_MASK is zero. > key values which result in zero being stored: > > x86-64: 1..7 (or other 64-bit) > i686: 1..11 > armhfp: 1..3 (or other 32-bit) > OK with bug # attached. Reviewed-by: Carlos O'Donell > diff --git a/malloc/malloc.c b/malloc/malloc.c > index 6acb5ad43a..ee87ddbbf9 100644 > --- a/malloc/malloc.c > +++ b/malloc/malloc.c > @@ -1632,7 +1632,7 @@ static INTERNAL_SIZE_T global_max_fast; > */ > > #define set_max_fast(s) \ > - global_max_fast = (((s) == 0) \ > + global_max_fast = (((size_t) (s) <= MALLOC_ALIGN_MASK - SIZE_SZ) \ > ? MIN_CHUNK_SIZE / 2 : ((s + SIZE_SZ) & ~MALLOC_ALIGN_MASK)) > > static inline INTERNAL_SIZE_T > -- Cheers, Carlos.