ksmbd: allow a filename to contain colons on SMB3.1.1 posix extensions
Subsystems (2)
PATCH 1/1 ksmbd: allow a filename to contain colons on SMB3.1.1 posix extensions
If the client sends SMB2_CREATE_POSIX_CONTEXT to ksmbd, allow the filename to contain a colon (':'). This requires disabling the support for Alternate Data Streams (ADS), which are denoted by a colon-separated suffix to the filename on Windows. This should not be an issue, since this concept is not known to POSIX anyway and the client has to explicitly request a POSIX context to get this behavior.
--- fs/smb/server/smb2pdu.c | 25 ++++++++++++++----------- fs/smb/server/vfs_cache.h | 2 ++ 2 files changed, 16 insertions(+), 11 deletions(-)
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,
Signature · 1 line
2.50.1
Samba allows this with POSIX extensions negotiated (creating file with : in the name) but I am wondering if a better way to solve this (to avoid any confusion with alternate data streams) is to change the client to use SFM_COLON (ie the remap in Unicode where colon is remapped to 0xF022 instead of 0x003A)
Quoted 83 lines · Philipp Kerling
If the client sends
SMB2_CREATE_POSIX_CONTEXTto ksmbd, allow the filename to contain a colon (':'). This requires disabling the support for Alternate Data Streams (ADS), which are denoted by a colon-separated suffix to the filename on Windows. This should not be an issue, since this concept is not known to POSIX anyway and the client has to explicitly request a POSIX context to get this behavior.Signed-off-by Philipp Kerling <[email protected]>--- fs/smb/server/smb2pdu.c | 25 ++++++++++++++----------- fs/smb/server/vfs_cache.h | 2 ++ 2 files changed, 16 insertions(+), 11 deletions(-)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
-1@@ -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, --2.50.1
Signature · 3 lines
Thanks, Steve
This remapping of colon (and other reserved characters) is done by default when not mounting with SMB3.1.1 Linux/POSIX extensions, but presumably would only be needed for colon with the SMB3.1.1 Linux/POSIX extensions (since colon is the only one that is 'required' by the protocol to mean something different)
Quoted 97 lines · Steve French
Samba allows this with POSIX extensions negotiated (creating file with : in the name) but I am wondering if a better way to solve this (to avoid any confusion with alternate data streams) is to change the client to use
SFM_COLON(ie the remap in Unicode where colon is remapped to0xF022instead of0x003A)Quoted 80 lines · Philipp Kerling
If the client sends
SMB2_CREATE_POSIX_CONTEXTto ksmbd, allow the filename to contain a colon (':'). This requires disabling the support for Alternate Data Streams (ADS), which are denoted by a colon-separated suffix to the filename on Windows. This should not be an issue, since this concept is not known to POSIX anyway and the client has to explicitly request a POSIX context to get this behavior.Signed-off-by Philipp Kerling <[email protected]>--- fs/smb/server/smb2pdu.c | 25 ++++++++++++++----------- fs/smb/server/vfs_cache.h | 2 ++ 2 files changed, 16 insertions(+), 11 deletions(-)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
-1@@ -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, --Quoted 3 lines
2.50.1
--
Thanks,Steve
Signature · 3 lines
Thanks, Steve
A message that is not in the archive (sent off-list or not yet received): CAH2r5mtB0aNQMYzUhgu0_xRzkWL1xYoRa6b5a5CiKUhV+WU_QQ@mail.gmail.com
Quoted 1 line · Steve French
Adding samba-technical in case opinions on this
yes. :)
No remapping for POSIX please. That means no streams support for POSIX and that's good.
Quoted 5 lines · Steve French
Samba allows this with POSIX extensions negotiated (creating file with : in the name) but I am wondering if a better way to solve this (to avoid any confusion with alternate data streams) is to change the client to use
SFM_COLON(ie the remap in Unicode where colon is remapped to0xF022instead of0x003A)
No. Only do that mapping to Windows servers.
POSIX servers should properly store the real ':' character.
Quoted 11 lines · Jeremy Allison
Quoted 5 lines · Steve French
Samba allows this with POSIX extensions negotiated (creating file with : in the name) but I am wondering if a better way to solve this (to avoid any confusion with alternate data streams) is to change the client to use
SFM_COLON(ie the remap in Unicode where colon is remapped to0xF022instead of0x003A)No. Only do that mapping to Windows servers.
POSIX servers should properly store the real ':' character.
makes sense
Signature · 3 lines
Thanks, Steve
Quoted 9 lines · Philipp Kerling
If the client sends
SMB2_CREATE_POSIX_CONTEXTto ksmbd, allow the filename to contain a colon (':'). This requires disabling the support for Alternate Data Streams (ADS), which are denoted by a colon-separated suffix to the filename on Windows. This should not be an issue, since this concept is not known to POSIX anyway and the client has to explicitly request a POSIX context to get this behavior.
Applied it to #ksmbd-for-next-next.
Thanks!