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 63109A0582; Tue, 22 Nov 2022 16:52:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF35142D9B; Tue, 22 Nov 2022 16:52:42 +0100 (CET) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by mails.dpdk.org (Postfix) with ESMTP id 2864342D77 for ; Tue, 22 Nov 2022 16:52:41 +0100 (CET) Received: by mail-lj1-f175.google.com with SMTP id r8so7814602ljn.8 for ; Tue, 22 Nov 2022 07:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=CtcbXuPN1LAVhOvPs/+8p2aqFgL+Lg4Y9/gMK7qzgPA=; b=Iww4tR6FA9FzzHz240j8HxwkR3fcv6jt5ryxXCggnevriIzWp68TJcaqF2h4Q12QZ9 x0j2R/VFLIrR/JW5rynGtj2vgLWguPSmW7LGcE9K2NUOQMgSmwFcNsNYDibt3hArDTQP I2TkMvA/w4YWYTexDpnSQBIhv9o5jTQX4YwMVZHvHI7whxDDrQzRjzQiJZu4i0Hb9Abv YerLwviKDIP3v+xCmES8IfIekbdZFRf9JlrSpXjztPETe6ckHrJFcuXtEpij3rQ+jjl9 A2gAjYtg4cLYWM+JpMW655r3cweB8UXbXHMtxDA4YTTKGoNPp9zLPJyp9keB3k8XDKVE D+yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CtcbXuPN1LAVhOvPs/+8p2aqFgL+Lg4Y9/gMK7qzgPA=; b=kt3AKVpEpH00lodExSJSiPmVCDamb7EhENviw6ASriLXWU+d4NX0FlCTMXuu57GnDs WO6c3rvA46NfZ/uOuKi6UV4UJ9qPN66p8T5/sEIAuAMumPvNC48ZaRjUlr3zQn8+IS0B x8DE9VDw0OZdfpcnD24estynoAAWN+NMOoSWTUeKwIDjqtMu/4+e6LPbgEz2CQsvkZsc SNCgUuyHaOYZ4j/yG9sRPG1WFsUcHUP5/djIIgG42Ggj+pp7P9tWBaCFqhIyeqJeAc88 hICftBTGN+ZC223AToN40IvG6ucvoJxAa3CXZaetJIMdhz8BDFKanzfmTd/XcIsSQfj7 LjMQ== X-Gm-Message-State: ANoB5plIiuZLfTRnoEsXtssQh1wa04aDGz5B5gTg8svwwQD2+Ef1NM/O YywUZz2VXE4TGQt25BuN+L0= X-Google-Smtp-Source: AA0mqf7qIuxIj30Jrnc05Z/O1M2UfZY9y5kSCaukViPsH3WnwEZSZ7o5/Y9t+i6/ITfC0Dn5bLjmnQ== X-Received: by 2002:a05:651c:205d:b0:26f:b445:8c8a with SMTP id t29-20020a05651c205d00b0026fb4458c8amr1877794ljo.156.1669132360697; Tue, 22 Nov 2022 07:52:40 -0800 (PST) Received: from sovereign (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id u23-20020a2e9f17000000b0027706d22878sm1919837ljk.94.2022.11.22.07.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 07:52:40 -0800 (PST) Date: Tue, 22 Nov 2022 18:52:39 +0300 From: Dmitry Kozlyuk To: okaya@kernel.org Cc: dev@dpdk.org Subject: Re: [PATCH v2 08/11] malloc: check result of rte_mem_virt2memseg Message-ID: <20221122185239.665c2edc@sovereign> In-Reply-To: <20221121223208.1147154-9-okaya@kernel.org> References: <20221121223208.1147154-1-okaya@kernel.org> <20221121223208.1147154-9-okaya@kernel.org> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 2022-11-21 17:32 (UTC-0500), okaya@kernel.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); > } In these three places "ms" or "tmp" are from the MSL by construction. I think RTE_ASSERT() would be sufficient.