Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Siddharth Chintamaneni <sidchintamaneni@gmail.com>,
	Adam Kim <adamkim@microsoft.com>,
	Paulo Alcantara <pc@manguebit.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y] smb: client: fix busy dentry and inode on unmount from late oplock break
Date: Fri,  4 Dec 2026 06:52:50 -0500	[thread overview]
Message-ID: <20261204115213.2855681-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120247-cold-satirical-d9d9@gregkh>

From: Siddharth Chintamaneni <sidchintamaneni@gmail.com>

[ Upstream commit a10ec8dba77799a0460a4b3dfcac040ac452a325 ]

During unmount, cifs_kill_sb() flushes cifsoplockd_wq and deferredclose_wq
before waiting on cifs_sb->outstanding_rreq for in-flight netfs I/O
requests to finish their cleanup_work in cifs_free_request().

While cifs_kill_sb() is waiting on outstanding_rreq, any cifsFileInfo
referenced by an in-flight request (req->cfile) still has cfile->count >= 1
and remains on tcon->openFileList. If the SMB server sends a lease or
oplock break for that file during this window, the demultiplex thread
(cifsd) finds cfile on tcon->openFileList and calls
cifs_queue_oplock_break(cfile), which takes a new reference on cfile and
queues cfile->oplock_break onto cifsoplockd_wq after cifsoplockd_wq was
already flushed:

  Thread 1 (umount)      Thread 2 (cifsd)       Thread 3 (workers)
  -----------------      ----------------       ------------------
  cifs_kill_sb()
  flush(cifsoplockd_wq)
  flush(deferredclose_wq)
  wait(outstanding_rreq)
    [blocks: rreq == 1]
                         SMB2 Lease Break
                         finds cfile on list
                         cifs_queue_oplock_break()
                           queue(cifsoplockd_wq)
                           cifsFileInfo_get(cfile)
                           [cfile->count: 1 -> 2]
                                                cifs_oplock_break()
                                                  ihold(inode)
                                                cifs_free_request()
                                                  cifsFileInfo_put()
                                                  [cfile->count: 2 -> 1]
                                                  dec(outstanding_rreq)
    [wakes: rreq == 0]
  flush(serverclose_wq)
  flush(fileinfo_put_wq)
  kill_anon_super(sb)
    -> generic_shutdown_super()
       BUG: Dentry still in use (1)
       VFS: Busy inodes after unmount!

Furthermore, cifs_oplock_break() itself holds the inode via ihold() after
dropping cfile and may initiate writeback via filemap_fdatawrite(),
spawning new netfs I/O requests.

Fix this by counting queued oplock breaks in cifs_sb->outstanding_rreq
from when cifs_queue_oplock_break() queues the work until
cifs_oplock_break() finishes, so wait_var_event() in cifs_kill_sb() waits
for both in-flight I/O requests and any late oplock breaks to complete.

Fixes: 340cea84f691 ("cifs: open files should not hold ref on superblock")
Cc: stable@vger.kernel.org
Reported-by: Adam Kim <adamkim@microsoft.com>
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Signed-off-by: Paulo Alcantara <pc@manguebit.org>
[ sashal: Renamed outstanding_rreq to outstanding_aio, used CIFS_SB(cfile->dentry->d_sb) and CIFS_SB(inode->i_sb) for this tree's API, and kept the local cifs_kill_sb() comment wording with a small addition. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/smb/client/cifsfs.c | 8 ++++----
 fs/smb/client/file.c   | 3 +++
 fs/smb/client/misc.c   | 6 +++++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c
index fb7ae74bf0d51..aadd026462636 100644
--- a/fs/smb/client/cifsfs.c
+++ b/fs/smb/client/cifsfs.c
@@ -302,10 +302,10 @@ static void cifs_kill_sb(struct super_block *sb)
 		flush_workqueue(deferredclose_wq);
 
 		/*
-		 * Wait for all in-flight AIO contexts to finish cleanup so
-		 * that their cifsFileInfo final puts have been queued, then
-		 * drain the workqueues so the dentry refs are dropped before
-		 * kill_anon_super().
+		 * Wait for all in-flight AIO contexts and oplock breaks to
+		 * finish cleanup so that their cifsFileInfo final puts have
+		 * been queued, then drain the workqueues so the dentry refs
+		 * are dropped before kill_anon_super().
 		 */
 		wait_var_event(&cifs_sb->outstanding_aio,
 			       !atomic_read(&cifs_sb->outstanding_aio));
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index 6fb4578eb0e0b..ee5576db43370 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -5274,6 +5274,7 @@ void cifs_oplock_break(struct work_struct *work)
 	struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
 						  oplock_break);
 	struct inode *inode = d_inode(cfile->dentry);
+	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 	struct cifsInodeInfo *cinode = CIFS_I(inode);
 	struct cifs_tcon *tcon;
 	struct TCP_Server_Info *server;
@@ -5367,6 +5368,8 @@ void cifs_oplock_break(struct work_struct *work)
 out:
 	cifs_done_oplock_break(cinode);
 	iput(inode);
+	if (atomic_dec_and_test(&cifs_sb->outstanding_aio))
+		wake_up_var(&cifs_sb->outstanding_aio);
 }
 
 /*
diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c
index 48197d47ee821..9b0d727319bf8 100644
--- a/fs/smb/client/misc.c
+++ b/fs/smb/client/misc.c
@@ -649,6 +649,8 @@ void cifs_put_writer(struct cifsInodeInfo *cinode)
  */
 void cifs_queue_oplock_break(struct cifsFileInfo *cfile)
 {
+	struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
+
 	/*
 	 * Bump the handle refcount now while we hold the
 	 * open_file_lock to enforce the validity of it for the oplock
@@ -657,8 +659,10 @@ void cifs_queue_oplock_break(struct cifsFileInfo *cfile)
 	 *
 	 * Only take a reference if the work is actually queued.
 	 */
-	if (queue_work(cifsoplockd_wq, &cfile->oplock_break))
+	if (queue_work(cifsoplockd_wq, &cfile->oplock_break)) {
 		cifsFileInfo_get(cfile);
+		atomic_inc(&cifs_sb->outstanding_aio);
+	}
 }
 
 void cifs_done_oplock_break(struct cifsInodeInfo *cinode)
-- 
2.53.0


      reply	other threads:[~2026-12-04 11:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 13:55 FAILED: patch "[PATCH] smb: client: fix busy dentry and inode on unmount from late" failed to apply to 6.6-stable tree gregkh
2026-12-04 11:52 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204115213.2855681-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=adamkim@microsoft.com \
    --cc=pc@manguebit.org \
    --cc=sidchintamaneni@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox