Linux-CIFS Archive mirror
 help / color / mirror / Atom feed
From: Henrique Carvalho <henrique.carvalho@suse.com>
To: sfrench@samba.org
Cc: metze@samba.org, pc@manguebit.org, ronniesahlberg@gmail.com,
	sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com,
	ematsumiya@suse.de, linux-cifs@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 2/3] smb: client: fix race in multichannel rescaling during mount
Date: Wed, 29 Apr 2026 17:52:35 -0300	[thread overview]
Message-ID: <20260429205236.456099-2-henrique.carvalho@suse.com> (raw)
In-Reply-To: <20260429205236.456099-1-henrique.carvalho@suse.com>

mchan_mount_* introduced async channel rescaling during mount. That can
lead race with other mount/remount attempts that use the same session,
when these are scaling down the channels, potentially leading to UAF, as
described in
https://lore.kernel.org/linux-cifs/rw7ptbx22cntes5eag5r3kvg5mzfvvzdhj4v2kw6mnunmsewev@f2iyrmmitkl3/

Fix this by using the same serialization used in other rescaling paths
and if in a race, rescheduling the channel scaling work.

Cc: stable@vger.kernel.org
Fixes: 556bb341f9f2 ("smb: client: introduce multichannel async work during mount")
Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com>
---
 fs/smb/client/cifsglob.h |  2 +-
 fs/smb/client/connect.c  | 32 +++++++++++++++++++++++++-------
 fs/smb/client/sess.c     |  1 -
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index 82e0adc1dabd..ef63a1c3249c 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -1817,7 +1817,7 @@ struct cifs_mount_ctx {
 };
 
 struct mchan_mount {
-	struct work_struct work;
+	struct delayed_work dwork;
 	struct cifs_ses *ses;
 };
 
diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c
index dcde25da468d..2ea93f0b78c9 100644
--- a/fs/smb/client/connect.c
+++ b/fs/smb/client/connect.c
@@ -3813,7 +3813,7 @@ mchan_mount_alloc(struct cifs_ses *ses)
 	if (!mchan_mount)
 		return ERR_PTR(-ENOMEM);
 
-	INIT_WORK(&mchan_mount->work, mchan_mount_work_fn);
+	INIT_DELAYED_WORK(&mchan_mount->dwork, mchan_mount_work_fn);
 
 	spin_lock(&cifs_tcp_ses_lock);
 	cifs_smb_ses_inc_refcount(ses);
@@ -3833,13 +3833,32 @@ mchan_mount_free(struct mchan_mount *mchan_mount)
 static void
 mchan_mount_work_fn(struct work_struct *work)
 {
-	struct mchan_mount *mchan_mount = container_of(work, struct mchan_mount, work);
+	struct mchan_mount *mchan_mount = container_of(work, struct mchan_mount, dwork.work);
+	struct cifs_ses *ses = mchan_mount->ses;
 
-	smb3_update_ses_channels(mchan_mount->ses,
-				 mchan_mount->ses->server,
+	/*
+	 * mchan_mount_work_fn could race with smb3_update_ses_channel called
+	 * for the same session on remount, other mounts or
+	 * smb3_update_ses_channel
+	 */
+	spin_lock(&ses->ses_lock);
+	if (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) {
+		spin_unlock(&ses->ses_lock);
+		queue_delayed_work(cifsiod_wq, &mchan_mount->dwork, 2 * HZ);
+		return;
+	}
+	ses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS;
+	spin_unlock(&ses->ses_lock);
+
+	smb3_update_ses_channels(ses,
+				 ses->server,
 				 false /* from_reconnect */,
 				 false /* disable_mchan */);
 
+	spin_lock(&ses->ses_lock);
+	ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS;
+	spin_unlock(&ses->ses_lock);
+
 	mchan_mount_free(mchan_mount);
 }
 
@@ -3885,7 +3904,7 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 		goto error;
 
 	if (ctx->multichannel)
-		queue_work(cifsiod_wq, &mchan_mount->work);
+		queue_work(cifsiod_wq, &mchan_mount->dwork.work);
 
 	free_xid(mnt_ctx.xid);
 	return rc;
@@ -3942,8 +3961,7 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
 		goto error;
 
 	if (ctx->multichannel)
-		queue_work(cifsiod_wq, &mchan_mount->work);
-
+		queue_work(cifsiod_wq, &mchan_mount->dwork.work);
 	free_xid(mnt_ctx.xid);
 	return rc;
 
diff --git a/fs/smb/client/sess.c b/fs/smb/client/sess.c
index de2012cc9cf3..24d5206e5c44 100644
--- a/fs/smb/client/sess.c
+++ b/fs/smb/client/sess.c
@@ -627,7 +627,6 @@ cifs_ses_add_channel(struct cifs_ses *ses,
 	return rc;
 }
 
-
 int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
 				    struct cifs_ses *ses)
 {
-- 
2.53.0


  reply	other threads:[~2026-04-29 20:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 20:52 [PATCH 1/3] smb: client: fix conflicting option validation for new mount API Henrique Carvalho
2026-04-29 20:52 ` Henrique Carvalho [this message]
2026-04-29 20:52 ` [PATCH 3/3] smb: client: make smb3_update_ses_channels() match expected API Henrique Carvalho

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=20260429205236.456099-2-henrique.carvalho@suse.com \
    --to=henrique.carvalho@suse.com \
    --cc=bharathsm@microsoft.com \
    --cc=ematsumiya@suse.de \
    --cc=linux-cifs@vger.kernel.org \
    --cc=metze@samba.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=sfrench@samba.org \
    --cc=sprasad@microsoft.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).