summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichal Jastrzebski <michalx.k.jastrzebski@intel.com>2016-07-22 16:33:50 +0200
committerThomas Monjalon <thomas.monjalon@6wind.com>2016-07-22 17:36:25 +0200
commitfe7b933b7ae0eccad4cae5937da30356fcc087d2 (patch)
tree75167bb710520a4ad4ff8415826ecdef7500e3f4 /lib
parent30301d0cace947f2b989caeec8a824565f873570 (diff)
downloaddpdk-fe7b933b7ae0eccad4cae5937da30356fcc087d2.zip
dpdk-fe7b933b7ae0eccad4cae5937da30356fcc087d2.tar.gz
dpdk-fe7b933b7ae0eccad4cae5937da30356fcc087d2.tar.xz
mem: fix check of physical address retrieval
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/librte_eal/linuxapp/eal/eal_memory.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 42a29fa..41e0a92 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -99,6 +99,8 @@
#include "eal_filesystem.h"
#include "eal_hugepages.h"
+#define PFN_MASK_SIZE 8
+
#ifdef RTE_LIBRTE_XEN_DOM0
int rte_xen_dom0_supported(void)
{
@@ -158,7 +160,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,10 +211,17 @@ 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, PFN_MASK_SIZE);
+ close(fd);
+ 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 != PFN_MASK_SIZE) {
+ RTE_LOG(ERR, EAL, "%s(): read %d bytes from /proc/self/pagemap "
+ "but expected %d:\n",
+ __func__, retval, PFN_MASK_SIZE);
return RTE_BAD_PHYS_ADDR;
}
@@ -222,7 +231,7 @@ rte_mem_virt2phy(const void *virtaddr)
*/
physaddr = ((page & 0x7fffffffffffffULL) * page_size)
+ ((unsigned long)virtaddr % page_size);
- close(fd);
+
return physaddr;
}