From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id ED56345B5D; Thu, 17 Oct 2024 12:02:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id ACAE640279; Thu, 17 Oct 2024 12:02:14 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by mails.dpdk.org (Postfix) with ESMTP id 5EC6A40273 for ; Thu, 17 Oct 2024 12:02:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729159334; x=1760695334; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=z+PhfK5XLcZsN/8TCjLQjOnz7dlZ2lHFtg2LktBTwTs=; b=F2jQ7szUgf5Ci/N/oFziDUCiI///CKdPKJTVSURrvKrXeD00E2drr12A fsibpoPePN++mk1j3dXE4k2NeTOJuroC4rhgmdWH97V2fboabvY2Uc9pN NltBqGjxuEV4O55pfy7yLkHI8LkqvrKqHZDEncgerF6wVjAHcXviBq+sD ciKwvGpS1GZi76SJCqIWsGXWOOQ6rq4qWUuukpTiW7igU5mUa9336EijG blDwiLu+GVyQTxwM+jHVjeeYT7Ja8Jl1BXl9HWZoXp/durMFZeo7B7vz8 Tm8mr0uY34uHrV/L8PQLDCmCZkLsdVACoo+xgfu9Q4SwTtnliHlbEWOyA w==; X-CSE-ConnectionGUID: fMM6MGpKTeOZJ83g7jqZKw== X-CSE-MsgGUID: LQXXJZ+dSYmGwltzvWsJqw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="28735860" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="28735860" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 03:02:13 -0700 X-CSE-ConnectionGUID: w9/oAianSbWG4HXI58cPjg== X-CSE-MsgGUID: 7blaOHJRQGWaXPDqplbUew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,210,1725346800"; d="scan'208";a="78527122" Received: from apaszkie-mobl2.apaszkie-mobl2 (HELO apaszkie-mobl2.intel.com) ([10.245.244.57]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 03:02:11 -0700 From: Artur Paszkiewicz To: dev@dpdk.org Cc: anatoly.burakov@intel.com, david.marchand@redhat.com Subject: [PATCH RESEND] malloc: fix allocation for a specific case with ASan Date: Thu, 17 Oct 2024 12:02:06 +0200 Message-ID: <20241017100207.1207-1-artur.paszkiewicz@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Allocation would fail with ASan enabled if the size and alignment was equal to half of the page size, e.g.: size_t pg_sz = 2 * (1 << 20); rte_malloc(NULL, pg_sz / 2, pg_sz / 2); In such case, try_expand_heap_primary() only allocated one page but it is not enough to fit this allocation with such alignment and MALLOC_ELEM_TRAILER_LEN > 0, as correctly checked by malloc_elem_can_hold(). Signed-off-by: Artur Paszkiewicz --- lib/eal/common/malloc_heap.c | 4 ++-- lib/eal/common/malloc_mp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c index 058aaf4209..5b93e7fcb8 100644 --- a/lib/eal/common/malloc_heap.c +++ b/lib/eal/common/malloc_heap.c @@ -401,8 +401,8 @@ try_expand_heap_primary(struct malloc_heap *heap, uint64_t pg_sz, int n_segs; bool callback_triggered = false; - alloc_sz = RTE_ALIGN_CEIL(RTE_ALIGN_CEIL(elt_size, align) + - MALLOC_ELEM_OVERHEAD, pg_sz); + alloc_sz = RTE_ALIGN_CEIL(RTE_MAX(MALLOC_ELEM_HEADER_LEN, align) + + elt_size + MALLOC_ELEM_TRAILER_LEN, pg_sz); n_segs = alloc_sz / pg_sz; /* we can't know in advance how many pages we'll need, so we malloc */ diff --git a/lib/eal/common/malloc_mp.c b/lib/eal/common/malloc_mp.c index 9765277f5d..1373da44c9 100644 --- a/lib/eal/common/malloc_mp.c +++ b/lib/eal/common/malloc_mp.c @@ -251,8 +251,8 @@ handle_alloc_request(const struct malloc_mp_req *m, return -1; } - alloc_sz = RTE_ALIGN_CEIL(RTE_ALIGN_CEIL(ar->elt_size, ar->align) + - MALLOC_ELEM_OVERHEAD, ar->page_sz); + alloc_sz = RTE_ALIGN_CEIL(RTE_MAX(MALLOC_ELEM_HEADER_LEN, ar->align) + + ar->elt_size + MALLOC_ELEM_TRAILER_LEN, ar->page_sz); n_segs = alloc_sz / ar->page_sz; /* we can't know in advance how many pages we'll need, so we malloc */ -- 2.43.0