fix(gc): swap enumeration order in gc mark phase to avoid TOCTOU bug#248
Open
GrizzlT wants to merge 1 commit into
Open
fix(gc): swap enumeration order in gc mark phase to avoid TOCTOU bug#248GrizzlT wants to merge 1 commit into
GrizzlT wants to merge 1 commit into
Conversation
Checking temp tags before named tags ensures that the blobs added and tagged through `AddProgress::with_named_tag()` cannot be deleted accidentally.
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.
Description
Currently, it is possible for the gc to accidentally delete blobs that were tagged using something like:
This can happen due to a TOCTOU bug in the mark phase of the gc (see #247). Because named tags are enumerated before temp tags in a check for blob liveness, it is possible to queue the following order of irpc messages:
The gc is completely blind to the tag added in this sequence of messages. The elegant fix is to swap the order of enumeration into the following:
Now, regardless of whether the temp tag is seen by the gc or not, the named tag is guaranteed to be seen by the gc and thus it becomes impossible to accidentally delete blobs as explained in the original problem statement.
Fixes #247.
Breaking Changes
Notes & open questions
Does it make sense to try and write a unit test for this bug to prevent it from returning in the future? Or does it suffice to add internal documentation to the code?
Change checklist