Commit c5a709f0 authored by Namjae Jeon's avatar Namjae Jeon Committed by Steve French

ksmbd: handle caseless file creation

Ray Zhang reported ksmbd can not create file if parent filename is
caseless.

Y:\>mkdir A
Y:\>echo 123 >a\b.txt
The system cannot find the path specified.
Y:\>echo 123 >A\b.txt

This patch convert name obtained by caseless lookup to parent name.

Cc: stable@vger.kernel.org # v5.15+
Reported-by: default avatarRay Zhang <zhanglei002@gmail.com>
Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent ca4974ca
...@@ -1167,7 +1167,7 @@ static bool __caseless_lookup(struct dir_context *ctx, const char *name, ...@@ -1167,7 +1167,7 @@ static bool __caseless_lookup(struct dir_context *ctx, const char *name,
if (cmp < 0) if (cmp < 0)
cmp = strncasecmp((char *)buf->private, name, namlen); cmp = strncasecmp((char *)buf->private, name, namlen);
if (!cmp) { if (!cmp) {
memcpy((char *)buf->private, name, namlen); memcpy((char *)buf->private, name, buf->used);
buf->dirent_count = 1; buf->dirent_count = 1;
return false; return false;
} }
...@@ -1235,10 +1235,7 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name, ...@@ -1235,10 +1235,7 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name,
char *filepath; char *filepath;
size_t path_len, remain_len; size_t path_len, remain_len;
filepath = kstrdup(name, GFP_KERNEL); filepath = name;
if (!filepath)
return -ENOMEM;
path_len = strlen(filepath); path_len = strlen(filepath);
remain_len = path_len; remain_len = path_len;
...@@ -1281,10 +1278,9 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name, ...@@ -1281,10 +1278,9 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name,
err = -EINVAL; err = -EINVAL;
out2: out2:
path_put(parent_path); path_put(parent_path);
out1:
kfree(filepath);
} }
out1:
if (!err) { if (!err) {
err = mnt_want_write(parent_path->mnt); err = mnt_want_write(parent_path->mnt);
if (err) { if (err) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment