Bug 11307 - Files/directories with reserved characters (colon or question mark) behave strangely
Summary: Files/directories with reserved characters (colon or question mark) behave st...
Status: NEEDINFO
Alias: None
Product: CifsVFS
Classification: Unclassified
Component: kernel fs (show other bugs)
Version: 3.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: Steve French
QA Contact: cifs QA contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-01 16:01 UTC by possum+samba
Modified: 2020-07-16 00:12 UTC (History)
2 users (show)

See Also:


Attachments
Example of behavior showing old system and new system (994 bytes, text/plain)
2015-06-01 16:01 UTC, possum+samba
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description possum+samba 2015-06-01 16:01:23 UTC
Created attachment 11118 [details]
Example of behavior showing old system and new system

Recent updates have caused mounted files/directories named with Windows reserved characters (*, :, |, <, >, ?) to behave strangely.

Files containing the special characters can be read normally but cannot be deleted. Directories containing the special characters will appear with an `ls` but the contents of the directory will not appear. Files in the directory appear to be readable if the full path is known.

The problem is evident with kernel version is 4.0.4-2-ARCH. On an older system (kernel version 3.16.3-1-ARCH) it's fine. I am attaching a file showing some examples of the behavior.

Downgrading cifs-utils didn't seem to help. smbclient appears to be unaffected, as I can access the remote server just fine.

If it's relevant, I am fairly certain the remote server supports unicode, as I have a number of files on the share that contain CJK characters in filenames (the remote server is the default on the ASUS RT-N66U router).

The change seems to have happened in arch sometime between November 2014 and February 2015. I believe this is not an arch-specific bug, as at least one other user has seen the same issue on Debian sid: 

http://www.reddit.com/r/debian/comments/37pbcq/wildcard_filename_issue_on_cifs_share_under_sid/
Comment 1 possum+samba 2015-07-02 21:52:10 UTC
I've narrowed down the kernel version this behavior was introduced in, at least in the Arch Linux packages.

Version 3.17.6-1-ARCH behaves as expected, but 3.18.2-2-ARCH does not.

According to the Arch Rollback Machine, that package was introduced 2015-01-15:

http://seblu.net/a/arm/2015/01/15/core/os/x86_64/

So the change was introduced sometime betweer 3.17.6 and 3.18.2. Could it be related to this?

https://bugzilla.kernel.org/show_bug.cgi?id=92401

The wiki also says there was a change to the way the reserved characters were mapped:

"By default support mapchars ('SFM' style remapping, ie the same way the Mac remaps them) for the seven reserved characters (*, ?, : etc.) when mounting with SMB3."

https://wiki.samba.org/index.php/LinuxCIFSKernel#3.18_Kernel
Comment 2 burnsmellfactory 2015-12-16 07:55:43 UTC
I can confirm this -- I have the same issue.  I have a Linux Samba server and Linux client.  I believe I am using protocol version 1 (seems to be the default).  I changed nothing on the server, but I did upgrade the kernel on my client machine from 3.12.13 to 4.1.12.  Since then, I can list but not read files which contain the Windows reserved chars, and I cannot enter directories which contain those chars.  Also, since UNIX extensions are enabled on the server and client (this is the default since both are Linux) I cannot use symlinks to read files/directories which have such chars in their paths, even if the symlinks themselves do not have such chars in their names.

I use Gentoo Linux on both my client and server.  On the client machine, I tried cifs-utils-6.1-r1 and 6.4 -- neither worked.

The bug you linked to https://bugzilla.kernel.org/show_bug.cgi?id=92401 describes exactly what I am seeing.
Comment 3 Steve French 2019-02-07 09:54:55 UTC
This was resolved and enabled by default for SMB2/SMB3 mounts more than four years ago, but there was this patch which may be important for your use case which certainly should be in by 4.2 kernel.   Make sure your /proc/mounts mount entry for this cifs mount shows "mapposix"

commit bc8ebdc4f54cc944b0ecc0fb0d18b0ffbaab0468
Author: Nakajima Akira <nakajima.akira@nttcom.co.jp>
Date:   Fri Feb 13 15:35:58 2015 +0900

    Fix that several functions handle incorrect value of mapchars
    
    Cifs client has problem with reserved chars filename.
    
    [BUG1] : several functions handle incorrect value of mapchars
    -       cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
    +       cifs_remap(cifs_sb));
    
    [BUG2] : forget to convert reserved chars when creating SymbolicLink.
    -       CIFSUnixCreateSymLink() calls cifs_strtoUTF16
    +       CIFSUnixCreateSymLink() calls cifsConvertToUTF16() with remap
    
    [BUG3] : forget to convert reserved chars when getting SymbolicLink.
    -       CIFSSMBUnixQuerySymLink() calls cifs_strtoUTF16
    +       CIFSSMBUnixQuerySymLink() calls cifsConvertToUTF16() with remap
    
    [BUG4] : /proc/mounts don't show "mapposix" when using mapposix mount option
    +           cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SFM_CHR)
    +               seq_puts(s, ",mapposix");