From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385185; b=ovI7Dpr9pFf1i7QeJxukjCnYq5yGoCE5eD+DQ6tjMWlyByN4j3bCMOkAk5T0FxYMfMlK lEsWq8zcIf9xEO9yFv9z7xofiUMucK2WpCPT5Yev3VFExgVYrdUma3OAPDH8otsJ0rOHD AQU8fEPDRLGumckCQctc1dlJ08ac1Vwosm6GykZK4kx0XXOT3ZNQs6NTE/ciyPzSd6gGV wtoirYWr8a+L0msdcj5mVxA9mChrM0v1xIrpPWdz5TMT1BtKOZWZIpH9zJyy4GdpN3652 dTUEqkzpBBOIm3m/EmVAY4Jd3Yn8iuj7zhoyX314dflPPcflYjpxrFDWnWfAaiUqVwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385185; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=NP9EvWn33VXvAGbVGo8dAvf4Ejmc6q9hJxs6lfkfYWw=; b=V4u++MW+octpYR9Q4wI4H4MGGpKh0lr0siSxQJUQLJyccUIgrK++UjZqW2nZBJEJjqGm eJXaEaxS4z3vY/d8q7RQWI2LMrvZWwIPzDOnihZXt5Bt1j/BnRrZ74ieNm8t/aPG+R8dA avyPp2jnpcUMEAoUu8oc17eLN9G6BUJEmUsMOv2X8/7g2JRZ1NefTbvOLtUrHAQtcsQRb 35fuUVyY8q8daZZpSIxug96Q1IvFqe3ZawYT6GNRpADVUHj3DUxmpsNLxcy4/Tt8dXSku vXLmGIBydqnnAIAepyjSHLV8wEw+aMDl1Xybr7ohIbfp0JvtNQQGy6VFozK5ftWDojg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=YaqLuMwJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B89FD606A322; Fri, 4 Dec 2026 11:53:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=YaqLuMwJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F7AA1F000CE; Fri, 4 Dec 2026 11:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385185; bh=NP9EvWn33VXvAGbVGo8dAvf4Ejmc6q9hJxs6lfkfYWw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YaqLuMwJd2WeqAQTnpVSA+mVIfF+vCUXSNh8/Ms2C8JdTDxF623U2dBaK0CqQvT/G C+I0cX9bNZTmbvp7ISx5Y2KZBC+sRYVlGZV5SO3xDi+ApClwvYaVaUpsj1SFcsb9Ws HLvITCPLf3l+Hln59O+gX9wy2AZSyt7V92S80LOk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dairui Zhang , Namjae Jeon , Sasha Levin Subject: [PATCH 6.6 0452/1167] ksmbd: cache the resolved share path for durable reconnects Date: Fri, 4 Dec 2026 18:57:59 +0900 Message-ID: <20261204100713.786050359@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Namjae Jeon [ Upstream commit 2a90ba573d41efa82e075ba9ac532bb3ec0519c4 ] A share configured as /a/link/b, with /a/link pointing to /real, is opened relative to share->vfs_path at /real/b. However, ksmbd_validate_name_reconnect() compares the file's d_path() result against the original /a/link/b string and rejects a valid reconnect. Render share->vfs_path with d_path() after the existing kern_path() lookup and cache a copy in real_path along with its length. Use the resolved string for durable reconnect name validation. Keep path and path_sz as the configured spelling for existing consumers, including the volume serial calculation and path lookups. Fixes: c8efcc786146 ("ksmbd: add support for durable handles v1/v2") Reported-by: Dairui Zhang Signed-off-by: Namjae Jeon [ sashal: adjusted the call site to a plain share_config_resolve_path() call without scoped_with_init_fs(), and used GFP_KERNEL instead of KSMBD_DEFAULT_GFP. ] Signed-off-by: Sasha Levin --- fs/smb/server/mgmt/share_config.c | 43 +++++++++++++++++++++++++++++-- fs/smb/server/mgmt/share_config.h | 2 ++ fs/smb/server/vfs_cache.c | 12 +++++---- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/fs/smb/server/mgmt/share_config.c b/fs/smb/server/mgmt/share_config.c index cb89e54c4da84..d1cc7fde739b8 100644 --- a/fs/smb/server/mgmt/share_config.c +++ b/fs/smb/server/mgmt/share_config.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,7 @@ static void kill_share(struct ksmbd_share_config *share) path_put(&share->vfs_path); kfree(share->name); kfree(share->path); + kfree(share->real_path); kfree(share); } @@ -124,6 +126,43 @@ static int parse_veto_list(struct ksmbd_share_config *share, return 0; } +static int share_config_resolve_path(struct ksmbd_share_config *share) +{ + char *buf, *path; + int ret; + + ret = kern_path(share->path, 0, &share->vfs_path); + if (ret) + return ret; + + buf = kmalloc(PATH_MAX, GFP_KERNEL); + if (!buf) { + ret = -ENOMEM; + goto out; + } + + path = d_path(&share->vfs_path, buf, PATH_MAX); + if (IS_ERR(path)) { + ret = PTR_ERR(path); + goto out_buf; + } + + path = kstrdup(path, GFP_KERNEL); + if (!path) { + ret = -ENOMEM; + goto out_buf; + } + + share->real_path = path; + share->real_path_sz = strlen(path); +out_buf: + kfree(buf); +out: + if (ret) + path_put(&share->vfs_path); + return ret; +} + static struct ksmbd_share_config *share_config_request(struct ksmbd_work *work, const char *name) { @@ -212,12 +251,12 @@ static struct ksmbd_share_config *share_config_request(struct ksmbd_work *work, goto out; } - ret = kern_path(share->path, 0, &share->vfs_path); + ret = share_config_resolve_path(share); ksmbd_revert_fsids(work); if (ret) { ksmbd_debug(SMB, "failed to access '%s'\n", share->path); - /* Avoid put_path() */ + /* No path reference is retained on failure. */ kfree(share->path); share->path = NULL; } diff --git a/fs/smb/server/mgmt/share_config.h b/fs/smb/server/mgmt/share_config.h index d4ac2dd4de204..baa9f9ed91cde 100644 --- a/fs/smb/server/mgmt/share_config.h +++ b/fs/smb/server/mgmt/share_config.h @@ -16,8 +16,10 @@ struct ksmbd_work; struct ksmbd_share_config { char *name; char *path; + char *real_path; unsigned int path_sz; + unsigned int real_path_sz; unsigned int flags; struct list_head veto_list; diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index 42d2b9cbdd894..e2f7a7d9cca96 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -1354,6 +1354,8 @@ void ksmbd_free_global_file_table(void) int ksmbd_validate_name_reconnect(struct ksmbd_share_config *share, struct ksmbd_file *fp, char *name) { + const char *share_path = share->real_path; + size_t share_path_sz = share->real_path_sz; char *pathname, *ab_pathname; int ret = 0; @@ -1370,14 +1372,14 @@ int ksmbd_validate_name_reconnect(struct ksmbd_share_config *share, if (name) { size_t len = strlen(ab_pathname); - if (len == share->path_sz && !strncmp(ab_pathname, share->path, len)) { + if (len == share_path_sz && !strncmp(ab_pathname, share_path, len)) { /* the durable fp is the share root itself */ if (name[0]) ret = -EINVAL; - } else if (len <= share->path_sz || - strncmp(ab_pathname, share->path, share->path_sz) || - ab_pathname[share->path_sz] != '/' || - strcmp(&ab_pathname[share->path_sz + 1], name)) { + } else if (len <= share_path_sz || + strncmp(ab_pathname, share_path, share_path_sz) || + ab_pathname[share_path_sz] != '/' || + strcmp(&ab_pathname[share_path_sz + 1], name)) { ret = -EINVAL; } if (ret) -- 2.53.0