smb/server: fix some bugs in file name information handling
Subsystems (2)
ChenXiaoSong
reviewercover smb/server: fix some bugs in file name information handling
From: ChenXiaoSong <[email protected]>
ChenXiaoSong (3):
smb/server: fix trailing period in generated short names smb/server: align partial normalized name responses to UTF-16 smb/server: rename smb2_file_alt_name_info to smb2_file_name_info
fs/smb/server/smb2pdu.c | 21 +++++++++++---------- fs/smb/server/smb2pdu.h | 6 ++---- fs/smb/server/smb_common.c | 4 +--- 3 files changed, 14 insertions(+), 17 deletions(-)
Signature · 1 line
2.55.0
ChenXiaoSong
reviewerPATCH 1/3 smb/server: fix trailing period in generated short names
From: ChenXiaoSong <[email protected]>
Reproducer:
1. touch /mnt/file
2. smbinfo filealternatenameinfo /mnt/file
Alternate Name: FILE~9!.
See MS-FSCC 2.1.5.2.1. The base filename MUST be 1-8 characters in length and MUST NOT contain a "." period character.
--- fs/smb/server/smb_common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/smb/server/smb_common.c +1 -3
@@ -523,8 +523,6 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level,* @shortname: destination short filename * * Return: shortname length or 0 when source long name is '.' or '..' -* TODO: Though this function conforms the restriction of 8.3 Filename spec, -* but the result is different with Windows 7's one. need to check. */ int ksmbd_extract_shortname (struct ksmbd_conn *conn,const char *longname,char *shortname)
@@ -588,7 +586,7 @@ int ksmbd_extract_shortname(struct ksmbd_conn *conn, const char *longname,if (dot_present)memcpy (out + baselen +4 , extension,4 );else - out[baselen +4 ] ='\0' ; + out[baselen +3 ] ='\0' ;smbConvertToUTF16 ((__le16 *)shortname, out,PATH_MAX , conn->local_nls,0 ); len =strlen (out) *2 ;
Signature · 1 line
2.55.0
ChenXiaoSong
reviewerPATCH 2/3 smb/server: align partial normalized name responses to UTF-16
In reply to ChenXiaoSongFrom: ChenXiaoSong <[email protected]>
See MS-FSA 2.1.5.12.30.
Set AvailableNameLength to BlockAlignTruncate((OutputBufferSize -
FieldOffset(FILE_NAME_INFORMATION.FileName)), 2).
--- fs/smb/server/smb2pdu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/smb/server/smb2pdu.c +5 -4
@@ -16,6 +16,7 @@#include <linux/mount.h> #include <linux/filelock.h> #include <linux/fileattr.h> +#include <linux/math.h> #include <linux/timekeeping.h> #include <linux/unaligned.h>
@@ -7218,7 +7219,7 @@ static int smb2_get_info_file(struct ksmbd_work *work,struct ksmbd_file *fp;int fileinfoclass =0 ;int rc =0 ; -unsigned int fixed_len; +unsigned int fixed_len, req_output_len;unsigned int id =KSMBD_NO_FID , pid =KSMBD_NO_FID ; if (test_share_config_flag(work->tcon->share_conf,
@@ -7325,6 +7326,7 @@ static int smb2_get_info_file(struct ksmbd_work *work, rc = -EOPNOTSUPP ; }if (!rc) { + req_output_len =le32_to_cpu (req->OutputBufferLength); fixed_len =le32_to_cpu (rsp->OutputBufferLength);switch (fileinfoclass) {case FILE_ALL_INFORMATION :
@@ -7335,14 +7337,13 @@ static int smb2_get_info_file(struct ksmbd_work *work,break ;case FILE_NORMALIZED_NAME_INFORMATION : fixed_len =FILE_NORMALIZED_NAME_INFORMATION_SIZE ; + req_output_len =round_down (req_output_len,2 );break ;case FILE_STREAM_INFORMATION : fixed_len =FILE_STREAM_INFORMATION_SIZE ;break ; } - rc =buffer_check_err (le32_to_cpu (req->OutputBufferLength), - fixed_len, - rsp); + rc =buffer_check_err (req_output_len, fixed_len, rsp); }ksmbd_fd_put (work, fp);
Signature · 1 line
2.55.0
Namjae Jeon
maintainerRe: [PATCH 2/3] smb/server: align partial normalized name responses to UTF-16
fs/smb/server/smb2pdu.c static int smb2_get_info_file(struct ksmbd_work *work, · line 7341
Quoted 6 lines
fs/smb/server/smb2pdu.c +1
-0@@ -7335,14 +7337,13 @@ static int smb2_get_info_file(struct ksmbd_work *work,break ;case FILE_NORMALIZED_NAME_INFORMATION : fixed_len =FILE_NORMALIZED_NAME_INFORMATION_SIZE ; + req_output_len =round_down (req_output_len,2 );break ;
Shouldn’t we apply the same alignment toFILE_ALTERNATE_NAME_INFORMATION as well?
ChenXiaoSong
reviewerRe: [PATCH 2/3] smb/server: align partial normalized name responses to UTF-16
I had the same question. However, the protocol does not specify any alignment requirement for ALTERNATE_NAME, see MS-FSA 2.1.5.12.4: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/5051d021-8d06-4b7e-94e3-55b118193427
Maybe this was missed in the protocol, or is it because an 8.3 filename is at most 12 bytes? See MS-FSCC 2.1.5.2.1: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/18e63b13-ba43-4f5f-a5b7-11e871b71f14
Hopefully Ralph or someone else can explain this.
Some people may not have received the patch. Here is the patch link: https://lore.kernel.org/linux-cifs/[email protected]/
Quoted 2 lines · Namjae Jeon
Shouldn’t we apply the same alignment to
FILE_ALTERNATE_NAME_INFORMATIONas well?
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
ChenXiaoSong
reviewerPATCH 3/3 smb/server: rename smb2_file_alt_name_info to smb2_file_name_info
In reply to ChenXiaoSongFrom: ChenXiaoSong <[email protected]>
FileAlternateNameInformation and FileNormalizedNameInformation use the same structure.
--- fs/smb/server/smb2pdu.c | 12 ++++++------ fs/smb/server/smb2pdu.h | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-)
fs/smb/server/smb2pdu.c +6 -6
@@ -6779,12 +6779,12 @@ static void get_file_alternate_info(struct ksmbd_work *work, void *rsp_org) {struct ksmbd_conn *conn = work->conn; -struct smb2_file_alt_name_info *file_info; +struct smb2_file_name_info *file_info;struct dentry *dentry = fp->filp->f_path.dentry;int conv_len;spin_lock (&dentry->d_lock); - file_info = (struct smb2_file_alt_name_info *)rsp->Buffer; + file_info = (struct smb2_file_name_info *)rsp->Buffer; conv_len =ksmbd_extract_shortname (conn, dentry->d_name.name, file_info->FileName);
@@ -6831,7 +6831,7 @@ static int get_file_normalized_name_info(struct ksmbd_work *work,struct smb2_query_info_rsp *rsp, struct ksmbd_file *fp) { - struct smb2_file_alt_name_info *file_info; + struct smb2_file_name_info *file_info;char *filename, *normalized, *stream_name;int buf_free_len, conv_len, filename_len;
@@ -6865,7 +6865,7 @@ static int get_file_normalized_name_info(struct ksmbd_work *work,return -EINVAL ; } - file_info = (struct smb2_file_alt_name_info *)rsp->Buffer; + file_info = (struct smb2_file_name_info *)rsp->Buffer; conv_len =smbConvertToUTF16 ((__le16 *)file_info->FileName, normalized, filename_len, work->conn->local_nls,0 );
@@ -7333,10 +7333,10 @@ static int smb2_get_info_file(struct ksmbd_work *work, fixed_len =FILE_ALL_INFORMATION_SIZE ;break ;case FILE_ALTERNATE_NAME_INFORMATION : - fixed_len =FILE_ALTERNATE_NAME_INFORMATION_SIZE ; + fixed_len =FILE_NAME_INFORMATION_SIZE ;break ;case FILE_NORMALIZED_NAME_INFORMATION : - fixed_len =FILE_NORMALIZED_NAME_INFORMATION_SIZE ; + fixed_len =FILE_NAME_INFORMATION_SIZE ; req_output_len =round_down (req_output_len,2 );break ;case FILE_STREAM_INFORMATION :
fs/smb/server/smb2pdu.h +2 -4
@@ -199,7 +199,7 @@ struct file_sparse {#define FILE_INTERNAL_INFORMATION_SIZE 8#define FILE_EA_INFORMATION_SIZE 4#define FILE_ACCESS_INFORMATION_SIZE 4 -#define FILE_NAME_INFORMATION_SIZE 9 +#define FILE_NAME_INFORMATION_SIZE 8#define FILE_RENAME_INFORMATION_SIZE 10#define FILE_LINK_INFORMATION_SIZE 11#define FILE_NAMES_INFORMATION_SIZE 12
@@ -211,8 +211,6 @@ struct file_sparse {#define FILE_ALL_INFORMATION_SIZE 104#define FILE_ALLOCATION_INFORMATION_SIZE 19#define FILE_END_OF_FILE_INFORMATION_SIZE 20 -#define FILE_ALTERNATE_NAME_INFORMATION_SIZE 8 -#define FILE_NORMALIZED_NAME_INFORMATION_SIZE 8#define FILE_STREAM_INFORMATION_SIZE 32#define FILE_PIPE_INFORMATION_SIZE 23#define FILE_PIPE_LOCAL_INFORMATION_SIZE 24
@@ -259,7 +257,7 @@ struct smb2_file_alignment_info {__le32 AlignmentRequirement; } __packed; -struct smb2_file_alt_name_info { +struct smb2_file_name_info {__le32 FileNameLength;char FileName[]; } __packed;
Signature · 1 line
2.55.0
Quoted 7 lines · ChenXiaoSong
From: ChenXiaoSong <[email protected]>
ChenXiaoSong (3):
smb/server: fix trailing period in generated short names smb/server: align partial normalized name responses to UTF-16 smb/server: renamesmb2_file_alt_name_infotosmb2_file_name_info
Applied them to #ksmbd-for-next.
Thanks!