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 F06E242E3C; Mon, 10 Jul 2023 19:08:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8620142B8E; Mon, 10 Jul 2023 19:08:09 +0200 (CEST) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mails.dpdk.org (Postfix) with ESMTP id E088941611 for ; Mon, 10 Jul 2023 19:08:06 +0200 (CEST) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-666e6541c98so4176796b3a.2 for ; Mon, 10 Jul 2023 10:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1689008886; x=1691600886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HadCKv8ON/rlBz7y5pzzsqsNZoiFEyBsmZEp/1o1ERk=; b=DfxirwkoSjFq1kGP8vWv5a9oThzbFnQq5xG5bExyzTJcN6UClkS00JVvPd44ErZZPp TEFCKiEh1RGp4SmGtBRkvrUB/1Tu/i07jbatGOz/GO6XP73dPvIvyDHQn1wxYv2LNDCy x4QrU4MNI3pwLawo4ruA/vHluHZgASTLrD0QTpPgzTm9BQJ0e3077Fp4NWDKfi1QFdGS jdxAZFAQZXtTIYLcTzwhY1I28O+KW7xUx+FylAoLdRkigwUrXFfAotQHrMfTj22gmo5K PIe21DUtYM5LDk+TY6gpB9q7d3ouGzOBRNUvkvJZ4CBwV+ks1+Yh/mdbFiNNvDJsvJp5 Sniw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689008886; x=1691600886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HadCKv8ON/rlBz7y5pzzsqsNZoiFEyBsmZEp/1o1ERk=; b=dhNrLuSAovMI5u8rmMECwAVRjzfTMihOkfzsKWMADAY+yhiRqm53OPsR8ReI0xE/UO PEHGRdisJtPAElVer2hh8qs5K/9rO+QIJcbBee5aCWVncEWTfbgQ5qrwYzXPObFYn03e lCIHpwRd1CG0eTZulD5qjbZmsYheNJigOEKWyJBq0INM6xddLOIe//NBLUjsxrcPHbrk 38401Pgnt3CPT3lra94twGQwmeGivAitaHA1oHWwqwCF6adiJgYc3pcY6Tyw50XbVtwg bnoNu4re+/hxnZ29qoQHdaQMhMlg1NwS4upmmWMJ3rDXQynvtqslliRPbyohKVN/HUOa gS0g== X-Gm-Message-State: ABy/qLZjereKErE2rb6oaZ3Hfs4lD2I90YZmyAGHWUp+8PgQqH0foh20 S3hirGuho9IOMHLE/EIsgdV8yf13sWT7W2FZZobbXQ== X-Google-Smtp-Source: APBJJlHZGoLI0pYfbNv47U2EUuBMn6fNkOF09pmUczS/pjaYG5Dnbv+JQIXrQ1n9W8vGU+8BwGWc9Q== X-Received: by 2002:a05:6a20:2585:b0:12e:5f07:7ede with SMTP id k5-20020a056a20258500b0012e5f077edemr16868438pzd.41.1689008885747; Mon, 10 Jul 2023 10:08:05 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id q17-20020a62e111000000b00682ed27f99dsm51799pfh.46.2023.07.10.10.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 10:08:05 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Sinan Kaya , Stephen Hemminger , Anatoly Burakov Subject: [PATCH v4 3/5] memzone: check result of rte_fbarray_get and malloc_elem_from_data Date: Mon, 10 Jul 2023 10:07:58 -0700 Message-Id: <20230710170800.12478-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230710170800.12478-1-stephen@networkplumber.org> References: <20230120044140.95975-1-okaya@kernel.org> <20230710170800.12478-1-stephen@networkplumber.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 memzone_lookup_thread_unsafe result of call to rte_fbarray_get is dereferenced here and may be null. In memzone_reserve_aligned_thread_unsafe result of call to malloc_elem_from_data is dereferenced here and may be null. Signed-off-by: Sinan Kaya Signed-off-by: Stephen Hemminger --- lib/eal/common/eal_common_memzone.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/eal/common/eal_common_memzone.c b/lib/eal/common/eal_common_memzone.c index 1f3e7014995b..c96053b41e63 100644 --- a/lib/eal/common/eal_common_memzone.c +++ b/lib/eal/common/eal_common_memzone.c @@ -77,7 +77,7 @@ memzone_lookup_thread_unsafe(const char *name) i = rte_fbarray_find_next_used(arr, 0); while (i >= 0) { mz = rte_fbarray_get(arr, i); - if (mz->addr != NULL && + if ((mz != NULL) && (mz->addr != NULL) && !strncmp(name, mz->name, RTE_MEMZONE_NAMESIZE)) return mz; i = rte_fbarray_find_next_used(arr, i + 1); @@ -206,6 +206,10 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, } struct malloc_elem *elem = malloc_elem_from_data(mz_addr); + if (elem == NULL) { + rte_errno = ENOSPC; + return NULL; + } /* fill the zone in config */ mz_idx = rte_fbarray_find_next_free(arr, 0); @@ -395,6 +399,10 @@ dump_memzone(const struct rte_memzone *mz, void *arg) fprintf(f, "physical segments used:\n"); ms_idx = RTE_PTR_DIFF(mz->addr, msl->base_va) / page_sz; ms = rte_fbarray_get(&msl->memseg_arr, ms_idx); + if (ms == NULL) { + RTE_LOG(DEBUG, EAL, "Skipping bad memzone\n"); + return; + } do { fprintf(f, " addr: %p iova: 0x%" PRIx64 " " -- 2.39.2