Skip to content

Commit

Permalink
ksmbd: handle caseless file creation
Browse files Browse the repository at this point in the history
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: Ray Zhang <zhanglei002@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Namjae Jeon authored and Steve French committed Sep 14, 2024
1 parent ca4974c commit c5a709f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions fs/smb/server/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ static bool __caseless_lookup(struct dir_context *ctx, const char *name,
if (cmp < 0)
cmp = strncasecmp((char *)buf->private, name, namlen);
if (!cmp) {
memcpy((char *)buf->private, name, namlen);
memcpy((char *)buf->private, name, buf->used);
buf->dirent_count = 1;
return false;
}
Expand Down Expand Up @@ -1235,10 +1235,7 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name,
char *filepath;
size_t path_len, remain_len;

filepath = kstrdup(name, GFP_KERNEL);
if (!filepath)
return -ENOMEM;

filepath = name;
path_len = strlen(filepath);
remain_len = path_len;

Expand Down Expand Up @@ -1281,10 +1278,9 @@ int ksmbd_vfs_kern_path_locked(struct ksmbd_work *work, char *name,
err = -EINVAL;
out2:
path_put(parent_path);
out1:
kfree(filepath);
}

out1:
if (!err) {
err = mnt_want_write(parent_path->mnt);
if (err) {
Expand Down

0 comments on commit c5a709f

Please sign in to comment.