Tarantool development patches archive
 help / color / mirror / Atom feed
From: sergeyb@tarantool.org
To: tarantool-patches@dev.tarantool.org
Cc: o.piskunov@tarantool.org
Subject: [Tarantool-patches] [PATCH 11/11][small] Add MAP_STACK to mmap() flags
Date: Tue, 12 May 2020 15:32:35 +0300	[thread overview]
Message-ID: <3c3f944e5982510f3ae32435606631cc55621408.1589285302.git.sergeyb@tarantool.org> (raw)
In-Reply-To: <cover.1589284160.git.sergeyb@tarantool.org>

From: Sergey Bronnikov <sergeyb@tarantool.org>

OpenBSD enabled enforcing that the user stack pointer pointed to a
region of memory that had been mapped as a stack, see [1] for the
details. The upshot of this is that when usermode software wants to
allocate a stack, the region it's going to use must be mapped with the
MAP_STACK flag; if not, entry to the kernel will trap this and generate
a signal to kill the process.

Part of [2]

[1] https://undeadly.org/cgi?action=article;sid=20180310000858
[2] https://github.com/tarantool/tarantool/issues/4967
---
 small/features.c   | 4 ++++
 small/slab_arena.c | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/small/features.c b/small/features.c
index 3adadae..bece95a 100644
--- a/small/features.c
+++ b/small/features.c
@@ -72,7 +72,11 @@ test_dontdump(void)
 	 * and work on it.
 	 */
 
+#if defined(__OpenBSD__)
+	ptr = mmap(NULL, size, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE | MAP_STACK, -1, 0);
+#else
 	ptr = mmap(NULL, size, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+#endif
 	if (ptr == MAP_FAILED) {
 		/*
 		 * We're out of memory, and cant guarantee anything.
diff --git a/small/slab_arena.c b/small/slab_arena.c
index 7661ef8..11b5364 100644
--- a/small/slab_arena.c
+++ b/small/slab_arena.c
@@ -95,6 +95,9 @@ mmap_checked(size_t size, size_t align, int flags)
 		flags = MAP_PRIVATE | MAP_ANONYMOUS;
 	else
 		flags = MAP_SHARED | MAP_ANONYMOUS;
+#if defined(__OpenBSD__)
+	flags |= MAP_STACK;
+#endif
 
 	/*
 	 * All mappings except the first are likely to
@@ -160,7 +163,11 @@ slab_arena_flags_init(struct slab_arena *arena, int flags)
 	 * map them to internal ones.
 	 */
 	if (!(flags & SLAB_ARENA_FLAG_MARK)) {
+#if defined(__OpenBSD__)
+		assert(flags & (MAP_PRIVATE | MAP_SHARED | MAP_STACK));
+#else
 		assert(flags & (MAP_PRIVATE | MAP_SHARED));
+#endif
 		if (flags == MAP_PRIVATE)
 			arena->flags = SLAB_ARENA_PRIVATE;
 		else
-- 
2.23.0

  parent reply	other threads:[~2020-05-12 12:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 12:32 [Tarantool-patches] [PATCH 00/11] Add OpenBSD support sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 01/11] build: introduce openbsd build target sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 02/11] build: test pthread_stackseg_np() on OpenBSD sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 03/11] build: skip linking with -ldl " sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 04/11] Fix building of tt_pthread_attr_getstack() " sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 05/11] sql: use mremap() " sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 06/11] Include libgen.h when building " sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 07/11] say: fix compilation " sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 08/11] test: mute broken tests " sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 09/11] Add README.OpenBSD sergeyb
2020-05-12 12:32 ` [Tarantool-patches] [PATCH 10/11] Mention OpenBSD as supported platorm sergeyb
2020-05-12 12:32 ` sergeyb [this message]
2020-05-18 18:22 ` [Tarantool-patches] [PATCH 00/11] Add OpenBSD support Cyrill Gorcunov
2020-05-20  6:41 ` Kirill Yukhin
2020-05-20 12:23   ` Sergey Bronnikov

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=3c3f944e5982510f3ae32435606631cc55621408.1589285302.git.sergeyb@tarantool.org \
    --to=sergeyb@tarantool.org \
    --cc=o.piskunov@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 11/11][small] Add MAP_STACK to mmap() flags' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox