cifsd-team / ksmbd

ksmbd kernel server(SMB/CIFS server)
154 stars 23 forks source link

ksmbd does not handle case-insensitive parent directory names correctly #613

Closed zhanglei002 closed 3 weeks ago

zhanglei002 commented 3 months ago

Step to reproduce:

Y:\>mkdir A

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

Y:\>echo 123 >A\\b.txt

ksmbd logs:

6月 20 16:44:41 zhanglei-pc kernel: ksmbd: can not get linux path for A, rc = -2
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: file does not exist, so creating
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: creating directory
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: inherit posix acl failed : -2
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: get query on disk id context
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: credits: requested[1] granted[1] total_granted[31]
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: RFC1002 header 88 bytes
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: SMB2 len 88
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: volatile_id = 2
6月 20 16:44:41 zhanglei-pc kernel: ksmbd: credits: requested[1] granted[1] total_granted[31]
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: RFC1002 header 224 bytes
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: SMB2 data length 88 offset 136
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: SMB2 len 224
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: converted name = a/b.txt
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: get query maximal access context
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: can not get linux path for a/b.txt, rc = -2
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: file does not exist, so creating
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: creating regular file
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: Error response: c000003a
6月 20 16:45:16 zhanglei-pc kernel: ksmbd: credits: requested[1] granted[1] total_granted[31]
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: RFC1002 header 224 bytes
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: SMB2 data length 88 offset 136
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: SMB2 len 224
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: converted name = A/b.txt
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: get query maximal access context
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: can not get linux path for A/b.txt, rc = -2
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: file does not exist, so creating
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: creating regular file
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: inherit posix acl failed : -2
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: get query on disk id context
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: credits: requested[1] granted[1] total_granted[31]
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: RFC1002 header 118 bytes
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: SMB2 data length 6 offset 112
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: SMB2 len 118
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: flags 0
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: filename b.txt, offset 0, len 6
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: unexpected oplock(0x9)
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: credits: requested[1] granted[1] total_granted[31]
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: RFC1002 header 88 bytes
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: SMB2 len 88
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: volatile_id = 3
6月 20 16:45:37 zhanglei-pc kernel: ksmbd: credits: requested[1] granted[1] total_granted[31]
namjaejeon commented 3 months ago

Okay, Let me check it, Thanks for your report.

namjaejeon commented 3 weeks ago

@zhanglei002 Can you check if the following patch fix your issue ?

diff --git a/vfs.c b/vfs.c
index 7257ba1..12f5d4d 100644
--- a/vfs.c
+++ b/vfs.c
@@ -2746,7 +2746,7 @@ static int __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;
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
                return false;
@@ -2823,10 +2823,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;

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

+out1:
zhanglei002 commented 3 weeks ago

Thanks, the issue seems to disappear.

namjaejeon commented 3 weeks ago

@zhanglei002 Let me know your e-mail address to add reported-by tag to the patch.

zhanglei002 commented 3 weeks ago

@zhanglei002 Let me know your e-mail address to add reported-by tag to the patch.

My e-mail address is zhanglei002@gmail.com

namjaejeon commented 3 weeks ago

Added it to the patch:) Thanks for your check!