[PATCH] avoid null pointer access in vm_struct

From: Mitsuo Hayasaka
Date: Wed Aug 17 2011 - 09:30:54 EST


The /proc/vmallocinfo shows information about vmalloc allocations in vmlist
that is a linklist of vm_struct. It, however, may access pages field of
vm_struct where a page was not allocated, which results in a null pointer
access and leads to a kernel panic.

Why this happen:
For example, in __vmalloc_area_node, the nr_pages field of vm_struct are
set to the expected number of pages to be allocated, before the actual
pages allocations. At the same time, when the /proc/vmallocinfo is read, it
accesses the pages field of vm_struct according to the nr_pages field at
show_numa_info(). Thus, a null pointer access happens.

Patch:
This patch avoids accessing the pages field with unallocated page when
show_numa_info() is called. So, it can solve this problem.

Signed-off-by: Mitsuo Hayasaka <mitsuo.hayasaka.hu@xxxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxx>
Cc: David Rientjes <rientjes@xxxxxxxxxx>
Cc: "Paul E. McKenney" <paulmck@xxxxxxxxxxxxxxxxxx>
Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>
---

mm/vmalloc.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 7ef0903..e2ec5b0 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2472,13 +2472,16 @@ static void show_numa_info(struct seq_file *m, struct vm_struct *v)
if (NUMA_BUILD) {
unsigned int nr, *counters = m->private;

- if (!counters)
+ if (!counters || !v->nr_pages || !v->pages)
return;

memset(counters, 0, nr_node_ids * sizeof(unsigned int));

- for (nr = 0; nr < v->nr_pages; nr++)
+ for (nr = 0; nr < v->nr_pages; nr++) {
+ if (!v->pages[nr])
+ break;
counters[page_to_nid(v->pages[nr])]++;
+ }

for_each_node_state(nr, N_HIGH_MEMORY)
if (counters[nr])

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/