From patchwork Tue Dec 22 15:59:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1419439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=qR1jbVqS; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D0gzb714fz9sVk for ; Wed, 23 Dec 2020 03:00:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37737388A029; Tue, 22 Dec 2020 16:00:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37737388A029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1608652840; bh=ncq5RYVaX2wOyeW/jO+8XWf5dCyerNBrg5pHAFlCOvA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qR1jbVqSTfQkEURxYWtJfUoaScMvp/ncw2Ae10SOJxb//CMFwts1TxG+jCRpKLpIW TgGJfPB39wpP/isot3Udk0xBVGHNTySIxbLAsSqMlQ3AIHoFbamGWpbV6CeE7llVsm cm9tA7VE0PIu81rTPNeB9jNZP5JWTTpychHzwc5s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from donkey.elm.relay.mailchannels.net (donkey.elm.relay.mailchannels.net [23.83.212.49]) by sourceware.org (Postfix) with ESMTPS id D0E603887035 for ; Tue, 22 Dec 2020 16:00:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D0E603887035 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 6B9B922779; Tue, 22 Dec 2020 16:00:35 +0000 (UTC) Received: from pdx1-sub0-mail-a49.g.dreamhost.com (100-96-8-104.trex.outbound.svc.cluster.local [100.96.8.104]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 63D66228B9; Tue, 22 Dec 2020 16:00:22 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a49.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.18.11); Tue, 22 Dec 2020 16:00:35 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Juvenile-Bored: 01d14b16703b9042_1608652830869_3671232553 X-MC-Loop-Signature: 1608652830869:4251028881 X-MC-Ingress-Time: 1608652830869 Received: from pdx1-sub0-mail-a49.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a49.g.dreamhost.com (Postfix) with ESMTP id BA9D08AB4F; Tue, 22 Dec 2020 08:00:20 -0800 (PST) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a49.g.dreamhost.com (Postfix) with ESMTPSA id C6BA68AB4D; Tue, 22 Dec 2020 08:00:17 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a49 To: libc-alpha@sourceware.org Subject: [PATCH] MTE: Do not pad size in realloc_check Date: Tue, 22 Dec 2020 21:29:58 +0530 Message-Id: <20201222155958.362134-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, 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-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Cc: schwab@linux-m68k.org, rearnsha@arm.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The MTE patch to add malloc support incorrectly padded the size passed to _int_realloc by SIZE_SZ when it ought to have sent just the chunksize. Revert that bit of the change so that realloc works correctly with MALLOC_CHECK_ set. This also brings the realloc_check implementation back in sync with libc_realloc. --- malloc/hooks.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/malloc/hooks.c b/malloc/hooks.c index 8a1c16dfa4..6474ba8b38 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -315,7 +315,7 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) __libc_lock_unlock (main_arena.mutex); if (!oldp) malloc_printerr ("realloc(): invalid pointer"); - const INTERNAL_SIZE_T oldchsize = CHUNK_AVAILABLE_SIZE (oldp); + const INTERNAL_SIZE_T oldsize = chunksize (oldp); if (!checked_request2size (rb, &chnb)) goto invert; @@ -331,7 +331,8 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) else #endif { - if (oldchsize >= chnb) + /* Note the extra SIZE_SZ overhead. */ + if (oldsize - SIZE_SZ >= chnb) newmem = oldmem; /* do nothing */ else { @@ -340,7 +341,7 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) newmem = _int_malloc (&main_arena, rb); if (newmem) { - memcpy (newmem, oldmem, oldchsize - CHUNK_HDR_SZ); + memcpy (newmem, oldmem, oldsize - CHUNK_HDR_SZ); munmap_chunk (oldp); } } @@ -349,7 +350,7 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) else { top_check (); - newmem = _int_realloc (&main_arena, oldp, oldchsize, chnb); + newmem = _int_realloc (&main_arena, oldp, oldsize, chnb); } DIAG_PUSH_NEEDS_COMMENT;