[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] mm: check for truncation in vmalloc_type()



commit 500516fcb9e1c09eae9bbbd3b30bb294c6993853
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Wed Nov 25 14:07:36 2020 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Nov 25 14:07:36 2020 +0100

    mm: check for truncation in vmalloc_type()
    
    While it's currently implied from the checking xmalloc_array() does,
    let's make this more explicit in the function itself. As a result both
    involved local variables don't need to have size_t type anymore. This
    brings them in line with the rest of the code in this file.
    
    Requested-by: Julien Grall <julien@xxxxxxx>
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Julien Grall <jgrall@xxxxxxxxxx>
---
 xen/common/vmap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/xen/common/vmap.c b/xen/common/vmap.c
index faebc1ddf1..4fd6b3067e 100644
--- a/xen/common/vmap.c
+++ b/xen/common/vmap.c
@@ -242,13 +242,15 @@ void vunmap(const void *va)
 static void *vmalloc_type(size_t size, enum vmap_region type)
 {
     mfn_t *mfn;
-    size_t pages, i;
+    unsigned int i, pages = PFN_UP(size);
     struct page_info *pg;
     void *va;
 
     ASSERT(size);
 
-    pages = PFN_UP(size);
+    if ( PFN_DOWN(size) > pages )
+        return NULL;
+
     mfn = xmalloc_array(mfn_t, pages);
     if ( mfn == NULL )
         return NULL;
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.