Skip to content

Commit 9351590

Browse files
ematsumiyasmfrench
authored andcommitted
cifs: properly invalidate cached root handle when closing it
Cached root file was not being completely invalidated sometimes. Reproducing: - With a DFS share with 2 targets, one disabled and one enabled - start some I/O on the mount # while true; do ls /mnt/dfs; done - at the same time, disable the enabled target and enable the disabled one - wait for DFS cache to expire - on reconnect, the previous cached root handle should be invalid, but open_cached_dir_by_dentry() will still try to use it, but throws a use-after-free warning (kref_get()) Make smb2_close_cached_fid() invalidate all fields every time, but only send an SMB2_close() when the entry is still valid. Signed-off-by: Enzo Matsumiya <[email protected]> Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 8d014f5 commit 9351590

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

fs/cifs/smb2ops.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -689,13 +689,19 @@ smb2_close_cached_fid(struct kref *ref)
689689
cifs_dbg(FYI, "clear cached root file handle\n");
690690
SMB2_close(0, cfid->tcon, cfid->fid->persistent_fid,
691691
cfid->fid->volatile_fid);
692-
cfid->is_valid = false;
693-
cfid->file_all_info_is_valid = false;
694-
cfid->has_lease = false;
695-
if (cfid->dentry) {
696-
dput(cfid->dentry);
697-
cfid->dentry = NULL;
698-
}
692+
}
693+
694+
/*
695+
* We only check validity above to send SMB2_close,
696+
* but we still need to invalidate these entries
697+
* when this function is called
698+
*/
699+
cfid->is_valid = false;
700+
cfid->file_all_info_is_valid = false;
701+
cfid->has_lease = false;
702+
if (cfid->dentry) {
703+
dput(cfid->dentry);
704+
cfid->dentry = NULL;
699705
}
700706
}
701707

0 commit comments

Comments
 (0)