From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH] mem: fix overflowed return value Date: Fri, 22 Apr 2016 09:24:34 -0700 Message-ID: <20160422092434.00bc0c46@xeon-e3> References: <1461321858-30339-1-git-send-email-michalx.kobylinski@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: thomas.monjalon@6wind.com, dev@dpdk.org To: Michal Kobylinski Return-path: Received: from mail-pf0-f176.google.com (mail-pf0-f176.google.com [209.85.192.176]) by dpdk.org (Postfix) with ESMTP id 8102D2BBE for ; Fri, 22 Apr 2016 18:24:23 +0200 (CEST) Received: by mail-pf0-f176.google.com with SMTP id 184so42985424pff.0 for ; Fri, 22 Apr 2016 09:24:23 -0700 (PDT) In-Reply-To: <1461321858-30339-1-git-send-email-michalx.kobylinski@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, 22 Apr 2016 12:44:18 +0200 Michal Kobylinski wrote: > Fix issue reported by Coverity. > > Coverity ID 13255: Overflowed return value: The return value will be too > small or even negative, likely resulting in unexpected behavior in a > caller that uses the return value. In rte_mem_virt2phy: An integer > overflow occurs, with the overflowed value used as the return value of > the function > > Fixes: 3097de6e6bfb ("mem: get physical address of any pointer") > > Signed-off-by: Michal Kobylinski > --- > lib/librte_eal/linuxapp/eal/eal_memory.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c > index 5b9132c..6ceca5b 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_memory.c > +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c > @@ -195,7 +195,7 @@ rte_mem_virt2phy(const void *virtaddr) > * the pfn (page frame number) are bits 0-54 (see > * pagemap.txt in linux Documentation) > */ > - physaddr = ((page & 0x7fffffffffffffULL) * page_size) > + physaddr = (uint64_t)((page & 0x7fffffffffffffULL) * page_size) > + ((unsigned long)virtaddr % page_size); > close(fd); > return physaddr; I am not trusting any of these Coverity patches you are sending. It seems you think wraparound can be just fixed by casting, it can't