From patchwork Mon Jul 19 18:46:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1507215 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=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) 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=udHbN+4P; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4GTB0T4l83z9sS8 for ; Tue, 20 Jul 2021 04:56:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D81A396E42E for ; Mon, 19 Jul 2021 18:56:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D81A396E42E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626721015; bh=EnKx/XHk7tHdsBOV5RJ/BGR6uKYEK4pBB+h1jRaf0+k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=udHbN+4PLobl+REc/9MOR5rJjO5c3dTBwUl3B1XjWMwxrTi/rMm+llfkdAJB89SjG 06WvTMTK9k/WDZ8m323JgMD/W/YCRER4Ou2BVpmojJbHa4dcS2RzP5tPnSlIiG6fGl exOHf75TtqFjB6FesIy8tmC0LihXmM4C4tP3LBwA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from aye.elm.relay.mailchannels.net (aye.elm.relay.mailchannels.net [23.83.212.6]) by sourceware.org (Postfix) with ESMTPS id ED4FD396E03F for ; Mon, 19 Jul 2021 18:47:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED4FD396E03F 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 AF22C362C7B; Mon, 19 Jul 2021 18:47:44 +0000 (UTC) Received: from pdx1-sub0-mail-a73.g.dreamhost.com (100-96-11-33.trex-nlb.outbound.svc.cluster.local [100.96.11.33]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 32CD53625AC; Mon, 19 Jul 2021 18:47:44 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a73.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.11.33 (trex/6.3.3); Mon, 19 Jul 2021 18:47:44 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Occur-Cure: 6d6884146620a0c2_1626720464523_2974156038 X-MC-Loop-Signature: 1626720464523:1385687441 X-MC-Ingress-Time: 1626720464522 Received: from pdx1-sub0-mail-a73.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a73.g.dreamhost.com (Postfix) with ESMTP id E56728A6A0; Mon, 19 Jul 2021 11:47:43 -0700 (PDT) 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-a73.g.dreamhost.com (Postfix) with ESMTPSA id 3305E8A6A9; Mon, 19 Jul 2021 11:47:40 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a73 To: libc-alpha@sourceware.org Subject: [PATCH v10 11/11] mcheck Fix malloc_usable_size [BZ #22057] Date: Tue, 20 Jul 2021 00:16:37 +0530 Message-Id: <20210719184637.1225275-12-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719184637.1225275-1-siddhesh@sourceware.org> References: <20210719184637.1225275-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-3494.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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: fweimer@redhat.com Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Interpose malloc_usable_size to return the correct mcheck value for malloc_usable_size. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell --- malloc/Makefile | 4 +--- malloc/malloc-debug.c | 2 ++ malloc/mcheck-impl.c | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/malloc/Makefile b/malloc/Makefile index a2b4383b68..48c6056fb3 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -83,7 +83,7 @@ ifeq ($(have-GLIBC_2.23)$(build-shared),yesyes) # the tests expect specific internal behavior that is changed due to linking to # libmcheck.a. tests-exclude-mcheck = tst-mallocstate \ - tst-safe-linking tst-malloc-usable \ + tst-safe-linking \ tst-malloc-backtrace \ tst-malloc-fork-deadlock \ tst-malloc-stats-cancellation \ @@ -92,8 +92,6 @@ tests-exclude-mcheck = tst-mallocstate \ tst-malloc-thread-fail \ tst-malloc-usable-tunables \ tst-malloc_info \ - tst-pvalloc-fortify \ - tst-reallocarray \ tst-compathooks-off tst-compathooks-on tests-mcheck = $(filter-out $(tests-exclude-mcheck), $(tests)) diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c index 34523b0cc3..9922ef5f25 100644 --- a/malloc/malloc-debug.c +++ b/malloc/malloc-debug.c @@ -399,6 +399,8 @@ strong_alias (__debug_calloc, calloc) size_t malloc_usable_size (void *mem) { + if (__is_malloc_debug_enabled (MALLOC_MCHECK_HOOK)) + return mcheck_usable_size (mem); if (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK)) return malloc_check_get_size (mem); diff --git a/malloc/mcheck-impl.c b/malloc/mcheck-impl.c index 8857e6b179..6597a290a6 100644 --- a/malloc/mcheck-impl.c +++ b/malloc/mcheck-impl.c @@ -404,3 +404,9 @@ __mcheck_initialize (void (*func) (enum mcheck_status), bool in_pedantic) pedantic = in_pedantic; return 0; } + +static int +mcheck_usable_size (struct hdr *h) +{ + return (h - 1)->size; +}