From: Mitsuo Hayasaka <mitsuo.hayasaka.hu@hitachi.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
yrl.pp-manager.tt@hitachi.com,
Mitsuo Hayasaka <mitsuo.hayasaka.hu@hitachi.com>,
Andrew Morton <akpm@linux-foundation.org>,
Namhyung Kim <namhyung@gmail.com>,
David Rientjes <rientjes@google.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Subject: [PATCH] avoid null pointer access in vm_struct
Date: Wed, 17 Aug 2011 22:28:48 +0900 [thread overview]
Message-ID: <20110817132848.2352.80544.stgit@ltc219.sdl.hitachi.co.jp> (raw)
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@hitachi.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: David Rientjes <rientjes@google.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
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, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2011-08-17 13:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-17 13:28 Mitsuo Hayasaka [this message]
2011-08-17 19:39 ` Andrew Morton
2011-08-18 9:21 ` HAYASAKA Mitsuo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110817132848.2352.80544.stgit@ltc219.sdl.hitachi.co.jp \
--to=mitsuo.hayasaka.hu@hitachi.com \
--cc=akpm@linux-foundation.org \
--cc=jeremy.fitzhardinge@citrix.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=namhyung@gmail.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=rientjes@google.com \
--cc=yrl.pp-manager.tt@hitachi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox