Linux-CIFS Archive on
 help / color / Atom feed
* [PATCH] CIFS: Fix use after free of file info structures
@ 2019-10-23 22:55 Pavel Shilovsky
  0 siblings, 0 replies; only message in thread
From: Pavel Shilovsky @ 2019-10-23 22:55 UTC (permalink / raw)
  To: Ronnie Sahlberg, Steve French, Dave Wysochanski
  Cc: linux-cifs, Pavel Shilovskiy

Currently the code assumes that if a file info entry belongs
to lists of open file handles of an inode and a tcon then
it has non-zero reference. The recent changes broke that
assumption when putting the last reference of the file info.
There may be a situation when a file is being deleted but
nothing prevents another thread to reference it again
and start using it. This happens because we do not hold
the inode list lock while checking the number of references
of the file info structure. Fix this by doing the proper
locking when doing the check.

Fixes: 487317c99477d ("cifs: add spinlock for the openFileList to cifsInodeInfo")
Fixes: cb248819d209d ("cifs: use cifsInodeInfo->open_file_lock while iterating to avoid a panic")
Cc: Stable <>
Reviewed-by: Ronnie Sahlberg <>
Signed-off-by: Pavel Shilovsky <>
 fs/cifs/file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 4c1aeb2cf7f5..53dbb6e0d390 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -405,10 +405,11 @@ void _cifsFileInfo_put(struct cifsFileInfo *cifs_file, bool wait_oplock_handler)
 	bool oplock_break_cancelled;
+	spin_lock(&cifsi->open_file_lock);
 	if (--cifs_file->count > 0) {
+		spin_unlock(&cifsi->open_file_lock);
@@ -421,9 +422,7 @@ void _cifsFileInfo_put(struct cifsFileInfo *cifs_file, bool wait_oplock_handler)
 	cifs_add_pending_open_locked(&fid, cifs_file->tlink, &open);
 	/* remove it from the lists */
-	spin_lock(&cifsi->open_file_lock);
-	spin_unlock(&cifsi->open_file_lock);
@@ -440,6 +439,7 @@ void _cifsFileInfo_put(struct cifsFileInfo *cifs_file, bool wait_oplock_handler)
 		cifs_set_oplock_level(cifsi, 0);
+	spin_unlock(&cifsi->open_file_lock);
 	oplock_break_cancelled = wait_oplock_handler ?

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23 22:55 [PATCH] CIFS: Fix use after free of file info structures Pavel Shilovsky

Linux-CIFS Archive on

Archives are clonable:
	git clone --mirror linux-cifs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-cifs linux-cifs/ \
	public-inbox-index linux-cifs

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone