From 7f6667b5bc802d30c006207f2d0cc2d025e47d08 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 19 Mar 2024 10:36:53 -0400 Subject: [PATCH] mempool: Use MADV_DONTFORK on init values The init values shared mapping should not be shared across fork. Use madvise MADV_DONTFORK on the memory range to ensure those pages are not shared with children processes across fork. Signed-off-by: Mathieu Desnoyers Change-Id: I4b3541d21401227ca568ef6e8105d088746341cb --- src/rseq-mempool.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rseq-mempool.c b/src/rseq-mempool.c index 1d87e1a..fa1cff0 100644 --- a/src/rseq-mempool.c +++ b/src/rseq-mempool.c @@ -748,6 +748,12 @@ struct rseq_mempool_range *rseq_mempool_range_create(struct rseq_mempool *pool) MAP_SHARED | MAP_FIXED, memfd, 0) != (void *) range->init) { goto error_alloc; } + /* + * Make sure the init values shared mapping is not + * shared with the children processes across fork. + */ + if (madvise(range->init, pool->attr.stride, MADV_DONTFORK)) + goto error_alloc; assert(pool->attr.type == MEMPOOL_TYPE_PERCPU); /* * Map per-cpu memory as private COW mappings of init values. -- 2.34.1