mm: check for truncation in vmalloc_type()
authorJan Beulich <jbeulich@suse.com>
Wed, 25 Nov 2020 13:07:36 +0000 (14:07 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 25 Nov 2020 13:07:36 +0000 (14:07 +0100)
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@xen.org>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
xen/common/vmap.c

index faebc1ddf1145210d95144606107a0a16c9c561e..4fd6b3067ec1be3dc66cad46e550a46677c11a35 100644 (file)
@@ -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;