Skip to content

Commit efacb45

Browse files
avagingvisor-bot
authored andcommitted
fsgofer: update lastUnlockedDentry only after unlocking the dentry
Update lastUnlockedDentry only after the mutex has been unlocked. If doRevalidationLisafs panics, deferred functions are executed. Updating lastUnlockedDentry earlier could lead to a deferred function attempting to acquire an already locked mutex, resulting in a deadlock. PiperOrigin-RevId: 810075556
1 parent 6448dbe commit efacb45

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

pkg/sentry/fsimpl/gofer/lisafs_inode.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,11 @@ func doRevalidationLisafs(ctx context.Context, vfsObj *vfs.VirtualFilesystem, st
704704
for i := 0; i < len(state.dentries); i++ {
705705
d := state.dentries[i]
706706
found := i < len(stats)
707-
// Advance lastUnlockedDentry. It is the responsibility of this for loop
708-
// block to unlock i.metadataMu.
709-
lastUnlockedDentry = i
710707

711708
// Note that synthetic dentries will always fail this comparison check.
712709
if !found || d.inode.inoKey != inoKeyFromStatx(&stats[i]) {
713710
d.inode.metadataMu.Unlock()
711+
lastUnlockedDentry = i
714712
if !found && d.inode.isSynthetic() {
715713
// We have a synthetic file, and no remote file has arisen to replace
716714
// it.
@@ -732,6 +730,7 @@ func doRevalidationLisafs(ctx context.Context, vfsObj *vfs.VirtualFilesystem, st
732730
// The file at this path hasn't changed. Just update cached metadata.
733731
d.inode.impl.(*lisafsInode).updateMetadataFromStatxLocked(&stats[i]) // +checklocksforce: see above.
734732
d.inode.metadataMu.Unlock()
733+
lastUnlockedDentry = i
735734
}
736735
return nil
737736
}

0 commit comments

Comments
 (0)