Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session::recreate_shared_mmap fixes #3863

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/Session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,22 @@ const AddressSpace::Mapping Session::recreate_shared_mmap(
uint32_t flags = m.flags;
size_t size = m.map.size();
void* preserved_data = preserve == PRESERVE_CONTENTS ? m.local_addr : nullptr;
if (preserved_data) {
remote.task()->vm()->detach_local_mapping(m.map.start());
void* remote_task_local_mapping = nullptr;

{
// Note that Mapping `m` may correspond to a Mapping from a different Task
// than the `maybe_detach_mapping`. See replay_syscall.cc prepare_clone()
// for an example.
auto remote_task_mapping = remote.task()->vm()->mapping_of(m.map.start());

// Sanity check
ASSERT(remote.task(), size == remote_task_mapping.map.size());
ASSERT(remote.task(), m.map.start() == remote_task_mapping.map.start());

remote_task_local_mapping =
remote.task()->vm()->detach_local_mapping(m.map.start());
}

remote_ptr<void> new_addr =
create_shared_mmap(remote, m.map.size(), m.map.start(),
extract_name(name, sizeof(name)), m.map.prot(), 0,
Expand All @@ -575,9 +588,11 @@ const AddressSpace::Mapping Session::recreate_shared_mmap(
new_map = remote.task()->vm()->mapping_of(new_addr);
if (preserved_data) {
memcpy(new_map.local_addr, preserved_data, size);
munmap(preserved_data, size);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This here is very problematic as it could unmap the local memory for the wrong task. We want to unmap for remote.task()Mapping's local_addr and not for Mapping m's local_addr

}
if (remote_task_local_mapping) {
munmap(remote_task_local_mapping, size);
}
return new_map;
}

Expand Down
Loading