From: Jamie Lokier <jamie@shareable.org>
To: Siddhesh Poyarekar <siddhesh.poyarekar@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org,
Michael Kerrisk <mtk.manpages@gmail.com>,
linux-man@vger.kernel.org
Subject: Re: [PATCH] Mark thread stack correctly in proc/<pid>/maps
Date: Mon, 16 Jan 2012 11:28:02 +0000 [thread overview]
Message-ID: <20120116112802.GB7180@jl-vm1.vm.bytemark.co.uk> (raw)
In-Reply-To: <1326544511-6547-1-git-send-email-siddhesh.poyarekar@gmail.com>
Siddhesh Poyarekar wrote:
> Memory mmaped by glibc for a thread stack currently shows up as a simple
> anonymous map, which makes it difficult to differentiate between memory
> usage of the thread on stack and other dynamic allocation. Since glibc
> already uses MAP_STACK to request this mapping, the attached patch
> uses this flag to add additional VM_STACK_FLAGS to the resulting vma
> so that the mapping is treated as a stack and not any regular
> anonymous mapping. Also, one may use vm_flags to decide if a vma is a
> stack.
I think this is fine.
> There is an additional complication with posix threads where the stack
> guard for a thread stack may be larger than a page, unlike the case
> for process stack where the stack guard is a page long. glibc
> implements these guards by calling mprotect on the beginning page(s)
> to remove all permissions. I have used this to remove vmas that have
> the thread stack guard, from the /proc/maps output.
> - /* We don't show the stack guard page in /proc/maps */
> + /* We don't show the stack guard pages in /proc/maps */
> + if (thread_stack_guard(vma))
> + return;
> +
> start = vma->vm_start;
> if (stack_guard_page_start(vma, start))
> start += PAGE_SIZE;
Hmm, I see why you did this. The current code already hides one guard
page, which is already dubious for programs that do things like read
/proc/pid/maps to decide if MAP_FIXED would be not clobber an existing
mapping. At least those programs _could_ know about the stack guard
page address
I wonder if it's a potential security hole: You've just allowed
programs to use two MAP_GROWSUP/DOWN|PROT_NONE to hide vmas from the
user. Sure, the memory isn't accessible, but it can still store data
and be ephemerally made visible using mprotect() then hidden again.
I would prefer a label like "[stack guard]" or just "[guard]",
both for the thread stacks and the process stack.
With a label like "[guard]" it needn't be limited to stacks; heap
guard pages used by some programs would also be labelled.
> +static inline int vma_is_stack(struct vm_area_struct *vma)
> +{
> + return vma && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN));
> +}
> +
> +/*
> + * POSIX thread stack guards may be more than a page long and access to it
> + * should return an error (possibly a SIGSEGV). The glibc implementation does
> + * an mprotect(..., ..., PROT_NONE), so our guard vma has no permissions.
> + */
> +static inline int thread_stack_guard(struct vm_area_struct *vma)
Is there a reason the names aren't consistent - i.e. not vma_is_stack_guard()?
> +{
> + return vma_is_stack(vma) &&
> + ((vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC | VM_MAYSHARE)) == 0) &&
> + vma_is_stack((vma->vm_flags & VM_GROWSDOWN)?vma->vm_next:vma->vm_prev);
> +}
> +
That doesn't check if ->vm_next/prev is adjacent in address space.
You can't assume the program is using Glibc, or that MAP_STACK
mappings are all from Glibc, or that they are in the pattern you expect.
How about simply calling it vma_is_guard(), return 1 if it's PROT_NONE
without checking vma_is_stack() or ->vm_next/prev, and annotate the
maps output like this:
is_stack => "[stack]"
is_guard & is_stack => "[stack guard]"
is_guard & !is_stack => "[guard]"
What do you think?
-- Jamie
--
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 prev parent reply other threads:[~2012-01-16 11:28 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-14 12:35 Siddhesh Poyarekar
2012-01-16 11:28 ` Jamie Lokier [this message]
2012-01-16 13:08 ` Siddhesh Poyarekar
2012-01-16 16:31 ` Jamie Lokier
2012-01-16 17:01 ` Siddhesh Poyarekar
2012-01-17 4:54 ` Siddhesh Poyarekar
2012-02-02 6:24 ` [RESEND][PATCH] " Siddhesh Poyarekar
2012-02-02 21:40 ` KOSAKI Motohiro
2012-02-03 7:09 ` Siddhesh Poyarekar
2012-02-03 8:01 ` KOSAKI Motohiro
2012-02-03 9:49 ` Siddhesh Poyarekar
2012-02-03 10:29 ` Mike Frysinger
2012-02-03 18:34 ` Siddhesh Poyarekar
2012-02-08 4:00 ` Siddhesh Poyarekar
2012-02-08 17:57 ` KOSAKI Motohiro
2012-02-11 10:19 ` Siddhesh Poyarekar
2012-02-11 15:03 ` [PATCH] " Siddhesh Poyarekar
2012-02-21 4:24 ` [RESEND][PATCH] " Siddhesh Poyarekar
2012-02-22 23:00 ` Andrew Morton
2012-02-23 4:03 ` [PATCH] " Siddhesh Poyarekar
2012-02-23 20:22 ` Andrew Morton
2012-02-24 13:05 ` Siddhesh Poyarekar
2012-02-23 23:47 ` Mike Frysinger
2012-02-24 5:47 ` Siddhesh Poyarekar
2012-02-24 16:12 ` Mike Frysinger
2012-02-24 18:23 ` Siddhesh Poyarekar
2012-02-23 23:17 ` KOSAKI Motohiro
2012-02-24 0:49 ` KOSAKI Motohiro
2012-02-24 5:29 ` Siddhesh Poyarekar
2012-02-24 16:14 ` KOSAKI Motohiro
2012-02-24 18:58 ` Siddhesh Poyarekar
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=20120116112802.GB7180@jl-vm1.vm.bytemark.co.uk \
--to=jamie@shareable.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mtk.manpages@gmail.com \
--cc=siddhesh.poyarekar@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/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