cifs: Fix struct FILE_ALL_INFO
Subsystems (2)
PATCH 1/12 cifs: Fix struct FILE_ALL_INFO
struct FILE_ALL_INFO for level 263 (0x107) used by QPathInfo does not have any IndexNumber, AccessFlags, IndexNumber1, CurrentByteOffset, Mode or AlignmentRequirement members. So remove all of them.
Also adjust code in move_cifs_info_to_smb2() function which convers struct FILE_ALL_INFO to struct smb2_file_all_info.
Fixed content of struct FILE_ALL_INFO was verified that is correct against:
* [MS-CIFS] section 2.2.8.3.10 SMB_QUERY_FILE_ALL_INFO
* Samba server implementation of trans2 query file/path for level 263
* Packet structure tests against Windows SMB servers
This change fixes CIFSSMBQFileInfo() and CIFSSMBQPathInfo() functions which directly copy received FILE_ALL_INFO network buffers into kernel structures of FILE_ALL_INFO type.
--- fs/smb/client/cifsglob.h | 12 +++++++----- fs/smb/client/cifspdu.h | 6 ------ 2 files changed, 7 insertions(+), 11 deletions(-)
fs/smb/client/cifsglob.h +7 -5
@@ -2216,11 +2216,13 @@ static inline size_t ntlmssp_workstation_name_size(const struct cifs_ses *ses)static inline void move_cifs_info_to_smb2 (struct smb2_file_all_info *dst,const FILE_ALL_INFO *src) { -memcpy (dst, src, (size_t )((u8 *)&src->AccessFlags - (u8 *)src)); - dst->AccessFlags = src->AccessFlags; - dst->CurrentByteOffset = src->CurrentByteOffset; - dst->Mode = src->Mode; - dst->AlignmentRequirement = src->AlignmentRequirement; +memcpy (dst, src, (size_t )((u8 *)&src->EASize - (u8 *)src)); + dst->IndexNumber =0 ; + dst->EASize = src->EASize; + dst->AccessFlags =0 ; + dst->CurrentByteOffset =0 ; + dst->Mode =0 ; + dst->AlignmentRequirement =0 ; dst->FileNameLength = src->FileNameLength; }
fs/smb/client/cifspdu.h +0 -6
@@ -2294,13 +2294,7 @@ typedef struct { /* data block encoding of response to level 263 QPathInfo */__u8 DeletePending;__u8 Directory;__u16 Pad2; -__le64 IndexNumber;__le32 EASize; -__le32 AccessFlags; -__u64 IndexNumber1; -__le64 CurrentByteOffset; -__le32 Mode; -__le32 AlignmentRequirement;__le32 FileNameLength;union {char __pad;
Signature · 1 line
2.20.1
PATCH 2/12 cifs: Fix calling CIFSFindFirst() for root path without msearch
To query root path (without msearch wildcard) it is needed to send pattern "\" instead of "" (empty string).
This allows to use CIFSFindFirst() to query information about root path.
--- fs/smb/client/cifssmb.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/smb/client/cifssmb.c +10 -0
@@ -4108,6 +4108,12 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, pSMB->FileName[name_len] =0 ; pSMB->FileName[name_len+1 ] =0 ; name_len +=2 ; + }else if (!searchName[0 ]) { + pSMB->FileName[0 ] =CIFS_DIR_SEP (cifs_sb); + pSMB->FileName[1 ] =0 ; + pSMB->FileName[2 ] =0 ; + pSMB->FileName[3 ] =0 ; + name_len =4 ; } }else { name_len =copy_path_name (pSMB->FileName, searchName);
@@ -4119,6 +4125,10 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, pSMB->FileName[name_len] ='*' ; pSMB->FileName[name_len+1 ] =0 ; name_len +=2 ; + }else if (!searchName[0 ]) { + pSMB->FileName[0 ] =CIFS_DIR_SEP (cifs_sb); + pSMB->FileName[1 ] =0 ; + name_len =2 ; } }
Signature · 1 line
2.20.1
PATCH 3/12 cifs: Optimize CIFSFindFirst() response when not searching
In reply to Pali RohárWhen not searching for child entries with msearch wildcard pattern then ask server just for one output entry. There is no need to ask for more entries as we are interested only for one search result, as we are doing query on path.
--- fs/smb/client/cifssmb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifssmb.c +1 -1
@@ -4155,7 +4155,7 @@ CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon, pSMB->SearchAttributes =cpu_to_le16 (ATTR_READONLY |ATTR_HIDDEN |ATTR_SYSTEM |ATTR_DIRECTORY ); - pSMB->SearchCount =cpu_to_le16 (CIFSMaxBufSize/sizeof (FILE_UNIX_INFO )); + pSMB->SearchCount =cpu_to_le16 (msearch ? CIFSMaxBufSize/sizeof (FILE_UNIX_INFO ) :1 ); pSMB->SearchFlags =cpu_to_le16 (search_flags); pSMB->InformationLevel =cpu_to_le16 (psrch_inf->info_level);
Signature · 1 line
2.20.1
PATCH 4/12 cifs: Fix and improve cifs_is_path_accessible() function
In reply to Pali RohárDo not call SMBQueryInformation() command for path with SMB wildcard characters on non-UNICODE connection because server expands wildcards. Function cifs_is_path_accessible() needs to check if the real path exists and must not expand wildcard characters.
Do not dynamically allocate memory for small FILE_ALL_INFO structure and instead allocate it on the stack. This structure is allocated on stack by all other functions.
When CAP_NT_SMBS was not negotiated then do not issue CIFSSMBQPathInfo() command. This command returns failure by non-NT Win9x SMB servers, so there is no need try it. The purpose of cifs_is_path_accessible() function is just to check if the path is accessible, so SMBQueryInformation() for old servers is enough.
--- fs/smb/client/smb1ops.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
fs/smb/client/smb1ops.c +16 -10
@@ -520,21 +520,27 @@ static int cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon, struct cifs_sb_info *cifs_sb, const char *full_path) { - int rc; -FILE_ALL_INFO *file_info; + int rc = -EOPNOTSUPP; +FILE_ALL_INFO file_info; - file_info =kmalloc (sizeof (FILE_ALL_INFO ),GFP_KERNEL ); -if (file_info ==NULL ) -return -ENOMEM ; +if (tcon->ses->capabilities &CAP_NT_SMBS ) + rc =CIFSSMBQPathInfo (xid, tcon, full_path, &file_info, +0 /* not legacy */ , cifs_sb->local_nls, +cifs_remap (cifs_sb)); - rc =CIFSSMBQPathInfo (xid, tcon, full_path, file_info, -0 /* not legacy */ , cifs_sb->local_nls, -cifs_remap (cifs_sb)); +/* +* Non-UNICODE variant of fallback functions below expands wildcards, +* so they cannot be used for querying paths with wildcard characters. +* Therefore for such paths returns -ENOENT as they cannot exist. +*/ +if ((rc == -EOPNOTSUPP || rc == -EINVAL ) && + !(tcon->ses->capabilities &CAP_UNICODE ) && +strpbrk (full_path,"*?\"><" )) + rc = -ENOENT ;if (rc == -EOPNOTSUPP || rc == -EINVAL ) - rc =SMBQueryInformation (xid, tcon, full_path, file_info, + rc =SMBQueryInformation (xid, tcon, full_path, &file_info, cifs_sb->local_nls,cifs_remap (cifs_sb)); -kfree (file_info);return rc; }
Signature · 1 line
2.20.1
PATCH 5/12 cifs: Fix cifs_query_path_info() for Windows NT servers
In reply to Pali RohárFor TRANS2 QUERY_PATH_INFO request when the path does not exist, the Windows NT SMB server returns error response STATUS_OBJECT_NAME_NOT_FOUND or ERRDOS/ERRbadfile without the SMBFLG_RESPONSE flag set. Similarly it returns STATUS_DELETE_PENDING when the file is being deleted. And looks like that any error response from TRANS2 QUERY_PATH_INFO does not have SMBFLG_RESPONSE flag set.
So relax check in check_smb_hdr() for detecting if the packet is response for this special case.
This change fixes stat() operation against Windows NT SMB servers and also all operations which depends on -ENOENT result from stat like creat() or mkdir().
--- fs/smb/client/misc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/smb/client/misc.c +8 -0
@@ -323,6 +323,14 @@ check_smb_hdr(struct smb_hdr *smb)if (smb->Command ==SMB_COM_LOCKING_ANDX )return 0 ; +/* +* Windows NT server returns error resposne (e.g. STATUS_DELETE_PENDING +* or STATUS_OBJECT_NAME_NOT_FOUND or ERRDOS/ERRbadfile or any other) +* for some TRANS2 requests without the RESPONSE flag set in header. +*/ +if (smb->Command ==SMB_COM_TRANSACTION2 && smb->Status.CifsError !=0 ) +return 0 ; +cifs_dbg (VFS ,"Server sent request, not response. mid=%u\n" ,get_mid (smb));return 1 ;
Signature · 1 line
2.20.1
PATCH 6/12 cifs: Fix and improve cifs_query_path_info() and cifs_query_file_info()
In reply to Pali RohárWhen CAP_NT_SMBS was not negotiated then do not issue CIFSSMBQPathInfo() and CIFSSMBQFileInfo() commands. CIFSSMBQPathInfo() is not supported by non-NT Win9x SMB server and CIFSSMBQFileInfo() returns from Win9x SMB server bogus data in Attributes field (for example lot of files are marked as reparse points, even Win9x does not support them and read-only bit is not marked for read-only files). Correct information is returned by CIFSFindFirst() or SMBQueryInformation() command.
So as a fallack in cifs_query_path_info() function use CIFSFindFirst() with SMB_FIND_FILE_FULL_DIRECTORY_INFO level which is supported by both NT and non-NT servers and as a last option use SMBQueryInformation() as it was before.
And in function cifs_query_file_info() immediately returns -EOPNOTSUPP when not communicating with NT server. Client then revalidate inode entry by the cifs_query_path_info() call, which is working fine. So fstat() syscall on already opened file will receive correct information.
Note that both fallback functions in non-UNICODE mode expands wildcards. Therefore those fallback functions cannot be used on paths which contain SMB wildcard characters (* ? " > <).
CIFSFindFirst() returns all 4 time attributes as opposite of SMBQueryInformation() which returns only one.
With this change it is possible to query all 4 times attributes from Win9x server and at the same time, client minimize sending of unsupported commands to server.
--- fs/smb/client/smb1ops.c | 78 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 7 deletions(-)
fs/smb/client/smb1ops.c +71 -7
@@ -550,19 +550,76 @@ static int cifs_query_path_info(const unsigned int xid,const char *full_path, struct cifs_open_info_data *data) { - int rc; + int rc = -EOPNOTSUPP;FILE_ALL_INFO fi = {}; +FILE_FULL_DIRECTORY_INFO *di; +struct cifs_search_info search_info = {}; data->reparse_point = false; data->adjust_tz = false; -/* could do find first instead but this returns more info */ - rc =CIFSSMBQPathInfo (xid, tcon, full_path, &fi,0 /* not legacy */ , cifs_sb->local_nls, -cifs_remap (cifs_sb));/* -* BB optimize code so we do not make the above call when server claims -* no NT SMB support and the above call failed at least once - set flag -* in tcon or mount. +* First try CIFSSMBQPathInfo() function which returns more info +* (NumberOfLinks) than CIFSFindFirst() fallback function. +* Some servers like Win9x do not support SMB_QUERY_FILE_ALL_INFO over +* TRANS2_QUERY_PATH_INFORMATION, but supports it with filehandle over +* TRANS2_QUERY_FILE_INFORMATION (function CIFSSMBQFileInfo(). But SMB +* Open command on non-NT servers works only for files, does not work +* for directories. And moreover Win9x SMB server returns bogus data in +* SMB_QUERY_FILE_ALL_INFO Attributes field. So for non-NT servers, +* do not even use CIFSSMBQPathInfo() or CIFSSMBQFileInfo() function. +*/ +if (tcon->ses->capabilities &CAP_NT_SMBS ) + rc =CIFSSMBQPathInfo (xid, tcon, full_path, &fi,0 /* not legacy */ , + cifs_sb->local_nls,cifs_remap (cifs_sb)); + +/* +* Non-UNICODE variant of fallback functions below expands wildcards, +* so they cannot be used for querying paths with wildcard characters. +* Therefore for such paths returns -ENOENT as they cannot exist. +*/ +if ((rc == -EOPNOTSUPP || rc == -EINVAL ) && + !(tcon->ses->capabilities &CAP_UNICODE ) && +strpbrk (full_path,"*?\"><" )) + rc = -ENOENT ; + +/* +* Then fallback to CIFSFindFirst() which works also with non-NT servers +* but does not does not provide NumberOfLinks. +*/ +if (rc == -EOPNOTSUPP || rc == -EINVAL ) { + search_info.info_level =SMB_FIND_FILE_FULL_DIRECTORY_INFO ; + rc =CIFSFindFirst (xid, tcon, full_path, cifs_sb,NULL , +CIFS_SEARCH_CLOSE_ALWAYS |CIFS_SEARCH_CLOSE_AT_END , + &search_info, false); +if (rc ==0 ) { + di = (FILE_FULL_DIRECTORY_INFO *)search_info.srch_entries_start; + fi.CreationTime = di->CreationTime; + fi.LastAccessTime = di->LastAccessTime; + fi.LastWriteTime = di->LastWriteTime; + fi.ChangeTime = di->ChangeTime; + fi.Attributes = di->ExtFileAttributes; + fi.AllocationSize = di->AllocationSize; + fi.EndOfFile = di->EndOfFile; + fi.EASize = di->EaSize; + fi.NumberOfLinks =cpu_to_le32 (1 ); + fi.DeletePending =0 ; + fi.Directory = !!(le32_to_cpu (di->ExtFileAttributes) &ATTR_DIRECTORY ); +cifs_buf_release (search_info.ntwrk_buf_start); + }else if (!full_path[0 ]) { +/* +* CIFSFindFirst() does not work on root path if the +* root path was exported on the server from the top +* level path (drive letter). +*/ + rc = -EOPNOTSUPP ; + } + } + +/* +* If everything failed then fallback to the legacy SMB command +* SMB_COM_QUERY_INFORMATION which works with all servers, but +* provide just few information. */ if ((rc == -EOPNOTSUPP) || (rc == -EINVAL)) { rc = SMBQueryInformation(xid, tcon, full_path, &fi, cifs_sb->local_nls,
@@ -646,6 +703,13 @@ static int cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,int rc;FILE_ALL_INFO fi = {}; +/* +* CIFSSMBQFileInfo() for non-NT servers returns bogus data in +* Attributes fields. So do not use this command for non-NT servers. +*/ +if (!(tcon->ses->capabilities &CAP_NT_SMBS )) +return -EOPNOTSUPP ; +if (cfile->symlink_target) { data->symlink_target =kstrdup (cfile->symlink_target,GFP_KERNEL );if (!data->symlink_target)
Signature · 1 line
2.20.1
PATCH 7/12 cifs: Improve SMB1 stat() to work also for paths in DELETE_PENDING state
In reply to Pali RohárWindows NT SMB server may return -EBUSY (STATUS_DELETE_PENDING) from CIFSSMBQPathInfo() function for files which are in DELETE_PENDING state. When this happens, it is still possible to use CIFSFindFirst() fallback. So allow to use CIFSFindFirst() fallback also for -EBUSY error.
This change fixed stat() to work also against Windows Server 2022 for files in DELETE_PENDING state.
--- fs/smb/client/smb1ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/smb1ops.c +2 -2
@@ -578,7 +578,7 @@ static int cifs_query_path_info(const unsigned int xid,* so they cannot be used for querying paths with wildcard characters. * Therefore for such paths returns -ENOENT as they cannot exist. */ -if ((rc == -EOPNOTSUPP || rc == -EINVAL ) && +if ((rc == -EOPNOTSUPP || rc == -EINVAL || rc == -EBUSY ) && !(tcon->ses->capabilities &CAP_UNICODE ) &&strpbrk (full_path,"*?\"><" )) rc = -ENOENT ;
@@ -587,7 +587,7 @@ static int cifs_query_path_info(const unsigned int xid,* Then fallback to CIFSFindFirst() which works also with non-NT servers * but does not does not provide NumberOfLinks. */ -if (rc == -EOPNOTSUPP || rc == -EINVAL ) { +if (rc == -EOPNOTSUPP || rc == -EINVAL || rc == -EBUSY ) { search_info.info_level =SMB_FIND_FILE_FULL_DIRECTORY_INFO ; rc = CIFSFindFirst(xid, tcon, full_path, cifs_sb, NULL, CIFS_SEARCH_CLOSE_ALWAYS | CIFS_SEARCH_CLOSE_AT_END,
Signature · 1 line
2.20.1
PATCH 9/12 cifs: Allow fallback code in smb_set_file_info() also for directories
In reply to Pali RohárOn NT systems, it is possible to do SMB open call also for directories. Open argument CREATE_NOT_DIR disallows opening directories. So in fallback code path in smb_set_file_info() remove CREATE_NOT_DIR restriction to allow it also for directories.
Similar fallback is implemented also in CIFSSMBSetPathInfoFB() function and this function already allows to call operation for directories.
--- fs/smb/client/smb1ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb1ops.c +1 -1
@@ -915,7 +915,7 @@ smb_set_file_info(struct inode *inode, const char *full_path, .tcon = tcon, .cifs_sb = cifs_sb, .desired_access = SYNCHRONIZE | FILE_WRITE_ATTRIBUTES, - .create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR), + .create_options = cifs_create_options(cifs_sb, 0), .disposition = FILE_OPEN, .path = full_path, .fid = &fid,
Signature · 1 line
2.20.1
PATCH 10/12 cifs: Fix changing times and read-only attr over SMB1 smb_set_file_info() function
In reply to Pali RohárFunction CIFSSMBSetPathInfo() is not supported by non-NT servers and returns error. Fallback code via open filehandle and CIFSSMBSetFileInfo() does not work neither because CIFS_open() works also only on NT server.
Therefore currently the whole smb_set_file_info() function as a SMB1 callback for the ->set_file_info() does not work with older non-NT SMB servers, like Win9x and others.
This change implements fallback code in smb_set_file_info() which will works with any server and allows to change time values and also to set or clear read-only attributes.
To make existing fallback code via CIFSSMBSetFileInfo() working with also non-NT servers, it is needed to change open function from CIFS_open() (which is NT specific) to cifs_open_file() which works with any server (this is just a open wrapper function which choose the correct open function supported by the server).
CIFSSMBSetFileInfo() is working also on non-NT servers, but zero time values are not treated specially. So first it is needed to fill all time values if some of them are missing, via cifs_query_path_info() call.
There is another issue, opening file in write-mode (needed for changing attributes) is not possible when the file has read-only attribute set. The only option how to clear read-only attribute is via SMB_COM_SETATTR command. And opening directory is not possible neither and here the SMB_COM_SETATTR command is the only option how to change attributes. And CIFSSMBSetFileInfo() does not honor setting read-only attribute, so for setting is also needed to use SMB_COM_SETATTR command.
Existing code in cifs_query_path_info() is already using SMB_COM_GETATTR as a fallback code path (function SMBQueryInformation()), so introduce a new function SMBSetInformation which will implement SMB_COM_SETATTR command.
My testing showed that Windows XP SMB1 client is also using SMB_COM_SETATTR command for setting or clearing read-only attribute against non-NT server. So this can prove that this is the correct way how to do it.
With this change it is possible set all 4 time values and all attributes, including clearing and setting read-only bit on non-NT SMB servers. Tested against Win98 SMB1 server.
This change fixes "touch" command which was failing when called on existing file. And fixes also "chmod +w" and "chmod -w" commands which were also failing (as they are changing read-only attribute).
Note that this change depends on following change "cifs: Improve cifs_query_path_info() and cifs_query_file_info()" as it require to query all 4 time attribute values.
--- fs/smb/client/cifspdu.h | 3 +- fs/smb/client/cifsproto.h | 4 ++ fs/smb/client/cifssmb.c | 57 +++++++++++++++++++ fs/smb/client/smb1ops.c | 112 +++++++++++++++++++++++++++++++++++--- 4 files changed, 165 insertions(+), 11 deletions(-)
fs/smb/client/cifspdu.h +1 -2
@@ -1270,8 +1270,7 @@ typedef struct smb_com_query_information_rsp { typedef struct smb_com_setattr_req { struct smb_hdr hdr; /* wct = 8 */ __le16 attr; - __le16 time_low; - __le16 time_high; + __le32 last_write_time; __le16 reserved[5]; /* must be zero */ __u16 ByteCount; __u8 BufferFormat; /* 4 = ASCII */
fs/smb/client/cifsproto.h +4 -0
@@ -392,6 +392,10 @@ extern int CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon);extern int CIFSSMBQFSPosixInfo (const unsigned int xid,struct cifs_tcon *tcon,struct kstatfs *FSData); +extern int SMBSetInformation (const unsigned int xid,struct cifs_tcon *tcon, +const char *fileName,__le32 attributes,__le64 write_time, +const struct nls_table *nls_codepage, +struct cifs_sb_info *cifs_sb); extern int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const FILE_BASIC_INFO *data, const struct nls_table *nls_codepage,
fs/smb/client/cifssmb.c +57 -0
63 lines not on this page · raw message
fs/smb/client/smb1ops.c +103 -9
149 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 12/12 cifs: Remove CIFSSMBSetPathInfoFB() fallback function
In reply to Pali RohárThis fallback function CIFSSMBSetPathInfoFB() is called only from CIFSSMBSetPathInfo() function. CIFSSMBSetPathInfo() is used in smb_set_file_info() which contains all required fallback code, including fallback via filehandle.
So the CIFSSMBSetPathInfoFB() is just code duplication, which is not needed anymore. Therefore remove it.
This change depends on other changes which are extending cifs_mkdir_setinfo() and smb_set_file_info() functions.
--- fs/smb/client/cifssmb.c | 36 ------------------------------------ 1 file changed, 36 deletions(-)
fs/smb/client/cifssmb.c +0 -36
@@ -5478,38 +5478,6 @@ CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon,return rc; } -static int -CIFSSMBSetPathInfoFB (const unsigned int xid,struct cifs_tcon *tcon, -const char *fileName,const FILE_BASIC_INFO *data, -const struct nls_table *nls_codepage, -struct cifs_sb_info *cifs_sb) -{ -int oplock =0 ; -struct cifs_open_parms oparms; -struct cifs_fid fid; -int rc; - - oparms = (struct cifs_open_parms ) { - .tcon = tcon, - .cifs_sb = cifs_sb, - .desired_access =GENERIC_WRITE , - .create_options =cifs_create_options (cifs_sb,0 ), - .disposition =FILE_OPEN , - .path = fileName, - .fid = &fid, - }; - - rc =CIFS_open (xid, &oparms, &oplock,NULL ); -if (rc) - goto out; - - rc =CIFSSMBSetFileInfo (xid, tcon, data, fid.netfid, current->tgid); -CIFSSMBClose (xid, tcon, fid.netfid); -out: - -return rc; -} - int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon, const char *fileName, const FILE_BASIC_INFO *data,
@@ -5586,10 +5554,6 @@ CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon,if (rc == -EAGAIN ) goto SetTimesRetry; -if (rc == -EOPNOTSUPP ) -return CIFSSMBSetPathInfoFB (xid, tcon, fileName, data, - nls_codepage, cifs_sb); -return rc; }
Signature · 1 line
2.20.1
PATCH 8/12 cifs: Remove code for querying FILE_INFO_STANDARD via CIFSSMBQPathInfo()
In reply to Pali RohárQuerying FILE_INFO_STANDARD structure via SMB_QUERY_FILE_ALL_INFO level over TRANS2_QUERY_PATH_INFORMATION or TRANS2_QUERY_FILE_INFORMATION command (implemented in CIFSSMBQPathInfo() when called with argument legacy=true) is mostly unusable.
Win9x SMB server returns over those commands the FILE_INFO_STANDARD structure with swapped TIME and DATE fields, compared with [MS-CIFS] spec and Samba server implementation. Therefore this command cannot be used unless we know against which server implementation we are connected.
There are already two fallback mechanisms for querying information about path which are working correctly against Samba, NT and Win9x servers:CIFSFindFirst() and SMBQueryInformation() commands.
So remove TRANS2_QUERY_PATH_INFORMATION/SMB_QUERY_FILE_ALL_INFO code from CIFSSMBQPathInfo() function, when the function is called with legacy=true. Note that there is no use of CIFSSMBQPathInfo(legacy=true) anymore.
--- fs/smb/client/cifsproto.h | 1 - fs/smb/client/cifssmb.c | 22 +++------------------- fs/smb/client/smb1ops.c | 4 ++-- 3 files changed, 5 insertions(+), 22 deletions(-)
fs/smb/client/cifsproto.h +0 -1
@@ -351,7 +351,6 @@ extern int CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon, u16 netfid, FILE_ALL_INFO *pFindData);extern int CIFSSMBQPathInfo (const unsigned int xid,struct cifs_tcon *tcon,const char *search_Name,FILE_ALL_INFO *data, -int legacy/* whether to use old info level */ ,const struct nls_table *nls_codepage,int remap); extern int SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon, const char *search_name, FILE_ALL_INFO *data,
fs/smb/client/cifssmb.c +3 -19
@@ -3816,7 +3816,6 @@ CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon,int CIFSSMBQPathInfo (const unsigned int xid,struct cifs_tcon *tcon,const char *search_name,FILE_ALL_INFO *data, -int legacy/* old style infolevel */ ,const struct nls_table *nls_codepage,int remap) {/* level 263 SMB_QUERY_FILE_ALL_INFO */
@@ -3864,10 +3863,7 @@ CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon, byte_count = params +1 /* pad */ ; pSMB->TotalParameterCount =cpu_to_le16 (params); pSMB->ParameterCount = pSMB->TotalParameterCount; -if (legacy) - pSMB->InformationLevel =cpu_to_le16 (SMB_INFO_STANDARD ); -else - pSMB->InformationLevel =cpu_to_le16 (SMB_QUERY_FILE_ALL_INFO ); + pSMB->InformationLevel =cpu_to_le16 (SMB_QUERY_FILE_ALL_INFO ); pSMB->Reserved4 =0 ;inc_rfc1001_len (pSMB, byte_count); pSMB->ByteCount =cpu_to_le16 (byte_count);
@@ -3881,25 +3877,13 @@ CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon,if (rc)/* BB add auto retry on EOPNOTSUPP? */ rc = -EIO ; -else if (!legacy &&get_bcc (&pSMBr->hdr) <40 ) +else if (get_bcc (&pSMBr->hdr) <40 ) rc = -EIO ;/* bad smb */ -else if (legacy &&get_bcc (&pSMBr->hdr) <24 ) - rc = -EIO ;/* 24 or 26 expected but we do not read -last field */ else if (data) {int size;__u16 data_offset =le16_to_cpu (pSMBr->t2.DataOffset); -/* -* On legacy responses we do not read the last field, -* EAsize, fortunately since it varies by subdialect and -* also note it differs on Set vs Get, ie two bytes or 4 -* bytes depending but we don't care here. -*/ -if (legacy) - size =sizeof (FILE_INFO_STANDARD ); -else - size =sizeof (FILE_ALL_INFO ); + size =sizeof (FILE_ALL_INFO );memcpy ((char *) data, (char *) &pSMBr->hdr.Protocol + data_offset, size); }else
fs/smb/client/smb1ops.c +2 -2
@@ -525,7 +525,7 @@ cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,if (tcon->ses->capabilities &CAP_NT_SMBS ) rc =CIFSSMBQPathInfo (xid, tcon, full_path, &file_info, -0 /* not legacy */ , cifs_sb->local_nls, + cifs_sb->local_nls,cifs_remap (cifs_sb));/*
@@ -570,7 +570,7 @@ static int cifs_query_path_info(const unsigned int xid,* do not even use CIFSSMBQPathInfo() or CIFSSMBQFileInfo() function. */ if (tcon->ses->capabilities &CAP_NT_SMBS ) - rc =CIFSSMBQPathInfo (xid, tcon, full_path, &fi,0 /* not legacy */ , + rc =CIFSSMBQPathInfo (xid, tcon, full_path, &fi, cifs_sb->local_nls,cifs_remap (cifs_sb));/*
Signature · 1 line
2.20.1
PATCH 11/12 cifs: Add fallback code path for cifs_mkdir_setinfo()
In reply to Pali RohárUse SMBSetInformation() as a fallback function (when CIFSSMBSetPathInfo() fails) which can set attribudes on the directory, including changing read-only attribute.
--- fs/smb/client/smb1ops.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/smb/client/smb1ops.c +5 -0
@@ -800,6 +800,11 @@ cifs_mkdir_setinfo(struct inode *inode, const char *full_path, info.Attributes =cpu_to_le32 (dosattrs); rc =CIFSSMBSetPathInfo (xid, tcon, full_path, &info, cifs_sb->local_nls, cifs_sb); +if (rc == -EOPNOTSUPP || rc == -EINVAL ) + rc =SMBSetInformation (xid, tcon, full_path, + info.Attributes, +0 /* do not change write time */ , + cifs_sb->local_nls, cifs_sb);if (rc ==0 ) cifsInode->cifsAttrs = dosattrs; }
Signature · 1 line
2.20.1
PATCH v2 1/1 cifs: Fix and improve cifs_query_path_info() and cifs_query_file_info()
In reply to Pali RohárWhen CAP_NT_SMBS was not negotiated then do not issue CIFSSMBQPathInfo() and CIFSSMBQFileInfo() commands. CIFSSMBQPathInfo() is not supported by non-NT Win9x SMB server and CIFSSMBQFileInfo() returns from Win9x SMB server bogus data in Attributes field (for example lot of files are marked as reparse points, even Win9x does not support them and read-only bit is not marked for read-only files). Correct information is returned by CIFSFindFirst() or SMBQueryInformation() command.
So as a fallback in cifs_query_path_info() function use CIFSFindFirst() with SMB_FIND_FILE_FULL_DIRECTORY_INFO level which is supported by both NT and non-NT servers and as a last option use SMBQueryInformation() as it was before.
And in function cifs_query_file_info() immediately returns -EOPNOTSUPP when not communicating with NT server. Client then revalidate inode entry by the cifs_query_path_info() call, which is working fine. So fstat() syscall on already opened file will receive correct information.
Note that both fallback functions in non-UNICODE mode expands wildcards. Therefore those fallback functions cannot be used on paths which contain SMB wildcard characters (* ? " > <).
CIFSFindFirst() returns all 4 time attributes as opposite of SMBQueryInformation() which returns only one.
With this change it is possible to query all 4 times attributes from Win9x server and at the same time, client minimize sending of unsupported commands to server.
---
Changes in v2:
* Handle both possible SMB_FIND_FILE_INFO_STANDARD and SMB_FIND_FILE_FULL_DIRECTORY_INFO levels (based on cap_nt_find)
* Fix non_unicode_wildcard, required for follow up v2 change:
cifs: Improve SMB1 stat() to work also for paths in DELETE_PENDING state
--- fs/smb/client/smb1ops.c | 103 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 8 deletions(-)
fs/smb/client/smb1ops.c +95 -8
@@ -550,24 +550,104 @@ static int cifs_query_path_info(const unsigned int xid,const char *full_path, struct cifs_open_info_data *data) { - int rc; + int rc = -EOPNOTSUPP;FILE_ALL_INFO fi = {}; +struct cifs_search_info search_info = {}; +bool non_unicode_wildcard = false; data->reparse_point = false; data->adjust_tz = false; -/* could do find first instead but this returns more info */ - rc =CIFSSMBQPathInfo (xid, tcon, full_path, &fi,0 /* not legacy */ , cifs_sb->local_nls, -cifs_remap (cifs_sb));/* -* BB optimize code so we do not make the above call when server claims -* no NT SMB support and the above call failed at least once - set flag -* in tcon or mount. +* First try CIFSSMBQPathInfo() function which returns more info +* (NumberOfLinks) than CIFSFindFirst() fallback function. +* Some servers like Win9x do not support SMB_QUERY_FILE_ALL_INFO over +* TRANS2_QUERY_PATH_INFORMATION, but supports it with filehandle over +* TRANS2_QUERY_FILE_INFORMATION (function CIFSSMBQFileInfo(). But SMB +* Open command on non-NT servers works only for files, does not work +* for directories. And moreover Win9x SMB server returns bogus data in +* SMB_QUERY_FILE_ALL_INFO Attributes field. So for non-NT servers, +* do not even use CIFSSMBQPathInfo() or CIFSSMBQFileInfo() function. */ -if ((rc == -EOPNOTSUPP ) || (rc == -EINVAL )) { +if (tcon->ses->capabilities &CAP_NT_SMBS ) + rc =CIFSSMBQPathInfo (xid, tcon, full_path, &fi,0 /* not legacy */ , + cifs_sb->local_nls,cifs_remap (cifs_sb)); + +/* +* Non-UNICODE variant of fallback functions below expands wildcards, +* so they cannot be used for querying paths with wildcard characters. +*/ +if (rc && !(tcon->ses->capabilities &CAP_UNICODE ) &&strpbrk (full_path,"*?\"><" )) + non_unicode_wildcard = true; + +/* +* Then fallback to CIFSFindFirst() which works also with non-NT servers +* but does not does not provide NumberOfLinks. +*/ +if ((rc == -EOPNOTSUPP || rc == -EINVAL ) && + !non_unicode_wildcard) { +if (!(tcon->ses->capabilities & tcon->ses->server->vals->cap_nt_find)) + search_info.info_level =SMB_FIND_FILE_INFO_STANDARD ; +else + search_info.info_level =SMB_FIND_FILE_FULL_DIRECTORY_INFO ; + rc =CIFSFindFirst (xid, tcon, full_path, cifs_sb,NULL , +CIFS_SEARCH_CLOSE_ALWAYS |CIFS_SEARCH_CLOSE_AT_END , + &search_info, false); +if (rc ==0 ) { +if (!(tcon->ses->capabilities & tcon->ses->server->vals->cap_nt_find)) { +FIND_FILE_STANDARD_INFO *di; +int offset = tcon->ses->server->timeAdj; + + di = (FIND_FILE_STANDARD_INFO *)search_info.srch_entries_start; + fi.CreationTime =cpu_to_le64 (cifs_UnixTimeToNT (cnvrtDosUnixTm ( + di->CreationDate, di->CreationTime, offset))); + fi.LastAccessTime =cpu_to_le64 (cifs_UnixTimeToNT (cnvrtDosUnixTm ( + di->LastAccessDate, di->LastAccessTime, offset))); + fi.LastWriteTime =cpu_to_le64 (cifs_UnixTimeToNT (cnvrtDosUnixTm ( + di->LastWriteDate, di->LastWriteTime, offset))); + fi.ChangeTime = fi.LastWriteTime; + fi.Attributes =cpu_to_le32 (le16_to_cpu (di->Attributes)); + fi.AllocationSize =cpu_to_le64 (le32_to_cpu (di->AllocationSize)); + fi.EndOfFile =cpu_to_le64 (le32_to_cpu (di->DataSize)); + }else { +FILE_FULL_DIRECTORY_INFO *di; + + di = (FILE_FULL_DIRECTORY_INFO *)search_info.srch_entries_start; + fi.CreationTime = di->CreationTime; + fi.LastAccessTime = di->LastAccessTime; + fi.LastWriteTime = di->LastWriteTime; + fi.ChangeTime = di->ChangeTime; + fi.Attributes = di->ExtFileAttributes; + fi.AllocationSize = di->AllocationSize; + fi.EndOfFile = di->EndOfFile; + fi.EASize = di->EaSize; + } + fi.NumberOfLinks =cpu_to_le32 (1 ); + fi.DeletePending =0 ; + fi.Directory = !!(le32_to_cpu (fi.Attributes) &ATTR_DIRECTORY ); +cifs_buf_release (search_info.ntwrk_buf_start); + }else if (!full_path[0 ]) { +/* +* CIFSFindFirst() does not work on root path if the +* root path was exported on the server from the top +* level path (drive letter). +*/ + rc = -EOPNOTSUPP ; + } + } + +/* +* If everything failed then fallback to the legacy SMB command +* SMB_COM_QUERY_INFORMATION which works with all servers, but +* provide just few information. +*/ +if ((rc == -EOPNOTSUPP || rc == -EINVAL ) && !non_unicode_wildcard) { rc =SMBQueryInformation (xid, tcon, full_path, &fi, cifs_sb->local_nls,cifs_remap (cifs_sb)); data->adjust_tz = true; + }else if ((rc == -EOPNOTSUPP || rc == -EINVAL ) && non_unicode_wildcard) { +/* Path with non-UNICODE wildcard character cannot exist. */ + rc = -ENOENT ; }if (!rc) {
@@ -646,6 +726,13 @@ static int cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,int rc;FILE_ALL_INFO fi = {}; +/* +* CIFSSMBQFileInfo() for non-NT servers returns bogus data in +* Attributes fields. So do not use this command for non-NT servers. +*/ +if (!(tcon->ses->capabilities &CAP_NT_SMBS )) +return -EOPNOTSUPP ; +if (cfile->symlink_target) { data->symlink_target =kstrdup (cfile->symlink_target,GFP_KERNEL );if (!data->symlink_target)
Signature · 1 line
2.20.1
PATCH v2 1/1 cifs: Improve SMB1 stat() to work also for paths in DELETE_PENDING state
In reply to Pali RohárWindows NT SMB server may return -EBUSY (STATUS_DELETE_PENDING) from CIFSSMBQPathInfo() function for files which are in DELETE_PENDING state. When this happens, it is still possible to use CIFSFindFirst() fallback. So allow to use CIFSFindFirst() fallback also for -EBUSY error.
This change fixes stat() to work also against Windows Server 2022 for files in DELETE_PENDING state.
---
Changes in v2:
* Extend comment
* Update on top of the v2 change:
cifs: Fix and improve cifs_query_path_info() and cifs_query_file_info()
--- fs/smb/client/smb1ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/smb/client/smb1ops.c +3 -2
@@ -582,9 +582,10 @@ static int cifs_query_path_info(const unsigned int xid,/* * Then fallback to CIFSFindFirst() which works also with non-NT servers -* but does not does not provide NumberOfLinks. +* but does not does not provide NumberOfLinks. Also it works for files +* in DELETE_PENDING state (CIFSSMBQPathInfo() returns -EBUSY for them). */ -if ((rc == -EOPNOTSUPP || rc == -EINVAL ) && +if ((rc == -EOPNOTSUPP || rc == -EINVAL || rc == -EBUSY ) && !non_unicode_wildcard) {if (!(tcon->ses->capabilities & tcon->ses->server->vals->cap_nt_find)) search_info.info_level =SMB_FIND_FILE_INFO_STANDARD ;
Signature · 1 line
2.20.1