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 31D2AA0582; Tue, 22 Nov 2022 16:31:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9E6D442D98; Tue, 22 Nov 2022 16:31:05 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mails.dpdk.org (Postfix) with ESMTP id CF35742D85 for ; Tue, 22 Nov 2022 16:31:01 +0100 (CET) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9D2B4B81BEA for ; Tue, 22 Nov 2022 15:31:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1162CC433B5; Tue, 22 Nov 2022 15:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669131061; bh=W2hMNo666ixKADSmKcIGEqrJdVzX4Yclf2h5OFo6Gqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BVJVOTNHu0UsXX+XaKlBD0uoM9Z4fIszgRzD3VJNl681IhgCZzl+kMnF44eqN6xsT k5kc9KPSsYh0oc0imFirxsfta6CbX4IEGGIMJXhSj6pPjGOpLQzx9+cKyDjjtu45N6 PxF7pjj7LTyhjm8s7WjQr8VDmPNhv6xaFBmG8WgmAbSgavsdKfcgfpqjwDn4o295gO iztYLGLQyJ3bqaq+DKjnz74bJo4A8w911AG/cbViJMVr0xtiFZUPp6zW/e9TqsIBe5 FgCxezxnKIolrt2sKkmBLhhHSA2c7s/mXCVG41wrmKmVeUBnDNGAAWtZgKdtt6muSt Ph9zKys7IX7mw== From: okaya@kernel.org To: dev@dpdk.org Cc: Sinan Kaya Subject: [PATCH RESEND v2 08/11] malloc: check result of rte_mem_virt2memseg Date: Tue, 22 Nov 2022 10:30:50 -0500 Message-Id: <20221122153053.1172434-9-okaya@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122153053.1172434-1-okaya@kernel.org> References: <20221122153053.1172434-1-okaya@kernel.org> 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 From: Sinan Kaya In malloc_elem_find_max_iova_contig result of call to rte_mem_virt2memseg is dereferenced here and may be null. Signed-off-by: Sinan Kaya --- lib/eal/common/malloc_elem.c | 11 ++++++++--- lib/eal/common/malloc_heap.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/eal/common/malloc_elem.c b/lib/eal/common/malloc_elem.c index 83f05497cc..8f49812846 100644 --- a/lib/eal/common/malloc_elem.c +++ b/lib/eal/common/malloc_elem.c @@ -63,6 +63,8 @@ malloc_elem_find_max_iova_contig(struct malloc_elem *elem, size_t align) cur_page = RTE_PTR_ALIGN_FLOOR(contig_seg_start, page_sz); ms = rte_mem_virt2memseg(cur_page, elem->msl); + if (ms == NULL) + return 0; /* do first iteration outside the loop */ page_end = RTE_PTR_ADD(cur_page, page_sz); @@ -91,9 +93,12 @@ malloc_elem_find_max_iova_contig(struct malloc_elem *elem, size_t align) * we're not blowing past data end. */ ms = rte_mem_virt2memseg(contig_seg_start, elem->msl); - cur_page = ms->addr; - /* don't trigger another recalculation */ - expected_iova = ms->iova; + if (ms != NULL) { + cur_page = ms->addr; + + /* don't trigger another recalculation */ + expected_iova = ms->iova; + } continue; } /* cur_seg_end ends on a page boundary or on data end. if we're diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c index 3f41430e42..88270ce4d2 100644 --- a/lib/eal/common/malloc_heap.c +++ b/lib/eal/common/malloc_heap.c @@ -930,7 +930,7 @@ malloc_heap_free(struct malloc_elem *elem) const struct rte_memseg *tmp = rte_mem_virt2memseg(aligned_start, msl); - if (tmp->flags & RTE_MEMSEG_FLAG_DO_NOT_FREE) { + if ((tmp != NULL) && (tmp->flags & RTE_MEMSEG_FLAG_DO_NOT_FREE)) { /* this is an unfreeable segment, so move start */ aligned_start = RTE_PTR_ADD(tmp->addr, tmp->len); } -- 2.25.1