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

From: Ingo Molnar (mingo_at_elte.hu)
Date: 01/31/05

  • Next message: Olaf Hering: "Re: [2.6 patch] drivers/char/tty_io.c: remove console_use_vt"
    Date:	Mon, 31 Jan 2005 20:06:04 +0100
    To: Andrew Morton <akpm@osdl.org>
    
    

    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@elte.hu>

    --- 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@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Olaf Hering: "Re: [2.6 patch] drivers/char/tty_io.c: remove console_use_vt"

    Relevant Pages

    • Re: [announce] [patch] NX (No eXecute) support for x86, 2.6.7-rc2-bk2
      ... I don't know if Fedora does that ... I don't think it makes any sense to have separate bits for heap and stack. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [announce] [patch] NX (No eXecute) support for x86, 2.6.7-rc2-bk2
      ... > I don't think it makes any sense to have separate bits for heap and stack. ... heap execution seems to be a lot more common than stack execution. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • why one stack per thread and one heap for all the threads?
      ... why in multithreading, each thread has its own stack, but all share the same ... I understand that one stack is needed for each thread as each could have its ... but why we don't associate a heap for each thread since ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [PROPOSAL/PATCH] Remove PT_GNU_STACK support before 2.6.11
      ... > about something else than the stack, from a security POV if the stack is ... The heap and all mmaps being ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: How does managed code work?
      ... Does it work the same way as the native stack with a frame pointer that is the head of a linked list of stack frames where each time we enter a function we create a new stack frame in which new variables are pushed and each time we exit a function the entire stack frame is popped? ... Can someone point me to a discussion of the managed heap? ... How does it prevent memory leaks that occur in COM when two objects reference each other and keep the others reference count nonzero? ... Because objects don't go out of scope, ...
      (microsoft.public.dotnet.languages.csharp)