From eeff3f3a2a43eda2d5622724fe930fb2d79af67d Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Tue, 25 Feb 2025 14:44:10 -0800 Subject: [PATCH] #Centipede Protect the shared mmap-ed buffers from forked processes. This is a short-term solution that only works for Linux. PiperOrigin-RevId: 731036490 --- centipede/shared_memory_blob_sequence.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/centipede/shared_memory_blob_sequence.cc b/centipede/shared_memory_blob_sequence.cc index a60ad856..56108e6c 100644 --- a/centipede/shared_memory_blob_sequence.cc +++ b/centipede/shared_memory_blob_sequence.cc @@ -147,6 +147,11 @@ void SharedMemoryBlobSequence::MmapData() { data_ = static_cast( mmap(nullptr, size_, PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0)); ErrorOnFailure(data_ == MAP_FAILED, "mmap() failed"); +#ifndef __APPLE__ + // TODO: b/385774476 - this is a temporary and Linux-only solution to protect + // the mmap-ed region from forked processes. + ErrorOnFailure(madvise(data_, size_, MADV_DONTFORK), "madvise() failed"); +#endif } SharedMemoryBlobSequence::~SharedMemoryBlobSequence() {