namjaejeon / ksmbd

ksmbd kernel server(SMB/CIFS server)
https://github.com/cifsd-team/ksmbd
282 stars 64 forks source link

Cannot open directory starting with unicode character ending with 0x5c #484

Closed invis-z closed 4 months ago

invis-z commented 5 months ago

If the directory name in the root of the share starts with character like 镜(0x955c) or Ṝ(0x1e5c), it (and anything inside) cannot be accessed. Other directory in the same share is accessible, including the one starts with 尒(0x5c12).

Probably related to code here: https://github.com/namjaejeon/ksmbd/blob/999cee7cc044a9a803e040020dc2385c18779190/smb2pdu.c#L2941-L2947

Distro: openSUSE Tumbleweed Kernel: 6.9.3-1-default ksmbd-tools: 3.5.2-1.1

Share config (linuxuser uid=1000 gid=1000):

[ShareName]
    ; share parameters
    force group = linuxuser
    force user = linuxuser
    path = /mnt/ShareName
    read only = no
    valid users = SMBUser
    write list = SMBUser

smb debug log:

Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 data length 2 offset 120
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 len 122
Jun 08 13:33:49 smbserver kernel: ksmbd: converted name = Ṝ
Jun 08 13:33:49 smbserver kernel: ksmbd: check permission using windows acl
Jun 08 13:33:49 smbserver kernel: ksmbd: failed to load dos attribute in xattr
Jun 08 13:33:49 smbserver kernel: ksmbd: credits: requested[1] granted[1] total_granted[8192]
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 data length 0 offset 104
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 len 105
Jun 08 13:33:49 smbserver kernel: ksmbd: GOT query info request
Jun 08 13:33:49 smbserver kernel: ksmbd: GOT SMB2_O_INFO_FILE
Jun 08 13:33:49 smbserver kernel: ksmbd: filename = \Ṝ
Jun 08 13:33:49 smbserver kernel: ksmbd: credits: requested[1] granted[1] total_granted[8192]
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 len 88
Jun 08 13:33:49 smbserver kernel: ksmbd: volatile_id = 19034
Jun 08 13:33:49 smbserver kernel: ksmbd: credits: requested[1] granted[1] total_granted[8192]
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 data length 2 offset 120
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 len 122
Jun 08 13:33:49 smbserver kernel: ksmbd: not allow directory name included leading slash
Jun 08 13:33:49 smbserver kernel: ksmbd: Error response: c000000d
Jun 08 13:33:49 smbserver kernel: ksmbd: credits: requested[1] granted[1] total_granted[8192]
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 data length 2 offset 120
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 len 122
Jun 08 13:33:49 smbserver kernel: ksmbd: converted name = Ṝ
Jun 08 13:33:49 smbserver kernel: ksmbd: check permission using windows acl
Jun 08 13:33:49 smbserver kernel: ksmbd: failed to load dos attribute in xattr
Jun 08 13:33:49 smbserver kernel: ksmbd: credits: requested[1] granted[1] total_granted[8192]
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 data length 0 offset 104
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 len 105
Jun 08 13:33:49 smbserver kernel: ksmbd: GOT query info request
Jun 08 13:33:49 smbserver kernel: ksmbd: GOT SMB2_O_INFO_FILE
Jun 08 13:33:49 smbserver kernel: ksmbd: filename = \Ṝ
Jun 08 13:33:49 smbserver kernel: ksmbd: credits: requested[1] granted[1] total_granted[8192]
Jun 08 13:33:49 smbserver kernel: ksmbd: SMB2 len 88
Jun 08 13:33:49 smbserver kernel: ksmbd: volatile_id = 19035
Jun 08 13:33:49 smbserver kernel: ksmbd: credits: requested[1] granted[1] total_granted[8192]
namjaejeon commented 5 months ago

Thanks for your report:) Can you check if this problem do not happen with samba ?

invis-z commented 5 months ago

It doesn't happen on samba. I was migrating the same share from samba, which worked fine with the same root path.

[ShareName]
path = /mnt/ShareName
valid users = 
comment = 
browseable = yes
writeable = yes
printable = no
guest ok = no
read only = no
create mask = 664

Note: I was using different credentials, and logging in as linuxuser directly so permission isn't different here.

namjaejeon commented 5 months ago

Okay, Can you check this patch ? https://github.com/namjaejeon/ksmbd/commit/ddb1df1c215172e63aef8ed1cb20985e0f1d1590

invis-z commented 5 months ago

Yes, the problem is gone with the patch! Thanks!

namjaejeon commented 5 months ago

Thanks for your check:) I will apply this patch to the mainline and github ksmbd.

invis-z commented 4 months ago

The patch seems was accepted by upstream and issue was fixed after upgrading to kernel 6.9.7-1-default for openSUSE Tumbleweed (rolling release so it probably was fixed in earlier kernels already). Closing. Thanks!