Skip to content

Fix locking and a double free in fsops rename and unlink - #615

Open
matejk wants to merge 4 commits into
LinearTapeFileSystem:release/v2.4.9.2from
matejk:fix/fsops-locking
Open

matejk wants to merge 4 commits into
LinearTapeFileSystem:release/v2.4.9.2from
matejk:fix/fsops-locking

Conversation

@matejk

@matejk matejk commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Two commits:

  • Releases of unheld meta_lock: in ltfs_fsops_rename, the directory WORM checks ran before todir's meta_lock was acquired but their error path released it (whenever todir != fromdir); ltfs_fsops_unlink had the same defect for parent->meta_lock on its WORM and non-empty-directory error paths. Releasing an unheld rwlock is undefined behaviour and can corrupt the lock state. The checks now run with the locks held; lock ordering is preserved.
  • Double free on a late rename failure: after the destination name buffers were assigned to fromdentry, a later failure freed them via out_free and left dangling pointers that were freed again when the dentry is disposed. Ownership is now cleared from the locals when it moves.

@vandelvan
vandelvan requested review from XV02, madjesc and syaoraang June 12, 2026 20:55
@matejk
matejk force-pushed the fix/fsops-locking branch from 9372f75 to bbdf041 Compare June 17, 2026 20:35
@matejk
matejk force-pushed the fix/fsops-locking branch from bbdf041 to 5ba5fc5 Compare August 17, 2026 20:10
@matejk
matejk changed the base branch from main to release/v2.4.9.0 August 17, 2026 20:10
@matejk
matejk changed the base branch from release/v2.4.9.0 to main August 17, 2026 20:11
@matejk
matejk force-pushed the fix/fsops-locking branch 3 times, most recently from 51ae222 to 3800dcb Compare August 17, 2026 20:28

@XV02 XV02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a complex change, will keep reviewing, for the time being please check this concern, if you find it wrong please discuss it on this thread :DD

Comment thread src/libltfs/ltfs_fsops.c Resolved
@matejk
matejk requested a review from XV02 August 19, 2026 10:10

@XV02 XV02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my comment, GTG!

@matejk

matejk commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main after the 2.4.9.1 release and added one commit. The WORM check that this PR moved below the lookups released only one reference when both names of a rename resolve to the same entry (Unicode-equivalent names in one directory), so the entry was never disposed. The exit now releases both, as the validation block above it does. LeakSanitizer reports the leaked entry before the change and nothing after it.

@syaoraang syaoraang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, thanks!

@rangelmx

Copy link
Copy Markdown
Contributor

Hi @matejk ! We agreed that this change can be merged into our next release, 2.4.9.2. Since for the previous release process some PRs got squashed, git might be marking some changes incorrectly in this PR when we switched the base branch, if this happened please merge your branch with the release/2.4.9.2 and please confirm there are no conflicts so we can merge it with the new release branch. Thank you for your contribution!

@Piloalucard Piloalucard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this work! LGTM!

@matejk
matejk force-pushed the fix/fsops-locking branch from f97265d to 2eb7281 Compare December 2, 2026 12:02
The WORM and non-empty-directory checks ran before the lock was taken but
their error paths released it. Take it first; lock order is unchanged.
After ownership moves to fromdentry, out_free freed the buffers again.
…in unlink

The check needs only the child's contents_lock, so parent->meta_lock is no
longer held while it is taken.
@matejk
matejk force-pushed the fix/fsops-locking branch from 2eb7281 to ad94699 Compare December 2, 2026 12:05
@matejk
matejk changed the base branch from main to release/v2.4.9.2 December 2, 2026 12:05
@matejk

matejk commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on release/v2.4.9.2 (00eb612). There were no conflicts, and the four commits are unchanged. The build and the integration tests from #611 (merged on top for the test run) pass. The base branch of this PR is now release/v2.4.9.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants