Skip to content

Commit ab9ddc8

Browse files
bharathsm-mssmfrench
authored andcommitted
SMB3: Add missing locks to protect deferred close file list
cifs_del_deferred_close function has a critical section which modifies the deferred close file list. We must acquire deferred_lock before calling cifs_del_deferred_close function. Fixes: ca08d0e ("cifs: Fix memory leak on the deferred close") Signed-off-by: Bharath SM <[email protected]> Acked-off-by: Paulo Alcantara (SUSE) <[email protected]> Acked-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 919e57c commit ab9ddc8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/cifs/misc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)
749749
list_for_each_entry(cfile, &cifs_inode->openFileList, flist) {
750750
if (delayed_work_pending(&cfile->deferred)) {
751751
if (cancel_delayed_work(&cfile->deferred)) {
752+
spin_lock(&cifs_inode->deferred_lock);
752753
cifs_del_deferred_close(cfile);
754+
spin_unlock(&cifs_inode->deferred_lock);
753755

754756
tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
755757
if (tmp_list == NULL)
@@ -780,7 +782,9 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)
780782
list_for_each_entry(cfile, &tcon->openFileList, tlist) {
781783
if (delayed_work_pending(&cfile->deferred)) {
782784
if (cancel_delayed_work(&cfile->deferred)) {
785+
spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
783786
cifs_del_deferred_close(cfile);
787+
spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
784788

785789
tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
786790
if (tmp_list == NULL)
@@ -815,7 +819,9 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)
815819
if (strstr(full_path, path)) {
816820
if (delayed_work_pending(&cfile->deferred)) {
817821
if (cancel_delayed_work(&cfile->deferred)) {
822+
spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
818823
cifs_del_deferred_close(cfile);
824+
spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
819825

820826
tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC);
821827
if (tmp_list == NULL)

0 commit comments

Comments
 (0)