From: He Wang Date: Mon, 6 Jan 2025 03:39:54 +0000 (+0000) Subject: ksmbd: fix unexpectedly changed path in ksmbd_vfs_kern_path_locked X-Git-Tag: v6.1.125~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13e41c58c74baa71f34c0830eaa3c29d53a6e964;p=thirdparty%2Fkernel%2Fstable.git ksmbd: fix unexpectedly changed path in ksmbd_vfs_kern_path_locked [ Upstream commit 2ac538e40278a2c0c051cca81bcaafc547d61372 ] When `ksmbd_vfs_kern_path_locked` met an error and it is not the last entry, it will exit without restoring changed path buffer. But later this buffer may be used as the filename for creation. Fixes: c5a709f08d40 ("ksmbd: handle caseless file creation") Signed-off-by: He Wang Acked-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin --- diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c index eaae67a2f720e..396d4ea77d34a 100644 --- a/fs/smb/server/vfs.c +++ b/fs/smb/server/vfs.c @@ -1249,6 +1249,8 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name, filepath, flags, path); + if (!is_last) + next[0] = '/'; if (err) goto out2; else if (is_last) @@ -1256,7 +1258,6 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name, path_put(parent_path); *parent_path = *path; - next[0] = '/'; remain_len -= filename_len + 1; }