Repository navigation
Conversation
the problem: the prophylactic `refcount++` was taken per handle, but DF frees per slot-occupancy. Anything that put the surface into raws an extra time (re-registration during the deferred-clear window, delayed-registration overlap) let DF's decrements outnumber our increments, allowing a surface to be freed while `g_handle_to_surface` still cached it, which lead to a UAF in `deleteHandle` this code avoids this by ensuring refcounts are incremented before DF can possibly free them, validates that the texture in a slot to be freed is actually what it is supposed to be before freeing it or returning it to a caller, and avoids using `operator[]` on a map (which can insert undesired phantom keys) FIxes DFHack#6045
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 problem: the prophylactic
refcount++was taken per handle, but DF frees per slot-occupancy. Anything that put the surface into raws an extra time (re-registration during the deferred-clear window, delayed-registration overlap) let DF's decrements outnumber our increments, allowing a surface to be freed whileg_handle_to_surfacestill cached it, which lead to a UAF indeleteHandlethis code avoids this by ensuring refcounts are incremented before DF can possibly free them, validates that the texture in a slot to be freed is actually what it is supposed to be before freeing it or returning it to a caller, and avoids using
operator[]on a map (which can insert undesired phantom keys)FIxes #6045
As a note: this code has always had a slight risk of a race with DF's render thread - this code is called from the simulation thread and the render thread is consuming this data asynchronously so it's possible for this to cause the render thread to do something weird. However, this PR doesn't change this risk and no adverse effect has ever been observed. But we might need to revisit this if Bay12 ever makes significant changes to the renderer.