DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: fix check number of bytes from read function
@ 2016-07-20 14:24 Michal Jastrzebski
  2016-07-21 14:35 ` Thomas Monjalon
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Michal Jastrzebski @ 2016-07-20 14:24 UTC (permalink / raw)
  To: bruce.richardson
  Cc: dev, michalx.kobylinski, sergio.gonzalez.monroy, david.marchand

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 <michalx.k.jastrzebski@intel.com>
---
 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))	{
+		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);
+		return RTE_BAD_PHYS_ADDR;
 	}
 
 	/*
-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-07-22 16:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-20 14:24 [dpdk-dev] [PATCH] eal: fix check number of bytes from read function Michal Jastrzebski
2016-07-21 14:35 ` Thomas Monjalon
2016-07-21 20:50   ` Jastrzebski, MichalX K
2016-07-21 23:09     ` Thomas Monjalon
2016-07-21 14:37 ` Sergio Gonzalez Monroy
2016-07-22 14:38   ` Jastrzebski, MichalX K
2016-07-22 14:33 ` [dpdk-dev] [PATCH v2] " Michal Jastrzebski
2016-07-22 15:24   ` Thomas Monjalon
2016-07-22 16:02     ` Sergio Gonzalez Monroy
2016-07-22 16:22       ` Thomas Monjalon
2016-07-22 16:23     ` Jastrzebski, MichalX K

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).