From: Andrew Morton <akpm@linux-foundation.org>
To: Waiman Long <longman@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Joe Mario <jmario@redhat.com>, Barry Marson <bmarson@redhat.com>,
Rafael Aquini <aquini@redhat.com>
Subject: Re: [PATCH] mm/mmap: Map MAP_STACK to VM_STACK
Date: Tue, 18 Apr 2023 14:18:52 -0700 [thread overview]
Message-ID: <20230418141852.75e551e57e97f4b522957c5c@linux-foundation.org> (raw)
In-Reply-To: <20230418210230.3495922-1-longman@redhat.com>
On Tue, 18 Apr 2023 17:02:30 -0400 Waiman Long <longman@redhat.com> wrote:
> One of the flags of mmap(2) is MAP_STACK to request a memory segment
> suitable for a process or thread stack. The kernel currently ignores
> this flags. Glibc uses MAP_STACK when mmapping a thread stack. However,
> selinux has an execstack check in selinux_file_mprotect() which disallows
> a stack VMA to be made executable.
>
> Since MAP_STACK is a noop, it is possible for a stack VMA to be merged
> with an adjacent anonymous VMA. With that merging, using mprotect(2)
> to change a part of the merged anonymous VMA to make it executable may
> fail. This can lead to sporadic failure of applications that need to
> make those changes.
"Sporadic failure of applications" sounds quite serious. Can you
provide more details?
Did you consider a -stable backport? I'm unable to judge, because the
description of the userspace effects is so thin,
> One possible fix is to make sure that a stack VMA will not be merged
> with a non-stack anonymous VMA. That requires a vm flag that can be
> used to distinguish a stack VMA from a regular anonymous VMA. One
> can add a new dummy vm flag for that purpose. However, there is only
> 1 bit left in the lower 32 bits of vm_flags. Another alternative is
> to use an existing vm flag. VM_STACK (= VM_GROWSDOWN for most arches)
> can certainly be used for this purpose. The downside is that it is a
> slight change in existing behavior.
>
> Making a stack VMA growable by default certainly fits the need of a
> process or thread stack. This patch now maps MAP_STACK to VM_STACK to
> prevent unwanted merging with adjacent non-stack VMAs and make the VMA
> more suitable for being used as a stack.
>
> ...
>
> --- a/include/linux/mman.h
> +++ b/include/linux/mman.h
> @@ -152,6 +152,7 @@ calc_vm_flag_bits(unsigned long flags)
> return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) |
> _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ) |
> _calc_vm_trans(flags, MAP_SYNC, VM_SYNC ) |
> + _calc_vm_trans(flags, MAP_STACK, VM_STACK ) |
> arch_calc_vm_flag_bits(flags);
> }
The mmap(2) manpage says
This flag is currently a no-op on Linux. However, by employing
this flag, applications can ensure that they transparently ob- tain
support if the flag is implemented in the future. Thus, it is used
in the glibc threading implementation to allow for the fact that some
architectures may (later) require special treat- ment for stack
allocations. A further reason to employ this flag is portability:
MAP_STACK exists (and has an effect) on some other systems (e.g.,
some of the BSDs).
so please propose an update for this?
next prev parent reply other threads:[~2023-04-18 21:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-18 21:02 Waiman Long
2023-04-18 21:18 ` Andrew Morton [this message]
2023-04-19 1:16 ` Waiman Long
2023-04-19 1:36 ` Hugh Dickins
2023-04-19 1:45 ` Waiman Long
2023-04-19 3:24 ` Matthew Wilcox
2023-04-19 14:38 ` Paul Moore
2023-04-19 3:46 ` Matthew Wilcox
2023-04-19 15:07 ` Waiman Long
2023-04-19 15:09 ` Matthew Wilcox
2023-04-19 16:00 ` Joe Mario
2023-04-19 23:21 ` Jane Chu
2023-04-20 0:00 ` Jane Chu
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=20230418141852.75e551e57e97f4b522957c5c@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aquini@redhat.com \
--cc=bmarson@redhat.com \
--cc=jmario@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.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