shim: always clear the reentrancy guard in rmdir - #6
Closed
davised wants to merge 2 commits into
Closed
Conversation
rmdir set in_shim on entry but cleared it only when the rmdir both succeeded and was journaled. After an ENOTEMPTY, or an rmdir of a path on the ignore list, the flag stayed set for the rest of the process: armed() returned false and every subsequent change went unrecorded while still happening on disk. A program that calls a failing rmdir() and then unlink() left an empty journal and an unrecoverable file. Callers going through unlinkat(AT_REMOVEDIR) were unaffected, which is why coreutils rm -rf never showed it. The inner in_shim assignments around jwrite are dropped as redundant -- the flag is already set at that point, and that redundancy is what disguised the missing reset. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Author
|
Closing — this turns out to be a duplicate. The same guard leak was fixed independently in 91aa609 ("Stop the shim silently going deaf mid-command"), released in v0.2.8, so the shim diff here is now empty against main. For what it is worth, I hit this from the other direction: a program calling a failing Thanks for the tool. |
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.
rmdir()sets the thread-localin_shimguard on entry but clears it only when thermdirboth succeeds and gets journaled:After an
ENOTEMPTY, or anrmdirof a path on the ignore list, the flag stays set for the rest of the process.armed()then returns false and the shim silently records nothing further — while the process carries on changing files.Repro. One compiled program, since
in_shimis thread-local andrmdir(1)/rm(1)are separate processes:With
v[1]a non-empty directory thermdirfails, and the followingunlinkis never journaled. The file is gone andundoreports "nothing to undo".Scope. Only reachable through the plain
rmdir()wrapper. Anything usingunlinkat(AT_REMOVEDIR)— coreutilsrm -rf, Python'sshutil.rmtree,git clean— is unaffected, becauseunlinkat()clears the guard correctly. That is why the headlinerm -rfpath never showed it. Directrmdir()callers (os.rmdir, C programs, some build tooling) are affected.The ignore-list variant is quieter: an
rmdirof a.gitornode_modulessubdirectory succeeds but setsok = 0, so the guard leaks with no error anywhere.Fix. Clear
in_shimunconditionally before returning. The inner assignments aroundjwriteare dropped as redundant — the flag is already set there, and that redundancy is what made the missing reset easy to miss.Test. Adds e2e case 21 per CONTRIBUTING; it fails on
mainand passes with the fix.make testgreen, shim's glibc floor unchanged atGLIBC_2.34.🤖 Generated with Claude Code