{"id":2231671,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2231671/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260501060907.3859641-1-charsyam@gmail.com/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.1/projects/12/?format=json","name":"Linux CIFS Client","link_name":"linux-cifs-client","list_id":"linux-cifs.vger.kernel.org","list_email":"linux-cifs@vger.kernel.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260501060907.3859641-1-charsyam@gmail.com>","date":"2026-05-01T06:09:07","name":"[v5] smb: client: avoid ctx corruption on failed multichannel remounts","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"9016be707bf6fa73b091392b97187df8aca9d6ab","submitter":{"id":93166,"url":"http://patchwork.ozlabs.org/api/1.1/people/93166/?format=json","name":"DaeMyung Kang","email":"charsyam@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260501060907.3859641-1-charsyam@gmail.com/mbox/","series":[{"id":502424,"url":"http://patchwork.ozlabs.org/api/1.1/series/502424/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=502424","date":"2026-05-01T06:09:07","name":"[v5] smb: client: avoid ctx corruption on failed multichannel remounts","version":5,"mbox":"http://patchwork.ozlabs.org/series/502424/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2231671/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2231671/checks/","tags":{},"headers":{"Return-Path":"\n <linux-cifs+bounces-11322-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-cifs@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=gtLyLYRW;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-cifs+bounces-11322-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"gtLyLYRW\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.216.42","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from sin.lore.kernel.org (sin.lore.kernel.org\n [IPv6:2600:3c15:e001:75::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g6LGW1PjDz1xqf\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 01 May 2026 16:09:23 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id 2CF6430080A9\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  1 May 2026 06:09:16 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 2E98734D3A5;\n\tFri,  1 May 2026 06:09:15 +0000 (UTC)","from mail-pj1-f42.google.com (mail-pj1-f42.google.com\n [209.85.216.42])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 94DE91EEA31\n\tfor <linux-cifs@vger.kernel.org>; Fri,  1 May 2026 06:09:13 +0000 (UTC)","by mail-pj1-f42.google.com with SMTP id\n 98e67ed59e1d1-364efc41420so68934a91.3\n        for <linux-cifs@vger.kernel.org>;\n Thu, 30 Apr 2026 23:09:13 -0700 (PDT)","from ser8.. ([221.156.231.192])\n        by smtp.gmail.com with ESMTPSA id\n 98e67ed59e1d1-364ec00b094sm1252022a91.9.2026.04.30.23.09.10\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 30 Apr 2026 23:09:12 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777615755; cv=none;\n b=Okmb2sQVqqlOpOgcIZzra0fcl8JXeMCpIVyD9FMsnWhuaH+QzhEx3uZeU84hG2DzKwTlT/OIw1QUzxZ9ww6bCXYLAjxSyQiJtrLlQg3+os8SvFU/dCks13W0Pym/g85pXjvpwtSPHnxriocWBop98VdOsESL81UUzskbbVVGKD4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777615755; c=relaxed/simple;\n\tbh=nP4pQbVF7HV231uf0jmDk9LxaD/5c4P8phigOlYZ/7s=;\n\th=From:To:Cc:Subject:Date:Message-ID:MIME-Version;\n b=r33yS6OvbgYDroiaCaZA8LTd8QlgVGLHXL8Crmy7ERPFAF8mBmLTDvaVjr4AcmP9lw7foNv72bn1pI/3Jk8uus5by99ud+6ojMAopbK3VHiOjuiGWJoz8+UUiiF1XTsZewryB95TIrZ5ifSV+wwExd/grVHJ7qhl0e+dl9zSCwM=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=gtLyLYRW; arc=none smtp.client-ip=209.85.216.42","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777615753; x=1778220553;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n         :to:from:from:to:cc:subject:date:message-id:reply-to;\n        bh=Ljh2MVoIl78+pzMqYmjc4MFbJ/Ye1uVBhLvcnHvPQb0=;\n        b=gtLyLYRWo84NN1/RjJJ7JDCNNH7qYb0UHwkOpsgQGVxKVqVYpWmTUqS4niSV+rW6FG\n         jU2ZuVZLiWEJnJHdmbhassqFI/XI4r/jD4s9YwrhxF7OSPrWOyYYSnOFqtZumrvp74PM\n         /I19xR4WT5BSXP+9EGHrrG2cUDKm5mkJl+pgrIzwc7174pAlpqqZtyl3+fLIF5eEd0zj\n         c9XIVv0J9QU4cy0TM1RR5ko5bWy2YiLXbYKzwbdy816+JhQNCzT96OSYuSF4Sq68Gz+Z\n         hRtv3wAk/wSLsTmD7v7+1Uc3YuPCRmDC1NGy/HAvVH9uvYhtXC0LNBFtCoixSiPs5ej8\n         C1hw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777615753; x=1778220553;\n        h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=Ljh2MVoIl78+pzMqYmjc4MFbJ/Ye1uVBhLvcnHvPQb0=;\n        b=JLCLL7CDlbk+lF+Jbf23jkKcdIvptVb+B3ZnakN6oNzz05nSGF8LQdhjoT6y7nU+nz\n         k+5WRpmynwhGrtenLneyyP3NIyWF6mf+XxSlbNr95c/DL5VIe8qUuAhSJqPUB5f/E96W\n         kGquL0zvplA1WDmKdicTlqhpZU4hn6I9SdUJKzItyLxHJSFlNqnqidOtGVGER+pFoNTD\n         w2l4HGOpK4D3Qmye/uaOxhURaeAlmz29C0ysmbsNbaWqV4b76kreHPxPjDLeh2i8hl21\n         u8Zkq2hffWeVRK2Xqa4vkkcbXvNlssBxM6f0lBD213xhuaZM7tFRHMAie++sH8jZ0mIG\n         guAA==","X-Forwarded-Encrypted":"i=1;\n AFNElJ/BLqa0KmZ6ihc5ok5eG3vKVoUzHEJe6nHS0s8cXkNG+nKr8YQ/wAsamQUXRjERLvZjZ8Ej0zC1b2c9@vger.kernel.org","X-Gm-Message-State":"AOJu0Yw6rcmchui1t+7Smjas9rMC8BACSR5/G5ksFgwNbZYrhiYHGDS9\n\th159JUNYe5ChsmwLQCpf+f6h57Y7ykLfB/psCR6gonj2xXfx9YMqMOaB","X-Gm-Gg":"AeBDiet5i+LS0R2xYaWCcAQPwM3/EP4dM1MeXBZ3QCTjezi/BbXyj03lOC7MRUGp3ah\n\tc6X/0Q+P3BtPLIr9+L/+XgFLhI8BiGNEcC+/0gzc8wee8vc121v7tRX9wp74qI4e0AyXgJCqxsK\n\t0YcN/SwKH1tPtG4AEgMkcW8Fl4b1vJb/FI/k0fiaaM/vyueu2yq0wntXrxWVt2YDYcNabieHIs5\n\tOsqn1H0Qi9z02E5+x2+CrowWgbUEsZZGaTIx1QE88JKh62mYGsx6EX94bany6ZRz7MBc5fo93w0\n\tUIkVFNByts47TikaHb0R26XXtmhnfjz67RUNJU8/ty8n+Yh7yRWQU7sgeEZWeM6SNn/+dBtprAP\n\toLsFSUkyOF5GFi/E9zhIdRbthKhN2Xvs9WdQGKh05yYZmk5t0cDsRaWvAQJ0YvGKRBmuqPQD29D\n\tlt3VCN+CJrYq2zmTiS6b0G5lT1qPT0gNy6tJ5WRA==","X-Received":"by 2002:a17:90b:3a4b:b0:359:8e93:4fd6 with SMTP id\n 98e67ed59e1d1-364c3157c9amr3639546a91.4.1777615752788;\n        Thu, 30 Apr 2026 23:09:12 -0700 (PDT)","From":"DaeMyung Kang <charsyam@gmail.com>","To":"Steve French <sfrench@samba.org>,\n\tPaulo Alcantara <pc@manguebit.org>","Cc":"Ronnie Sahlberg <ronniesahlberg@gmail.com>,\n\tShyam Prasad N <sprasad@microsoft.com>,\n\tTom Talpey <tom@talpey.com>,\n\tBharath SM <bharathsm@microsoft.com>,\n\tHenrique Carvalho <henrique.carvalho@suse.com>,\n\tRajasi Mandal <rajasimandal@microsoft.com>,\n\tRajasi Mandal <rajasimandalos@gmail.com>,\n\tlinux-cifs@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tDaeMyung Kang <charsyam@gmail.com>","Subject":"[PATCH v5] smb: client: avoid ctx corruption on failed multichannel\n remounts","Date":"Fri,  1 May 2026 15:09:07 +0900","Message-ID":"<20260501060907.3859641-1-charsyam@gmail.com>","X-Mailer":"git-send-email 2.43.0","Precedence":"bulk","X-Mailing-List":"linux-cifs@vger.kernel.org","List-Id":"<linux-cifs.vger.kernel.org>","List-Subscribe":"<mailto:linux-cifs+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-cifs+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"smb3_reconfigure() moves string fields out of the live mount context\n(cifs_sb->ctx) before updating multichannel state. If the remount fails\nafter that point, the live context can be left with NULL strings or with\noptions that do not match the session state.\n\nSnapshot cifs_sb->ctx on entry, build the new context separately, and\nreplace cifs_sb->ctx only after the staged reconfigure work succeeds.\nRestore the snapshot on failure paths before committing session-side\nstate.\n\nAlso make smb3_sync_session_ctx_passwords() all-or-nothing, and keep the\nses->password commit before smb3_update_ses_channels() so newly added\nchannels authenticate with the new credentials.\n\nFixes: ef529f655a2c (\"cifs: client: allow changing multichannel mount options on remount\")\nReported-by: RAJASI MANDAL <rajasimandalos@gmail.com>\nCloses: https://lore.kernel.org/lkml/CAEY6_V1+dzW3OD5zqXhsWyXwrDTrg5tAMGZ1AJ7_GAuRE+aevA@mail.gmail.com/\nLink: https://lore.kernel.org/lkml/xkr2dlvgibq5j6gkcxd3yhhnj4atgxw2uy4eug2pxm7wy7nbms@iq6cf5taa65v/\nSigned-off-by: DaeMyung Kang <charsyam@gmail.com>\n---\nv5: (feedback from Henrique Carvalho)\n - Drop mchan_rc / scale_busy; the early failure paths now restore\n   cifs_sb->ctx from a snapshot taken on entry.\n - Build new_ctx separately and replace cifs_sb->ctx only on success.\n - Make smb3_sync_session_ctx_passwords() all-or-nothing: allocate\n   both copies first, commit only when both succeed.\n - Switch smb3_sync_ses_chan_max() max_channels parameter to size_t\n   to match struct cifs_ses::chan_max.\n - Shorten the commit message and follow nearby CIFS log style.\n\n fs/smb/client/fs_context.c | 163 +++++++++++++++++++++++++------------\n 1 file changed, 110 insertions(+), 53 deletions(-)","diff":"diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c\nindex b9544eb0381b..1f0cbcf78e17 100644\n--- a/fs/smb/client/fs_context.c\n+++ b/fs/smb/client/fs_context.c\n@@ -767,7 +767,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,\n static int smb3_fs_context_parse_monolithic(struct fs_context *fc,\n \t\t\t\t\t    void *data);\n static int smb3_get_tree(struct fs_context *fc);\n-static void smb3_sync_ses_chan_max(struct cifs_ses *ses, unsigned int max_channels);\n+static void smb3_sync_ses_chan_max(struct cifs_ses *ses, size_t max_channels);\n static int smb3_reconfigure(struct fs_context *fc);\n \n static const struct fs_context_operations smb3_fs_context_ops = {\n@@ -1041,24 +1041,35 @@ do {\t\t\t\t\t\t\t\t\t\\\n \n int smb3_sync_session_ctx_passwords(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses)\n {\n+\tchar *password = NULL, *password2 = NULL;\n+\tbool update_password = false, update_password2 = false;\n+\n \tif (ses->password &&\n \t    cifs_sb->ctx->password &&\n \t    strcmp(ses->password, cifs_sb->ctx->password)) {\n-\t\tkfree_sensitive(cifs_sb->ctx->password);\n-\t\tcifs_sb->ctx->password = kstrdup(ses->password, GFP_KERNEL);\n-\t\tif (!cifs_sb->ctx->password)\n+\t\tpassword = kstrdup(ses->password, GFP_KERNEL);\n+\t\tif (!password)\n \t\t\treturn -ENOMEM;\n+\t\tupdate_password = true;\n \t}\n \tif (ses->password2 &&\n \t    cifs_sb->ctx->password2 &&\n \t    strcmp(ses->password2, cifs_sb->ctx->password2)) {\n-\t\tkfree_sensitive(cifs_sb->ctx->password2);\n-\t\tcifs_sb->ctx->password2 = kstrdup(ses->password2, GFP_KERNEL);\n-\t\tif (!cifs_sb->ctx->password2) {\n-\t\t\tkfree_sensitive(cifs_sb->ctx->password);\n-\t\t\tcifs_sb->ctx->password = NULL;\n+\t\tpassword2 = kstrdup(ses->password2, GFP_KERNEL);\n+\t\tif (!password2) {\n+\t\t\tkfree_sensitive(password);\n \t\t\treturn -ENOMEM;\n \t\t}\n+\t\tupdate_password2 = true;\n+\t}\n+\n+\tif (update_password) {\n+\t\tkfree_sensitive(cifs_sb->ctx->password);\n+\t\tcifs_sb->ctx->password = password;\n+\t}\n+\tif (update_password2) {\n+\t\tkfree_sensitive(cifs_sb->ctx->password2);\n+\t\tcifs_sb->ctx->password2 = password2;\n \t}\n \treturn 0;\n }\n@@ -1072,7 +1083,7 @@ int smb3_sync_session_ctx_passwords(struct cifs_sb_info *cifs_sb, struct cifs_se\n  * with the session's channel lock. This should be called whenever the maximum\n  * allowed channels for a session changes (e.g., after a remount or reconfigure).\n  */\n-static void smb3_sync_ses_chan_max(struct cifs_ses *ses, unsigned int max_channels)\n+static void smb3_sync_ses_chan_max(struct cifs_ses *ses, size_t max_channels)\n {\n \tspin_lock(&ses->chan_lock);\n \tses->chan_max = max_channels;\n@@ -1082,12 +1093,15 @@ static void smb3_sync_ses_chan_max(struct cifs_ses *ses, unsigned int max_channe\n static int smb3_reconfigure(struct fs_context *fc)\n {\n \tstruct smb3_fs_context *ctx = smb3_fc2context(fc);\n+\tstruct smb3_fs_context *new_ctx = NULL;\n+\tstruct smb3_fs_context *old_ctx = NULL;\n \tstruct dentry *root = fc->root;\n \tstruct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);\n \tstruct cifs_ses *ses = cifs_sb_master_tcon(cifs_sb)->ses;\n \tunsigned int rsize = ctx->rsize, wsize = ctx->wsize;\n \tchar *new_password = NULL, *new_password2 = NULL;\n \tbool need_recon = false;\n+\tbool need_mchan_update;\n \tint rc;\n \n \tif (ses->expired_pwd)\n@@ -1097,6 +1111,16 @@ static int smb3_reconfigure(struct fs_context *fc)\n \tif (rc)\n \t\treturn rc;\n \n+\told_ctx = kzalloc_obj(*old_ctx);\n+\tif (!old_ctx)\n+\t\treturn -ENOMEM;\n+\n+\trc = smb3_fs_context_dup(old_ctx, cifs_sb->ctx);\n+\tif (rc) {\n+\t\tkfree(old_ctx);\n+\t\treturn rc;\n+\t}\n+\n \t/*\n \t * We can not change UNC/username/password/domainname/\n \t * workstation_name/nodename/iocharset\n@@ -1106,16 +1130,22 @@ static int smb3_reconfigure(struct fs_context *fc)\n \tSTEAL_STRING(cifs_sb, ctx, UNC);\n \tSTEAL_STRING(cifs_sb, ctx, source);\n \tSTEAL_STRING(cifs_sb, ctx, username);\n+\tSTEAL_STRING(cifs_sb, ctx, domainname);\n+\tSTEAL_STRING(cifs_sb, ctx, nodename);\n+\tSTEAL_STRING(cifs_sb, ctx, iocharset);\n \n-\tif (need_recon == false)\n+\tif (!need_recon) {\n \t\tSTEAL_STRING_SENSITIVE(cifs_sb, ctx, password);\n-\telse  {\n+\t} else {\n \t\tif (ctx->password) {\n \t\t\tnew_password = kstrdup(ctx->password, GFP_KERNEL);\n-\t\t\tif (!new_password)\n-\t\t\t\treturn -ENOMEM;\n-\t\t} else\n+\t\t\tif (!new_password) {\n+\t\t\t\trc = -ENOMEM;\n+\t\t\t\tgoto restore_ctx;\n+\t\t\t}\n+\t\t} else {\n \t\t\tSTEAL_STRING_SENSITIVE(cifs_sb, ctx, password);\n+\t\t}\n \t}\n \n \t/*\n@@ -1125,11 +1155,29 @@ static int smb3_reconfigure(struct fs_context *fc)\n \tif (ctx->password2) {\n \t\tnew_password2 = kstrdup(ctx->password2, GFP_KERNEL);\n \t\tif (!new_password2) {\n-\t\t\tkfree_sensitive(new_password);\n-\t\t\treturn -ENOMEM;\n+\t\t\trc = -ENOMEM;\n+\t\t\tgoto restore_ctx;\n \t\t}\n-\t} else\n+\t} else {\n \t\tSTEAL_STRING_SENSITIVE(cifs_sb, ctx, password2);\n+\t}\n+\n+\t/* if rsize or wsize not passed in on remount, use previous values */\n+\tctx->rsize = rsize ? CIFS_ALIGN_RSIZE(fc, rsize) : cifs_sb->ctx->rsize;\n+\tctx->wsize = wsize ? CIFS_ALIGN_WSIZE(fc, wsize) : cifs_sb->ctx->wsize;\n+\n+\tnew_ctx = kzalloc_obj(*new_ctx);\n+\tif (!new_ctx) {\n+\t\trc = -ENOMEM;\n+\t\tgoto restore_ctx;\n+\t}\n+\n+\trc = smb3_fs_context_dup(new_ctx, ctx);\n+\tif (rc)\n+\t\tgoto restore_ctx;\n+\n+\tneed_mchan_update = ctx->multichannel != cifs_sb->ctx->multichannel ||\n+\t\t\t    ctx->max_channels != cifs_sb->ctx->max_channels;\n \n \t/*\n \t * we may update the passwords in the ses struct below. Make sure we do\n@@ -1140,54 +1188,55 @@ static int smb3_reconfigure(struct fs_context *fc)\n \t/*\n \t * smb2_reconnect may swap password and password2 in case session setup\n \t * failed. First get ctx passwords in sync with ses passwords. It should\n-\t * be okay to do this even if this function were to return an error at a\n-\t * later stage\n+\t * be done before committing new passwords.\n \t */\n \trc = smb3_sync_session_ctx_passwords(cifs_sb, ses);\n \tif (rc) {\n \t\tmutex_unlock(&ses->session_mutex);\n-\t\tkfree_sensitive(new_password);\n-\t\tkfree_sensitive(new_password2);\n-\t\treturn rc;\n+\t\tgoto restore_new_ctx;\n \t}\n \n \t/*\n-\t * now that allocations for passwords are done, commit them\n+\t * If multichannel or max_channels has changed, update the session's channels accordingly.\n+\t * This may add or remove channels to match the new configuration.\n+\t */\n+\tif (need_mchan_update) {\n+\t\t/* Prevent concurrent scaling operations */\n+\t\tspin_lock(&ses->ses_lock);\n+\t\tif (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) {\n+\t\t\tspin_unlock(&ses->ses_lock);\n+\t\t\tmutex_unlock(&ses->session_mutex);\n+\t\t\trc = -EINVAL;\n+\t\t\tgoto restore_new_ctx;\n+\t\t}\n+\t\tses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS;\n+\t\tspin_unlock(&ses->ses_lock);\n+\t}\n+\n+\t/*\n+\t * Commit session passwords before any channel work so newly added\n+\t * channels authenticate with the new credentials.\n \t */\n \tif (new_password) {\n \t\tkfree_sensitive(ses->password);\n \t\tses->password = new_password;\n+\t\tnew_password = NULL;\n \t}\n \tif (new_password2) {\n \t\tkfree_sensitive(ses->password2);\n \t\tses->password2 = new_password2;\n+\t\tnew_password2 = NULL;\n \t}\n \n-\t/*\n-\t * If multichannel or max_channels has changed, update the session's channels accordingly.\n-\t * This may add or remove channels to match the new configuration.\n-\t */\n-\tif ((ctx->multichannel != cifs_sb->ctx->multichannel) ||\n-\t    (ctx->max_channels != cifs_sb->ctx->max_channels)) {\n-\n+\tif (need_mchan_update) {\n \t\t/* Synchronize ses->chan_max with the new mount context */\n \t\tsmb3_sync_ses_chan_max(ses, ctx->max_channels);\n-\t\t/* Now update the session's channels to match the new configuration */\n-\t\t/* Prevent concurrent scaling operations */\n-\t\tspin_lock(&ses->ses_lock);\n-\t\tif (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) {\n-\t\t\tspin_unlock(&ses->ses_lock);\n-\t\t\tmutex_unlock(&ses->session_mutex);\n-\t\t\treturn -EINVAL;\n-\t\t}\n-\t\tses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS;\n-\t\tspin_unlock(&ses->ses_lock);\n \n \t\tmutex_unlock(&ses->session_mutex);\n \n-\t\trc = smb3_update_ses_channels(ses, ses->server,\n-\t\t\t\t\t       false /* from_reconnect */,\n-\t\t\t\t\t       false /* disable_mchan */);\n+\t\tsmb3_update_ses_channels(ses, ses->server,\n+\t\t\t\t\t false /* from_reconnect */,\n+\t\t\t\t\t false /* disable_mchan */);\n \n \t\t/* Clear scaling flag after operation */\n \t\tspin_lock(&ses->ses_lock);\n@@ -1197,22 +1246,30 @@ static int smb3_reconfigure(struct fs_context *fc)\n \t\tmutex_unlock(&ses->session_mutex);\n \t}\n \n-\tSTEAL_STRING(cifs_sb, ctx, domainname);\n-\tSTEAL_STRING(cifs_sb, ctx, nodename);\n-\tSTEAL_STRING(cifs_sb, ctx, iocharset);\n-\n-\t/* if rsize or wsize not passed in on remount, use previous values */\n-\tctx->rsize = rsize ? CIFS_ALIGN_RSIZE(fc, rsize) : cifs_sb->ctx->rsize;\n-\tctx->wsize = wsize ? CIFS_ALIGN_WSIZE(fc, wsize) : cifs_sb->ctx->wsize;\n-\n \tsmb3_cleanup_fs_context_contents(cifs_sb->ctx);\n-\trc = smb3_fs_context_dup(cifs_sb->ctx, ctx);\n+\tmemcpy(cifs_sb->ctx, new_ctx, sizeof(*new_ctx));\n+\tkfree(new_ctx);\n+\tnew_ctx = NULL;\n+\tsmb3_cleanup_fs_context(old_ctx);\n+\told_ctx = NULL;\n \tsmb3_update_mnt_flags(cifs_sb);\n #ifdef CONFIG_CIFS_DFS_UPCALL\n \tif (!rc)\n \t\trc = dfs_cache_remount_fs(cifs_sb);\n #endif\n \n+\treturn rc;\n+\n+restore_new_ctx:\n+\tsmb3_cleanup_fs_context_contents(new_ctx);\n+restore_ctx:\n+\tkfree(new_ctx);\n+\tkfree_sensitive(new_password);\n+\tkfree_sensitive(new_password2);\n+\tsmb3_cleanup_fs_context_contents(cifs_sb->ctx);\n+\tmemcpy(cifs_sb->ctx, old_ctx, sizeof(*old_ctx));\n+\tkfree(old_ctx);\n+\n \treturn rc;\n }\n \n","prefixes":["v5"]}