[dpdk-dev] [PATCH] eal: fix check number of bytes from read function

Jastrzebski, MichalX K michalx.k.jastrzebski at intel.com
Fri Jul 22 16:38:08 CEST 2016


> -----Original Message-----
> From: Gonzalez Monroy, Sergio
> Sent: Thursday, July 21, 2016 4:37 PM
> To: Jastrzebski, MichalX K <michalx.k.jastrzebski at intel.com>; Richardson,
> Bruce <bruce.richardson at intel.com>
> Cc: dev at dpdk.org; Kobylinski, MichalX <michalx.kobylinski at intel.com>;
> david.marchand at 6wind.com
> Subject: Re: [PATCH] eal: fix check number of bytes from read function
> 
> 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 <michalx.k.jastrzebski at 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))	{
> 
> 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 <sergio.gonzalez.monroy at intel.com>
> 
> > +		return RTE_BAD_PHYS_ADDR;
> >   	}
> >
> >   	/*

Thanks Sergio,
I have sent v2 with the changes that You suggest

Michal.


More information about the dev mailing list