ksmbd and special characters in file names

Steve French smfrench at gmail.com
Sun May 25 02:39:40 UTC 2025


Interesting ... looks like ksmbd reports the files properly.  I do see
a bug with "ls -l" though

/* check the local view of the shared directory, ie on xfs */
smfrench at smfrench-ThinkPad-P52:/shares/scratch$ ls
'dir-with-&-and'  'file\backslash'     ' file with spaces'
'file*asterisk'   'file?questionmark'   testfile

/* Mount without specifying linux/posix extensions */
smfrench at smfrench-ThinkPad-P52:/shares/scratch$ ls /mnt/no-posix
'dir-with-&-and'  'file\backslash'     ' file with spaces'
'file*asterisk'   'file?questionmark'   testfile

/* Mount with linux/posix/extensions */
smfrench at smfrench-ThinkPad-P52:/shares/scratch$ ls /mnt/posix
'dir-with-&-and'  'file\backslash'     ' file with spaces'
'file*asterisk'   'file?questionmark'   testfile

/* But doing "ls -l" of either posix (or non-posix) mounts returns
errors even though files are displayed correctly */
smfrench at smfrench-ThinkPad-P52:/shares/scratch$ ls /mnt/posix -l
ls: '/mnt/cifs/file*asterisk': No such file or directory
ls: '/mnt/cifs/file\backslash': No such file or directory
ls: '/mnt/cifs/file?questionmark': No such file or directory
total 64
drwxr-xr-x 2 root root     0 May 24 21:20 'dir-with-&-and'
-rwxr-xr-x 1 root root     0 May 24 21:16 'file*asterisk'
-rwxr-xr-x 1 root root     0 May 24 21:17 'file\backslash'
-rwxr-xr-x 1 root root     0 May 24 21:18 'file?questionmark'
-rwxr-xr-x 1 root root     0 May 24 21:17 ' file with spaces'
-rwxr-xr-x 1 root root 65536 May 23 00:10  testfile

Interestingly trying this to Samba I don't have any problem creating
the files with the reserved characters on smb3.1.1 mount but Samba
server returns the incorrect filename in the Find (query dir)
response. It mangles the names (e.g. to A7V558~Y) even with posix
mounts which looks incorrect




On Sat, May 24, 2025 at 4:57 PM Philipp Kerling <pkerling at casix.org> wrote:
>
> Hi!
>
> I've been reading a lot about the SAMBA 3.1.1 POSIX extensions and had
> (perhaps wrongly?) hoped that they would allow native support for all
> file names valid in POSIX if the server and client agree, so I could
> continue to access my files that contain colons or quotes as I did
> using nfs. I know there are remapping options for the reserved
> characters, but they are very annoying to use if you want to have
> direct access to the files on the server machine as well or want to
> serve a directory that already exists and has "problematic" file names.
>
> I have been playing with this on Linux 6.14.6 with ksmbd as server and
> Linux cifs as client. Unfortunately, I was not able to access any
> file/folder containing, for example, a double quote character ("). From
> what I can tell in the logs, this is due to ksmbd validating the name
> and failing:
>
>    May 24 22:25:15 takaishi kernel: ksmbd: converted name = Jazz/SOIL&"PIMP" SESSIONS
>    May 24 22:25:15 takaishi kernel: ksmbd: File name validation failed: 0x22
>
> This seems to be an explicit and intentional check for various
> characters including ?"<>|* [1]. If not for that check, I could access
> my files just fine (mounting with -o nomapposix of course). I've
> patched it out locally to test and it's working great. Even smbclient
> and gvfs are happy with it. Is this something that would make sense
> (even if only as an option), or are there other restrictions/security
> concerns in the SMB protocol that prevent having the special characters
> be treated as valid?
>
> Best regards
> Philipp
>
> [1] https://elixir.bootlin.com/linux/v6.15-rc7/source/fs/smb/server/misc.c#L80-L84
>


-- 
Thanks,

Steve



More information about the samba-technical mailing list