[patch] annotate /proc/<PID>/maps with [heap]/[stack]/[vdso] markers

From: Ingo Molnar
Date: Mon Jan 31 2005 - 14:11:34 EST



This patch makes the /proc/<PID>/maps file easier to parse (both for
humans and for applications), by annotating the heap, stack and vdso
mappings with [heap], [stack] and [vdso] markers.

It makes it easier/faster to determine at a quick glance whether an
application has a secure VM layout, and it also makes it easier for
tools to determine whether e.g. the heap or stack is executable or not.

new maps file, on a patched kernel:

001c4000-001d9000 r-xp 00000000 03:01 19954 /lib/ld-2.3.3.so
001d9000-001db000 rw-p 00014000 03:01 19954 /lib/ld-2.3.3.so
001dd000-002fb000 r-xp 00000000 03:01 19960 /lib/tls/libc-2.3.3.so
002fb000-002fd000 r--p 0011d000 03:01 19960 /lib/tls/libc-2.3.3.so
002fd000-002ff000 rw-p 0011f000 03:01 19960 /lib/tls/libc-2.3.3.so
002ff000-00301000 rw-p 002ff000 00:00 0
08048000-0804c000 r-xp 00000000 03:01 31968 /bin/cat
0804c000-0804d000 rw-p 00003000 03:01 31968 /bin/cat
0804d000-0806e000 rw-p 0804d000 00:00 0 [heap]
b7dbc000-b7dbd000 r--p 009d1000 03:01 83628 /usr/lib/locale/locale-archive
b7dbd000-b7dc4000 r--p 0097d000 03:01 83628 /usr/lib/locale/locale-archive
b7dc4000-b7df1000 r--p 0094a000 03:01 83628 /usr/lib/locale/locale-archive
b7df1000-b7ff1000 r--p 00000000 03:01 83628 /usr/lib/locale/locale-archive
b7ff1000-b7ff2000 rw-p b7ff1000 00:00 0
bffeb000-c0000000 rw-p bffeb000 00:00 0 [stack]
ffffe000-fffff000 ---p 00000000 00:00 0 [vdso]

Tested on x86, but should work on all architectures.

Signed-off-by: Ingo Molnar <mingo@xxxxxxx>

--- fs/proc/task_mmu.c.orig
+++ fs/proc/task_mmu.c
@@ -77,9 +77,18 @@ out:
return result;
}

+static void pad_len_spaces(struct seq_file *m, int len)
+{
+ len = 25 + sizeof(void*) * 6 - len;
+ if (len < 1)
+ len = 1;
+ seq_printf(m, "%*c", len, ' ');
+}
+
static int show_map(struct seq_file *m, void *v)
{
struct vm_area_struct *map = v;
+ struct mm_struct *mm = map->vm_mm;
struct file *file = map->vm_file;
int flags = map->vm_flags;
unsigned long ino = 0;
@@ -102,12 +117,31 @@ static int show_map(struct seq_file *m,
map->vm_pgoff << PAGE_SHIFT,
MAJOR(dev), MINOR(dev), ino, &len);

+ /*
+ * Print the dentry name for named mappings, and a
+ * special [heap] marker for the heap:
+ */
if (map->vm_file) {
- len = 25 + sizeof(void*) * 6 - len;
- if (len < 1)
- len = 1;
- seq_printf(m, "%*c", len, ' ');
+ pad_len_spaces(m, len);
seq_path(m, file->f_vfsmnt, file->f_dentry, "");
+ } else {
+ if (mm) {
+ if (map->vm_start <= mm->start_brk &&
+ map->vm_end >= mm->brk) {
+ pad_len_spaces(m, len);
+ seq_puts(m, "[heap]");
+ } else {
+ if (map->vm_start <= mm->start_stack &&
+ map->vm_end >= mm->start_stack) {
+
+ pad_len_spaces(m, len);
+ seq_puts(m, "[stack]");
+ }
+ }
+ } else {
+ pad_len_spaces(m, len);
+ seq_puts(m, "[vdso]");
+ }
}
seq_putc(m, '\n');
return 0;

-
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/