ksmbd and special characters in file names
Subsystems (2)
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
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@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@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@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@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
Quoted 35 lines · Philipp Kerling
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: 0x22This 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
Signature · 3 lines
Thanks, Steve
Quoted 5 lines · Steve French via samba-technical
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
I've filed a bug
https://bugzilla.samba.org/show_bug.cgi?id=15862
and attached a WIP fix. Can you test it? It's on top of master.
-slow
Namjae Jeon
maintainerQuoted 21 lines · Philipp Kerling
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
Quoted 8 lines
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?
Files containing special characters are not recognized in Windows. That's why ksmbd restricts the creation of such files. However, it seems right to allow it when mounting posix extensions. So we can probably handle it like the following change.
fs/smb/server/smb2pdu.c +5 -3
@@ -2925,9 +2925,11 @@ int smb2_open(struct ksmbd_work *work) goto err_out2; } - rc =ksmbd_validate_filename (name); -if (rc <0 ) - goto err_out2; +if (tcon->posix_extensions == false) { + rc =ksmbd_validate_filename (name); +if (rc <0 ) + goto err_out2; + }if (ksmbd_share_veto_filename (share, name)) { rc = -ENOENT ;
But There is one problem. cifs.ko always sends SMB2_POSIX_EXTENSIONS_AVAILABLE context
to the server regardless of mount option -o posix.
Steve,
ksmbd assumes that the client is doing smb3.1.1 posix extension mount if it sends SMB2_POSIX_EXTENSIONS_AVAILABLE context.
If cifs.ko always sends SMB2_POSIX_EXTENSIONS_AVAILABLE context regardless of -o posix, how does the server know whether posix extension mount or not?
Quoted 6 lines
Best regards
Philipp[1] https://elixir.bootlin.com/linux/v6.15-rc7/source/fs/smb/server/misc.c#L80-L84
Quoted 60 lines · Namjae Jeon
Quoted 21 lines · Philipp Kerling
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: 0x22Quoted 8 lines
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?
Files containing special characters are not recognized in Windows. That's why ksmbd restricts the creation of such files. However, it seems right to allow it when mounting posix extensions. So we can probably handle it like the following change.
fs/smb/server/smb2pdu.c +5
-3@@ -2925,9 +2925,11 @@ int smb2_open(struct ksmbd_work *work) goto err_out2; } - rc =ksmbd_validate_filename (name); -if (rc <0 ) - goto err_out2; +if (tcon->posix_extensions == false) { + rc =ksmbd_validate_filename (name); +if (rc <0 ) + goto err_out2; + }if (ksmbd_share_veto_filename (share, name)) { rc = -ENOENT ;But There is one problem. cifs.ko always sends
SMB2_POSIX_EXTENSIONS_AVAILABLEcontext
to the server regardless of mount option -o posix.
Quoted 6 lines
Steve,
ksmbd assumes that the client is doing smb3.1.1 posix extension mount if it sendsSMB2_POSIX_EXTENSIONS_AVAILABLEcontext.
If cifs.ko always sendsSMB2_POSIX_EXTENSIONS_AVAILABLEcontext regardless of -o posix, how does the server know whether posix extension mount or not?
If the POSIX/Linux context is included in the SMB3.1.1 open then we mounted with ("linux" or "posix")
Signature · 3 lines
Thanks, Steve
Namjae Jeon
maintainerQuoted 62 lines · Steve French
Quoted 60 lines · Namjae Jeon
Quoted 21 lines · Philipp Kerling
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: 0x22Quoted 8 lines
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?
Files containing special characters are not recognized in Windows. That's why ksmbd restricts the creation of such files. However, it seems right to allow it when mounting posix extensions. So we can probably handle it like the following change.
fs/smb/server/smb2pdu.c +5
-3@@ -2925,9 +2925,11 @@ int smb2_open(struct ksmbd_work *work) goto err_out2; } - rc =ksmbd_validate_filename (name); -if (rc <0 ) - goto err_out2; +if (tcon->posix_extensions == false) { + rc =ksmbd_validate_filename (name); +if (rc <0 ) + goto err_out2; + }if (ksmbd_share_veto_filename (share, name)) { rc = -ENOENT ;But There is one problem. cifs.ko always sends
SMB2_POSIX_EXTENSIONS_AVAILABLEcontext
to the server regardless of mount option -o posix.
Quoted 9 lines
Quoted 6 lines
Steve,
ksmbd assumes that the client is doing smb3.1.1 posix extension mount if it sendsSMB2_POSIX_EXTENSIONS_AVAILABLEcontext.
If cifs.ko always sendsSMB2_POSIX_EXTENSIONS_AVAILABLEcontext regardless of -o posix, how does the server know whether posix extension mount or not?If the POSIX/Linux context is included in the SMB3.1.1 open then we mounted with ("linux" or "posix")
Such a context could be created in smb2_create context like apple context(AAPL). However, I wonder if there is any plan to add it to SMB3.1.1 posix extension specification.
Quoted 6 lines
--
Thanks,Steve
Quoted 6 lines · Namjae Jeon
Quoted 2 lines · Steve French
If the POSIX/Linux context is included in the SMB3.1.1 open then we mounted with ("linux" or "posix")
Such a context could be created in
smb2_createcontext like apple context(AAPL). However, I wonder if there is any plan to add it to SMB3.1.1 posix extension specification.
It's been part of the spec since the beginning. You can find it here:
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16 SMB2_CREATE_POSIX_CONTEXT
Namjae Jeon
maintainerQuoted 9 lines · Ralph Boehme
Quoted 6 lines · Namjae Jeon
Quoted 2 lines · Steve French
If the POSIX/Linux context is included in the SMB3.1.1 open then we mounted with ("linux" or "posix")
Such a context could be created in
smb2_createcontext like apple context(AAPL). However, I wonder if there is any plan to add it to SMB3.1.1 posix extension specification.It's been part of the spec since the beginning. You can find it here:
Right, I found it.
Thanks for your reply.
Quoted 4 lines
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16
SMB2_CREATE_POSIX_CONTEXT
Namjae Jeon
maintainerQuoted 5 lines · Namjae Jeon
Quoted 3 lines · Ralph Boehme
Quoted 1 line · Namjae Jeon
On Mon, May 26, 2025 at 7:45 AM Steve French <[email protected]> wrote:
Quoted 12 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
If the POSIX/Linux context is included in the SMB3.1.1 open then we mounted with ("linux" or "posix")
Such a context could be created in
smb2_createcontext like apple context(AAPL). However, I wonder if there is any plan to add it to SMB3.1.1 posix extension specification.It's been part of the spec since the beginning. You can find it here:
Right, I found it.
Thanks for your reply.Quoted 4 lines
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16
SMB2_CREATE_POSIX_CONTEXT
Philipp,
Can you confirm if your issue is fixed with the attached patch ?
Thanks!
From 4d4fd5bb63797209d63247c95e875730aa9040de Mon Sep 17 00:00:00 2001
From: Namjae Jeon <[email protected]>
Date: Tue, 27 May 2025 11:23:01 +0900
Subject: [PATCH] ksmbd: allow a filename to contain special characters on
SMB3.1.1 posix extension
If client send SMB2_CREATE_POSIX_CONTEXT to ksmbd, Allow a filename to contain special characters.
--- fs/smb/server/smb2pdu.c | 53 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 26 deletions(-)
fs/smb/server/smb2pdu.c +27 -26
@@ -2874,7 +2874,7 @@ int smb2_open(struct ksmbd_work *work)int req_op_level =0 , open_flags =0 , may_flags =0 , file_info =0 ;int rc =0 ;int contxt_cnt =0 , query_disk_id =0 ; -int maximal_access_ctxt =0 , posix_ctxt =0 ; +bool maximal_access_ctxt = false, posix_ctxt = false;int s_type =0 ;int next_off =0 ;char *name =NULL ;
@@ -2903,6 +2903,27 @@ int smb2_open(struct ksmbd_work *work)return create_smb2_pipe (work); } +if (req->CreateContextsOffset && tcon->posix_extensions) { + context =smb2_find_context_vals (req,SMB2_CREATE_TAG_POSIX ,16 ); +if (IS_ERR (context)) { + rc =PTR_ERR (context); + goto err_out2; + }else if (context) { +struct create_posix *posix = (struct create_posix *)context; + +if (le16_to_cpu (context->DataOffset) + +le32_to_cpu (context->DataLength) < +sizeof (struct create_posix ) -4 ) { + rc = -EINVAL ; + goto err_out2; + } +ksmbd_debug (SMB ,"get posix context\n" ); + + posix_mode =le32_to_cpu (posix->Mode); + posix_ctxt = true; + } + } +if (req->NameLength) { name = smb2_get_name((char *)req + le16_to_cpu(req->NameOffset), le16_to_cpu(req->NameLength),
@@ -2925,9 +2946,11 @@ int smb2_open(struct ksmbd_work *work) goto err_out2; } - rc =ksmbd_validate_filename (name); -if (rc <0 ) - goto err_out2; +if (posix_ctxt == false) { + rc =ksmbd_validate_filename (name); +if (rc <0 ) + goto err_out2; + }if (ksmbd_share_veto_filename (share, name)) { rc = -ENOENT ;
@@ -3085,28 +3108,6 @@ int smb2_open(struct ksmbd_work *work) rc = -EBADF ; goto err_out2; } - -if (tcon->posix_extensions) { - context =smb2_find_context_vals (req, -SMB2_CREATE_TAG_POSIX ,16 ); -if (IS_ERR (context)) { - rc =PTR_ERR (context); - goto err_out2; - }else if (context) { -struct create_posix *posix = - (struct create_posix *)context; -if (le16_to_cpu (context->DataOffset) + -le32_to_cpu (context->DataLength) < -sizeof (struct create_posix ) -4 ) { - rc = -EINVAL ; - goto err_out2; - } -ksmbd_debug (SMB ,"get posix context\n" ); - - posix_mode =le32_to_cpu (posix->Mode); - posix_ctxt =1 ; - } - } }if (ksmbd_override_fsids (work)) {
Signature · 1 line
2.25.1
A message that is not in the archive (sent off-list or not yet received): CAKYAXd9BPqg=0QKrpsOHaVDQkM8=Q6fragLmpTPve=pJdNjovw@rx2.rx-server.de
Hi!
2025-05-27 (火) の 11:57 +0900 に Namjae Jeon さんは書きました:
Quoted 8 lines
Quoted 6 lines · Namjae Jeon
Quoted 3 lines
It's been part of the spec since the beginning. You can find it here:
Right, I found it.
Thanks for your reply.Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16
SMB2_CREATE_POSIX_CONTEXTPhilipp,
Can you confirm if your issue is fixed with the attached patch ?
Thanks!
I can confirm the following behavior after applying the patch:
* Path with "&" is not accessible with mount.smb3 and default options
* Path with "&" is not accessible with mount.smb3 and "nomapposix" option
* Path with "&" is not accessible with mount.smb3 and "unix" option
* Path with "&" is accessible with mount.smb3 and "unix,nomapposix" options
Perhaps "nomapposix" should be the default for the client when "unix" is enabled? Tough call though, might break some backwards compatibility.
Furthermore, in the last case in which the file is accessible, I can only access the file as root. This is because enabling the "unix" mount option leads to the origin UIDs and GIDs being taken over from the host, which do not correspond to anything on my client. I usually set "forceuid,forcegid,uid=...,gid=...,file_mode=0640,dir_mode=0750" on the mount but, for whatever reason (might be intentional? might not be?), these options do nothing at all when combined with "unix". I can sort of get around this by setting "noperm", but it does seem odd that I would have to disable any and all permission checking just to get special characters in my paths working.
Thanks,
Philipp
Namjae Jeon
maintainerQuoted 20 lines · Philipp Kerling
Hi!
2025-05-27 (火) の 11:57 +0900 に Namjae Jeon さんは書きました:
Quoted 8 lines
Quoted 6 lines · Namjae Jeon
Quoted 3 lines
It's been part of the spec since the beginning. You can find it here:
Right, I found it.
Thanks for your reply.Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16
SMB2_CREATE_POSIX_CONTEXTPhilipp,
Can you confirm if your issue is fixed with the attached patch ?
Thanks!
Quoted 10 lines
I can confirm the following behavior after applying the patch:
* Path with "&" is not accessible with mount.smb3 and default options
* Path with "&" is not accessible with mount.smb3 and "nomapposix" option
* Path with "&" is not accessible with mount.smb3 and "unix" option
* Path with "&" is accessible with mount.smb3 and "unix,nomapposix" options
Perhaps "nomapposix" should be the default for the client when "unix" is enabled? Tough call though, might break some backwards compatibility.
I agree that "nomapposix" should be enabled along with "unix" option. You can try to submit a patch for this.
Quoted 11 lines
Furthermore, in the last case in which the file is accessible, I can only access the file as root. This is because enabling the "unix" mount option leads to the origin UIDs and GIDs being taken over from the host, which do not correspond to anything on my client. I usually set "forceuid,forcegid,uid=...,gid=...,file_mode=0640,dir_mode=0750" on the mount but, for whatever reason (might be intentional? might not be?), these options do nothing at all when combined with "unix". I can sort of get around this by setting "noperm", but it does seem odd that I would have to disable any and all permission checking just to get special characters in my paths working.
Please tell me the steps to reproduce it.
Thanks!
Quoted 3 lines
Thanks,
Philipp
A message that is not in the archive (sent off-list or not yet received): CAKYAXd9OQW9oOfjUDWSGmh+b7QtHSc7M=rHhCW6QEsFpEkVFVw@rx2.rx-server.de
2025-06-01 (日) の 23:30 +0900 に Namjae Jeon さんは書きました:
Quoted 38 lines
Quoted 22 lines · Philipp Kerling
Hi!
2025-05-27 (火) の 11:57 +0900 に Namjae Jeon さんは書きました:
Quoted 10 lines
Quoted 7 lines · Namjae Jeon
Quoted 4 lines
It's been part of the spec since the beginning. You can find it
here:Right, I found it.
Thanks for your reply.Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16
SMB2_CREATE_POSIX_CONTEXTPhilipp,
Can you confirm if your issue is fixed with the attached patch ?
Thanks!
Quoted 14 lines
I can confirm the following behavior after applying the patch:
* Path with "&" is not accessible with mount.smb3 and default options
* Path with "&" is not accessible with mount.smb3 and "nomapposix" option
* Path with "&" is not accessible with mount.smb3 and "unix" option
* Path with "&" is accessible with mount.smb3 and "unix,nomapposix"
options
Perhaps "nomapposix" should be the default for the client when "unix"
is enabled? Tough call though, might break some backwards compatibility.
Quoted 2 lines
I agree that "nomapposix" should be enabled along with "unix" option. You can try to submit a patch for this.
OK, I will try.
Quoted 16 lines
Quoted 8 lines
Furthermore, in the last case in which the file is accessible, I can
only access the file as root. This is because enabling the "unix" mount
option leads to the origin UIDs and GIDs being taken over from the host, which do not correspond to anything on my client. I usually set "forceuid,forcegid,uid=...,gid=...,file_mode=0640,dir_mode=0750" onQuoted 8 lines
the
mount but, for whatever reason (might be intentional? might not be?),
these options do nothing at all when combined with "unix". I can sort
of get around this by setting "noperm", but it does seem odd that I would have to disable any and all permission checking just to get special characters in my paths working.
Quoted 1 line
Please tell me the steps to reproduce it.
1. Create a folder on the server and put a file owned by UID 1000,
GID 1000 with mode 0640 into it.
2. Export this folder using ksmbd. For the record, I am using "force
user = <user with uid 1000>", but I don't think the options on
the server matter much.
3. On the client, mount using "mount -t smb3 -o
vers=3.1.1,forceuid,forcegid,uid=1001,gid=1001" and list the
folder -> file will be owned by 1001:10014. Unmount and mount with ",unix" option added -> file will be owned by 1000:1000; most likely forceuid/forcegid is not applied with 3.1.1 POSIX extensions (tested on Linux 6.14.6)
Namjae Jeon
maintainerQuoted 40 lines · Philipp Kerling
2025-06-01 (日) の 23:30 +0900 に Namjae Jeon さんは書きました:
Quoted 38 lines
Quoted 36 lines · Philipp Kerling
Hi!
2025-05-27 (火) の 11:57 +0900 に Namjae Jeon さんは書きました:
Quoted 10 lines
Quoted 7 lines · Namjae Jeon
Quoted 4 lines
It's been part of the spec since the beginning. You can find it
here:Right, I found it.
Thanks for your reply.Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16
SMB2_CREATE_POSIX_CONTEXTPhilipp,
Can you confirm if your issue is fixed with the attached patch ?
Thanks!
I can confirm the following behavior after applying the patch:
* Path with "&" is not accessible with mount.smb3 and default
options
* Path with "&" is not accessible with mount.smb3 and "nomapposix" option
* Path with "&" is not accessible with mount.smb3 and "unix"
option
* Path with "&" is accessible with mount.smb3 and
"unix,nomapposix"
options
Perhaps "nomapposix" should be the default for the client when "unix"
is enabled? Tough call though, might break some backwards compatibility.
Quoted 22 lines
Quoted 2 lines
I agree that "nomapposix" should be enabled along with "unix" option. You can try to submit a patch for this.
OK, I will try.
Quoted 17 lines
Quoted 8 lines
Furthermore, in the last case in which the file is accessible, I can
only access the file as root. This is because enabling the "unix" mount
option leads to the origin UIDs and GIDs being taken over from the host, which do not correspond to anything on my client. I usually set "forceuid,forcegid,uid=...,gid=...,file_mode=0640,dir_mode=0750" onQuoted 8 lines
the
mount but, for whatever reason (might be intentional? might not be?),
these options do nothing at all when combined with "unix". I can sort
of get around this by setting "noperm", but it does seem odd that I would have to disable any and all permission checking just to get special characters in my paths working.Please tell me the steps to reproduce it.
Hi Steve,
Quoted 11 lines
1. Create a folder on the server and put a file owned by UID 1000,
GID 1000 with mode 0640 into it. 2. Export this folder using ksmbd. For the record, I am using "force user = <user with uid 1000>", but I don't think the options on the server matter much. 3. On the client, mount using "mount -t smb3 -o vers=3.1.1,forceuid,forcegid,uid=1001,gid=1001" and list the folder -> file will be owned by 1001:10014. Unmount and mount with ",unix" option added -> file will be owned by 1000:1000; most likely forceuid/forcegid is not applied with 3.1.1 POSIX extensions (tested on Linux 6.14.6)
Could you please answer this question ? (forceuid/forcegid is not applied with 3.1.1 POSIX extensions)
Thanks.
Hi,
2025-05-27 (火) の 11:57 +0900 に Namjae Jeon さんは書きました:
Quoted 22 lines
Quoted 20 lines · Namjae Jeon
Quoted 7 lines · Ralph Boehme
Quoted 5 lines · Namjae Jeon
Quoted 3 lines · Steve French
If the POSIX/Linux context is included in the SMB3.1.1 open then we
mounted with ("linux" or "posix")Quoted 7 lines
Quoted 5 lines
Such a context could be created in
smb2_createcontext like apple context(AAPL).
However, I wonder if there is any plan to add it to SMB3.1.1 posix
extension specification.It's been part of the spec since the beginning. You can find it here:
Right, I found it.
Thanks for your reply.Quoted 1 line
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16
SMB2_CREATE_POSIX_CONTEXTPhilipp,
Can you confirm if your issue is fixed with the attached patch ?
after some more testing, I've found out that there is still (at least) one special character causing problems. It is the ':' (colon), because it is used to distinguish alternate data streams on NTFS, but is a perfectly valid path character in POSIX as well. I have attached a draft patch on top of the current master that fixes the problem on my end. It does mean that alternate data streams cannot be accessed when a posix create context is specified though. Anyway, I guess you can't really have it both ways given the current specification. If you think this is a valid approach, I can submit as a proper patch.
Before (being on the client in an smb3-mounted directory with -o unix,posixpaths):
[philipp@atami smbmnt]$ echo 'hello' > 'a:b'
bash: a:b: No such file or directory
[philipp@atami smbmnt]$ echo 'hello' > 'a' [philipp@atami smbmnt]$ cat a
hello
[philipp@atami smbmnt]$ mv a 'a:b'
mv: cannot move 'a' to 'a:b': Device or resource busy [philipp@atami smbmnt]$ mkdir 'f:g'
mkdir: cannot create directory 'f:g': No such file or directory [philipp@atami smbmnt]$ ls -l | grep 'test'
drwxr-xr-x? 2 root root 23 Aug 11 19:10 test:dir
[philipp@atami smbmnt]$ ls -l 'test:dir'
ls: cannot access 'test:dir': No such file or directory [philipp@atami smbmnt]$
After:
[philipp@atami smbmnt]$ echo 'hello' > 'a:b'
[philipp@atami smbmnt]$ cat 'a:b'
hello
[philipp@atami smbmnt]$ echo 'hello' > 'a'
[philipp@atami smbmnt]$ cat 'a'
hello
[philipp@atami smbmnt]$ mv a 'a:b'
[philipp@atami smbmnt]$ mkdir 'f:g'
[philipp@atami smbmnt]$ ls -l | grep 'test'
drwxr-xr-x 2 root root 23 Aug 11 19:10 test:dir
[philipp@atami smbmnt]$ ls -l 'test:dir'
total 0
-rw-r--r-- 1 root root 0 Aug 11 19:10 a
[philipp@atami smbmnt]$
Best regards,
Philipp
fs/smb/server/smb2pdu.c +14 -11
@@ -2951,18 +2951,19 @@ int smb2_open(struct ksmbd_work *work) }ksmbd_debug (SMB ,"converted name = %s\n" , name); -if (strchr (name,':' )) { -if (!test_share_config_flag (work->tcon->share_conf, -KSMBD_SHARE_FLAG_STREAMS )) { - rc = -EBADF ; - goto err_out2; - } - rc =parse_stream_name (name, &stream_name, &s_type); -if (rc <0 ) - goto err_out2; - }if (posix_ctxt == false) { +if (strchr (name,':' )) { +if (!test_share_config_flag (work->tcon->share_conf, +KSMBD_SHARE_FLAG_STREAMS )) { + rc = -EBADF ; + goto err_out2; + } + rc =parse_stream_name (name, &stream_name, &s_type); +if (rc <0 ) + goto err_out2; + } + rc =ksmbd_validate_filename (name);if (rc <0 ) goto err_out2;
@@ -3443,6 +3444,8 @@ int smb2_open(struct ksmbd_work *work) fp->attrib_only = !(req->DesiredAccess & ~(FILE_READ_ATTRIBUTES_LE |FILE_WRITE_ATTRIBUTES_LE |FILE_SYNCHRONIZE_LE )); + fp->is_posix_ctxt = posix_ctxt; +/* fp should be searchable through ksmbd_inode.m_fp_list * after daccess, saccess, attrib_only, and stream are * initialized.
@@ -5988,7 +5991,7 @@ static int smb2_rename(struct ksmbd_work *work,if (IS_ERR (new_name))return PTR_ERR (new_name); -if (strchr (new_name,':' )) { +if (fp->is_posix_ctxt == false &&strchr (new_name,':' )) {int s_type;char *xattr_stream_name, *stream_name =NULL ;size_t xattr_stream_size;
fs/smb/server/vfs_cache.h +2 -0
@@ -112,6 +112,8 @@ struct ksmbd_file {bool is_durable;bool is_persistent;bool is_resilient; + +bool is_posix_ctxt; }; static inline void set_ctx_actor(struct dir_context *ctx,
Namjae Jeon
maintainerQuoted 2 lines · Philipp Kerling
Hi,
Hi Philipp,
Quoted 30 lines
2025-05-27 (火) の 11:57 +0900 に Namjae Jeon さんは書きました:
Quoted 22 lines
Quoted 20 lines · Namjae Jeon
Quoted 7 lines · Ralph Boehme
Quoted 5 lines · Namjae Jeon
Quoted 3 lines · Steve French
If the POSIX/Linux context is included in the SMB3.1.1 open then we
mounted with ("linux" or "posix")Quoted 7 lines
Quoted 5 lines
Such a context could be created in
smb2_createcontext like apple context(AAPL).
However, I wonder if there is any plan to add it to SMB3.1.1 posix
extension specification.It's been part of the spec since the beginning. You can find it here:
Right, I found it.
Thanks for your reply.Quoted 1 line
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
https://gitlab.com/samba-team/smb3-posix-spec/-/releases
POSIX-SMB2 2.2.13.2.16
SMB2_CREATE_POSIX_CONTEXTPhilipp,
Can you confirm if your issue is fixed with the attached patch ?
Quoted 9 lines
after some more testing, I've found out that there is still (at least) one special character causing problems. It is the ':' (colon), because it is used to distinguish alternate data streams on NTFS, but is a perfectly valid path character in POSIX as well. I have attached a draft patch on top of the current master that fixes the problem on my end. It does mean that alternate data streams cannot be accessed when a posix create context is specified though. Anyway, I guess you can't really have it both ways given the current specification. If you think this is a valid approach, I can submit as a proper patch.
Okay, Looks ok.
Could you submit this patch to the list after filling the patch description ?
Thanks.
Quoted 41 lines
Before (being on the client in an smb3-mounted directory with -o unix,posixpaths):
[philipp@atami smbmnt]$ echo 'hello' > 'a:b'
bash: a:b: No such file or directory
[philipp@atami smbmnt]$ echo 'hello' > 'a' [philipp@atami smbmnt]$ cat a
hello
[philipp@atami smbmnt]$ mv a 'a:b'
mv: cannot move 'a' to 'a:b': Device or resource busy [philipp@atami smbmnt]$ mkdir 'f:g'
mkdir: cannot create directory 'f:g': No such file or directory [philipp@atami smbmnt]$ ls -l | grep 'test'
drwxr-xr-x? 2 root root 23 Aug 11 19:10 test:dir
[philipp@atami smbmnt]$ ls -l 'test:dir'
ls: cannot access 'test:dir': No such file or directory [philipp@atami smbmnt]$After:
[philipp@atami smbmnt]$ echo 'hello' > 'a:b'
[philipp@atami smbmnt]$ cat 'a:b'
hello
[philipp@atami smbmnt]$ echo 'hello' > 'a'
[philipp@atami smbmnt]$ cat 'a'
hello
[philipp@atami smbmnt]$ mv a 'a:b'
[philipp@atami smbmnt]$ mkdir 'f:g'
[philipp@atami smbmnt]$ ls -l | grep 'test'
drwxr-xr-x 2 root root 23 Aug 11 19:10 test:dir
[philipp@atami smbmnt]$ ls -l 'test:dir'
total 0
-rw-r--r-- 1 root root 0 Aug 11 19:10 a
[philipp@atami smbmnt]$Best regards,
Philipp