From 00a478ca80fb3cd40bbea4f06f011c58b18c6d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Crelier?= Date: Thu, 14 Mar 2019 20:47:14 +0000 Subject: [PATCH] [VM runtime] Do not leak file descriptors of dual mappings to child processes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This applies to linux only and is a suggested precaution. Change-Id: I81cc345eb2c316530de1fd779cdf392804a68490 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96982 Reviewed-by: Ryan Macnak Commit-Queue: Régis Crelier --- runtime/vm/virtual_memory_posix.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/vm/virtual_memory_posix.cc b/runtime/vm/virtual_memory_posix.cc index 985d5b66b00..5751e7f13f8 100644 --- a/runtime/vm/virtual_memory_posix.cc +++ b/runtime/vm/virtual_memory_posix.cc @@ -83,6 +83,11 @@ static void unmap(uword start, uword end) { } #if defined(DUAL_MAPPING_SUPPORTED) +// Do not leak file descriptors to child processes. +#if !defined(MFD_CLOEXEC) +#define MFD_CLOEXEC 0x0001U +#endif + // Wrapper to call memfd_create syscall. static inline int memfd_create(const char* name, unsigned int flags) { #if !defined(__NR_memfd_create) @@ -143,7 +148,7 @@ VirtualMemory* VirtualMemory::AllocateAligned(intptr_t size, const bool dual_mapping = is_executable && FLAG_write_protect_code && FLAG_dual_map_code; if (dual_mapping) { - fd = memfd_create("dart_vm", 0); + fd = memfd_create("dart_vm", MFD_CLOEXEC); if (fd == -1) { return NULL; }