-
Notifications
You must be signed in to change notification settings - Fork 105
Fix locking and a double free in fsops rename and unlink #615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matejk
wants to merge
3
commits into
LinearTapeFileSystem:main
Choose a base branch
from
matejk:fix/fsops-locking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving acquirewrite_mrsw(&parent->meta_lock) above the WORM and non-empty-dir checks fixes the original "release of unheld lock" bug, but creates a lock-order inversion with the non-empty-dir check. Every other site in this file (and the rest of the codebase) acquires contents_lock before meta_lock on the same node, and parent locks before child locks. Here the order is reversed: parent meta_lock is held when a child's contents_lock is taken. Any concurrent thread that holds d->contents_lock (e.g. a readdir) and then tries to acquire parent->meta_lock will deadlock with this path.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is an inversion, but I have reordered the code so the pairing no longer occurs.
The documented order (
struct dentry,ltfs.h:279) is: "contents_lock, meta_lock ... take all parent locks before any dentry locks." Parent contents -> parent meta -> child contents -> child meta is that rule, and it is the orderfs_path_lookupitself uses (fs.c:627-640). A deadlock would need the inverse pair - a childcontents_lockheld while taking the parent'smeta_lock- and no site in the tree does that;readdirtakesd->contents_lock, releases it, thend->meta_lock, and never touches the parent'smeta_lock.Still, the non-empty check only needs the child's
contents_lock, so it now runs beforeparent->meta_lockis taken (new commit).parent->meta_lockis held only for the WORM checks and the unlink, never whiled->contents_lockis acquired.The original defect: the WORM and non-empty error paths went to
out->fs_release_dentry_unlocked(parent)->releasewrite_mrsw(&parent->meta_lock), but the lock was only acquired later (old line 485), so they released a lock never held. The WORM flags are alsometa_lock-protected (ltfs.h; written underd->meta_lockinxattr.c), so reading them without it was a second defect.