From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 6926C37AC for ; Thu, 21 Jul 2016 16:37:24 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 21 Jul 2016 07:37:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,399,1464678000"; d="scan'208";a="850647083" Received: from smonroyx-mobl.ger.corp.intel.com (HELO [10.237.220.149]) ([10.237.220.149]) by orsmga003.jf.intel.com with ESMTP; 21 Jul 2016 07:37:21 -0700 To: Michal Jastrzebski , bruce.richardson@intel.com References: <1469024689-1076-1-git-send-email-michalx.k.jastrzebski@intel.com> Cc: dev@dpdk.org, michalx.kobylinski@intel.com, david.marchand@6wind.com From: Sergio Gonzalez Monroy Message-ID: Date: Thu, 21 Jul 2016 15:37:20 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <1469024689-1076-1-git-send-email-michalx.k.jastrzebski@intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] eal: fix check number of bytes from read function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2016 14:37:24 -0000 On 20/07/2016 15:24, Michal Jastrzebski wrote: > In rte_mem_virt2phy: Value returned from a function and indicating the > number of bytes was ignored. This could cause a wrong pfn (page frame > number) mask read from pagemap file. > When read returns less than the number of sizeof(uint64_t) bytes, > function rte_mem_virt2phy returns error. > > Coverity issue: 13212 > Fixes: 40b966a211ab ("ivshmem: library changes for mmaping using > ivshmem"). > > Signed-off-by: Michal Jastrzebski > --- > lib/librte_eal/linuxapp/eal/eal_memory.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c > index 42a29fa..05769fb 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_memory.c > +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c > @@ -158,7 +158,7 @@ rte_mem_lock_page(const void *virt) > phys_addr_t > rte_mem_virt2phy(const void *virtaddr) > { > - int fd; > + int fd, retval; > uint64_t page, physaddr; > unsigned long virt_pfn; > int page_size; > @@ -209,11 +209,19 @@ rte_mem_virt2phy(const void *virtaddr) > close(fd); > return RTE_BAD_PHYS_ADDR; > } > - if (read(fd, &page, sizeof(uint64_t)) < 0) { > + > + retval = read(fd, &page, sizeof(uint64_t)); > + if (retval < 0) { > RTE_LOG(ERR, EAL, "%s(): cannot read /proc/self/pagemap: %s\n", > __func__, strerror(errno)); > close(fd); > return RTE_BAD_PHYS_ADDR; > + } else if (retval >= 0 && retval < (int)sizeof(uint64_t)) { Just a couple of nits, retval >= 0 it's already implicit, no need to do that check. > + RTE_LOG(ERR, EAL, "%s(): read %d bytes from /proc/self/pagemap " > + "but expected %d: %s\n", > + __func__, retval, (int)sizeof(uint64_t), strerror(errno)); > + close(fd); Another nit, we could just close(fd) right after read, regardless of read being success or error as we close(fd) also on success just before exiting the function. Other than that: Acked-by: Sergio Gonzalez Monroy > + return RTE_BAD_PHYS_ADDR; > } > > /*