fix: serialise BuildInplaceOnly tarball extraction to prevent TOCTOU race#269
Open
angerman wants to merge 1 commit intowip/andrea/add-executable-extensionfrom
Open
fix: serialise BuildInplaceOnly tarball extraction to prevent TOCTOU race#269angerman wants to merge 1 commit intowip/andrea/add-executable-extensionfrom
angerman wants to merge 1 commit intowip/andrea/add-executable-extensionfrom
Conversation
2 tasks
…race When two stages of the same package (e.g. build: and host: in cross- compilation) are scheduled concurrently, both threads can observe the unpacked source directory as non-existent and race to extract the tarball. The second extraction overwrites the first mid-flight, corrupting the result and causing intermittent "No cabal file found" errors. Add an unpackLock (using the existing Lock/criticalSection from JobControl) to serialise the doesDirectoryExist check and tarball extraction in the BuildInplaceOnly path of withTarballLocalDirectory. This is the same pattern already used for registerLock and cacheLock.
39c39f7 to
254388a
Compare
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.
Summary
unpackLockto serialise thedoesDirectoryExistcheck andunpackPackageTarballcall in theBuildInplaceOnlypath ofwithTarballLocalDirectorybuild:andhost:in cross-compilation) are scheduled concurrentlyLock/criticalSectionpattern fromJobControl, matchingregisterLockandcacheLockRoot Cause
In cross-compilation builds, cabal-install creates two independent graph nodes for each package:
WithStage Build <unitid>andWithStage Host <unitid>. Both are scheduled concurrently byInstallPlan.execute. When both stages haveBuildInplaceOnlybuild style, they callwithTarballLocalDirectorywhich:distUnpackedSrcDirectory pkgidexists (keyed only byPackageId, not stage)This manifests as intermittent "No cabal file found" errors (observed on FreeBSD CI for
os-string-2.0.8).Fix
Wrap the check-and-extract block in
criticalSection unpackLockso only one thread performs the extraction while the other waits and finds the directory already present.Test plan