Fix potential UAF/double-free footgun #3
+10
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
MappedModuleclass currently unconditionally callsVirtualFreeon the module allocation when its destructor is called. This makes it fairly hard to use as the destructor will be called even if the object is moved.This PR replaces the manual allocation with a
std::unique_ptr<std::vector<std::byte>>. This makes the class safe to move.Unfortunately, I noticed that this change broke TLS callbacks in some of the BOFs I tested when proper section protection was applied. This showed up as attempts to write in a stack region that didn't exist (anymore?). This issue went away when I made the entire allocation RWX. Therefore I also made
UpdateSectionPermissionsapply RWX on the entire buffer. I did notice that the protection wasn't always correctly applied when a RW section followed a non RW-section (.data after .text for ex.). Fixing this wasn't enough to prevent the aforementioned crash, hence the RWX.