Skip to contentSkip to conversation

vmalloc.c: fix lose num_physpages checking

PATCH In review Figo.zhang 2 participants 2 messages Jul 10, 2009 – Jul 22, 2009

Subsystems (2)
lore
Share & tools
lore

Figo.zhang

author
#0 lore raw

PATCH 1/1 vmalloc.c: fix lose num_physpages checking

__get_vm_area_node() lose size (physpages limit) checking, it be called by __get_vm_area() that some drivers called it directly.

---
mm/vmalloc.c | 2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
mm/vmalloc.c +1 -1
index f8189a4..99f3aea 100644
@@ -1144,7 +1144,7 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
 	}
 
 	size = PAGE_ALIGN(size);
-	if (unlikely(!size))
+	if (unlikely(!size || (size >> PAGE_SHIFT) > num_physpages))
 		return NULL;
 
 	area = kmalloc_node(sizeof(*area), gfp_mask & GFP_RECLAIM_MASK, node);
maintainer
#1 lore raw
Quoted 13 lines · On Fri, 10 Jul 2009 10:06:44 +0800 "Figo.zhang" <[email protected]> wrote:

__get_vm_area_node() lose size (physpages limit) checking, it be called by __get_vm_area() that some drivers called it directly.

---
mm/vmalloc.c | 2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
mm/vmalloc.c +0 -0
index f8189a4..99f3aea 100644

mm/vmalloc.c static struct vm_struct *__get_vm_area_node(unsigned long size, · line 1150

Quoted 8 lines
mm/vmalloc.c +1 -1
@@ -1144,7 +1144,7 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
 	}
 
 	size = PAGE_ALIGN(size);
-	if (unlikely(!size))
+	if (unlikely(!size || (size >> PAGE_SHIFT) > num_physpages))
 		return NULL;
 
 	area = kmalloc_node(sizeof(*area), gfp_mask & GFP_RECLAIM_MASK, node);

I question whether those num_physpages checks in vmalloc.c are useful.

a) the caller is doing something crazy

b) if the caller passed in size=num_physpages-1 then that test will succeed, but the vmalloc is surely going to fail.

c) a request for >num_physpages of vmalloc space should fail later on in the vmalloc code, making this test redundant.

d) the cheerily undocumented __get_vm_area() and __get_vm_area_node() don't actually allocate physical pages for the area, and those functions cannot assume that the caller will be fully populating the area with physical pages, so checking that there are enough physical pages to fill the area doesn't make sense.

No?