mempool: Use MADV_DONTFORK on init values
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Mar 2024 14:36:53 +0000 (10:36 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Mar 2024 14:36:53 +0000 (10:36 -0400)
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 <mathieu.desnoyers@efficios.com>
Change-Id: I4b3541d21401227ca568ef6e8105d088746341cb

src/rseq-mempool.c

index 1d87e1a254de812a59852e6e03fdecf5c02f386a..fa1cff0c73b79bb1030d47207c143fe3d4cd5413 100644 (file)
@@ -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.
This page took 0.037216 seconds and 4 git commands to generate.