SMB3: Add missing locks to protect deferred close file list
Subsystems (2)
PATCH 1/1 SMB3: Add missing locks to protect deferred close file list
From: Bharath SM <[email protected]>
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.
--- fs/cifs/misc.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/cifs/misc.c +9 -0
@@ -742,7 +742,10 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)list_for_each_entry (cfile, &cifs_inode->openFileList, flist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&cifs_inode->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&cifs_inode->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )
@@ -773,7 +776,10 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)list_for_each_entry (cfile, &tcon->openFileList, tlist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )
@@ -808,7 +814,10 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)if (strstr (full_path, path)) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )
Signature · 1 line
2.34.1
ronnie sahlberg
reviewerLooks good. Acked-by me.
Can you add a "Fixes ..." line to the commit message.
Quoted 52 lines · Bharath SM
From: Bharath SM <[email protected]>
cifs_del_deferred_closefunction has a critical section which modifies the deferred close file list. We must acquiredeferred_lockbefore callingcifs_del_deferred_closefunction.Signed-off-by Bharath SM <[email protected]>--- fs/cifs/misc.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/cifs/misc.c +9
-1@@ -742,7 +742,10 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)list_for_each_entry (cfile, &cifs_inode->openFileList, flist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&cifs_inode->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&cifs_inode->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )@@ -773,7 +776,10 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)list_for_each_entry (cfile, &tcon->openFileList, tlist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )@@ -808,7 +814,10 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)if (strstr (full_path, path)) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL ) --2.34.1
Quoted 4 lines · ronnie sahlberg
Looks good. Acked-by me.
Can you add a "Fixes ..." line to the commit message.
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.
Quoted 16 lines · Bharath SM
From: Bharath SM <[email protected]>
cifs_del_deferred_closefunction has a critical section which modifies the deferred close file list. We must acquiredeferred_lockbefore callingcifs_del_deferred_closefunction.Signed-off-by Bharath SM <[email protected]>--- fs/cifs/misc.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/cifs/misc.c +0
-0
fs/cifs/misc.c cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode) · line 745
Quoted 4 lines
fs/cifs/misc.c +1
-0@@ -742,7 +742,10 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)list_for_each_entry (cfile, &cifs_inode->openFileList, flist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { +
No need for this extra blank line. Please remove the below ones as well.
With the "Fixes:" tag added as per Ronnie's suggestion,
Quoted 30 lines
fs/cifs/misc.c +8
-0+spin_lock (&cifs_inode->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&cifs_inode->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )@@ -773,7 +776,10 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)list_for_each_entry (cfile, &tcon->openFileList, tlist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )@@ -808,7 +814,10 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)if (strstr (full_path, path)) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )Signature · 1 line
2.34.1
Quoted 27 lines · Paulo Alcantara
Quoted 16 lines · Bharath SM
From: Bharath SM <[email protected]>
cifs_del_deferred_closefunction has a critical section which modifies the deferred close file list. We must acquiredeferred_lockbefore callingcifs_del_deferred_closefunction.Signed-off-by Bharath SM <[email protected]>--- fs/cifs/misc.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/cifs/misc.c +0
-0fs/cifs/misc.c cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode) · line 745
Quoted 4 lines
fs/cifs/misc.c +1
-0@@ -742,7 +742,10 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)list_for_each_entry (cfile, &cifs_inode->openFileList, flist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { +No need for this extra blank line. Please remove the below ones as well.
Quoted 3 lines
With the "Fixes:" tag added as per Ronnie's suggestion,
Done. Please find updated patch in attachments.
From 0db3e8aeff0973f9cbe6a55030918e1b828e1b6a Mon Sep 17 00:00:00 2001
From: Bharath SM <[email protected]>
Date: Thu, 20 Apr 2023 13:54:33 +0000
Subject: [PATCH] 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.
--- fs/cifs/misc.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/cifs/misc.c +6 -0
@@ -742,7 +742,9 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)list_for_each_entry (cfile, &cifs_inode->openFileList, flist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { +spin_lock (&cifs_inode->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&cifs_inode->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )
@@ -773,7 +775,9 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)list_for_each_entry (cfile, &tcon->openFileList, tlist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )
@@ -808,7 +812,9 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)if (strstr (full_path, path)) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )
Signature · 1 line
2.34.1
added to cifs-2.6.git for-next now (with the 2 acked-bys) that Fixes tag is there
Quoted 61 lines · Paulo Alcantara
Quoted 16 lines · Bharath SM
From: Bharath SM <[email protected]>
cifs_del_deferred_closefunction has a critical section which modifies the deferred close file list. We must acquiredeferred_lockbefore callingcifs_del_deferred_closefunction.Signed-off-by Bharath SM <[email protected]>--- fs/cifs/misc.c | 9 +++++++++ 1 file changed, 9 insertions(+)fs/cifs/misc.c +0
-0fs/cifs/misc.c cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode) · line 745
Quoted 4 lines
fs/cifs/misc.c +1
-0@@ -742,7 +742,10 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)list_for_each_entry (cfile, &cifs_inode->openFileList, flist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { +No need for this extra blank line. Please remove the below ones as well.
With the "Fixes:" tag added as per Ronnie's suggestion,
Quoted 30 lines
fs/cifs/misc.c +8
-1+spin_lock (&cifs_inode->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&cifs_inode->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )@@ -773,7 +776,10 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)list_for_each_entry (cfile, &tcon->openFileList, tlist) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL )@@ -808,7 +814,10 @@ cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon, const char *path)if (strstr (full_path, path)) {if (delayed_work_pending (&cfile->deferred)) {if (cancel_delayed_work (&cfile->deferred)) { + +spin_lock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock);cifs_del_deferred_close (cfile); +spin_unlock (&CIFS_I (d_inode (cfile->dentry))->deferred_lock); tmp_list =kmalloc (sizeof (struct file_list ),GFP_ATOMIC );if (tmp_list ==NULL ) --2.34.1
Signature · 3 lines
Thanks, Steve