From 4cd61e281dbdab118e1a1a4ec06dbaa12f5a9933 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 23 Oct 2018 19:07:41 -0400 Subject: [PATCH] add workaround for bug in Linux MPK implementation --- malloc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/malloc.c b/malloc.c index 4057dbb..4a03961 100644 --- a/malloc.c +++ b/malloc.c @@ -776,6 +776,14 @@ static void full_unlock(void) { static void post_fork_child(void) { thread_unseal_metadata(); + +#ifdef USE_PKEY + // disable sealing to work around kernel bug causing fork to lose the pkey setup + memory_protect_rw(&ro, sizeof(ro)); + ro.metadata_pkey = -1; + memory_protect_ro(&ro, sizeof(ro)); +#endif + mutex_init(&ro.region_allocator->lock); random_state_init(&ro.region_allocator->rng); for (unsigned class = 0; class < N_SIZE_CLASSES; class++) {