cifs: fix bad fids sent over wire
Subsystems (2)
PATCH 1/2 cifs: fix bad fids sent over wire
The client used to partially convert the fids to le64, while storing or sending them by using host endianness. This broke the client on big-endian machines. Instead of converting them to le64, store them as opaque integers and then avoid byteswapping when sending them over wire.
--- fs/cifs/smb2misc.c | 4 +-- fs/cifs/smb2ops.c | 8 ++--- fs/cifs/smb2pdu.c | 63 +++++++++++++++++---------------------- fs/smbfs_common/smb2pdu.h | 24 +++++++-------- 4 files changed, 46 insertions(+), 53 deletions(-)
fs/cifs/smb2misc.c +2 -2
@@ -832,8 +832,8 @@ smb2_handle_cancelled_mid(struct mid_q_entry *mid, struct TCP_Server_Info *serve rc =__smb2_handle_cancelled_cmd (tcon,le16_to_cpu (hdr->Command),le64_to_cpu (hdr->MessageId), -le64_to_cpu (rsp->PersistentFileId), -le64_to_cpu (rsp->VolatileFileId)); + rsp->PersistentFileId, + rsp->VolatileFileId);if (rc)cifs_put_tcon (tcon);
fs/cifs/smb2ops.c +4 -4
@@ -900,8 +900,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,atomic_inc (&tcon->num_remote_opens); o_rsp = (struct smb2_create_rsp *)rsp_iov[0 ].iov_base; - oparms.fid->persistent_fid =le64_to_cpu (o_rsp->PersistentFileId); - oparms.fid->volatile_fid =le64_to_cpu (o_rsp->VolatileFileId); + oparms.fid->persistent_fid = o_rsp->PersistentFileId; + oparms.fid->volatile_fid = o_rsp->VolatileFileId;#ifdef CONFIG_CIFS_DEBUG2 oparms.fid->mid =le64_to_cpu (o_rsp->hdr.MessageId);#endif /* CIFS_DEBUG2 */
@@ -2410,8 +2410,8 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,cifs_dbg (FYI ,"query_dir_first: open failed rc=%d\n" , rc); goto qdf_free; } - fid->persistent_fid =le64_to_cpu (op_rsp->PersistentFileId); - fid->volatile_fid =le64_to_cpu (op_rsp->VolatileFileId); + fid->persistent_fid = op_rsp->PersistentFileId; + fid->volatile_fid = op_rsp->VolatileFileId;/* Anything else than ENODATA means a genuine error */ if (rc && rc != -ENODATA ) {
fs/cifs/smb2pdu.c +28 -35
153 lines not on this page · raw message
fs/smbfs_common/smb2pdu.h +12 -12
@@ -608,8 +608,8 @@ struct smb2_close_req {__le16 StructureSize;/* Must be 24 */ __le16 Flags;__le32 Reserved; -__le64 PersistentFileId;/* opaque endianness */ -__le64 VolatileFileId;/* opaque endianness */ +__u64 PersistentFileId;/* opaque endianness */ +__u64 VolatileFileId;/* opaque endianness */ } __packed;/*
@@ -653,8 +653,8 @@ struct smb2_read_req {__u8 Flags;/* MBZ unless SMB3.02 or later */ __le32 Length;__le64 Offset; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 MinimumCount;__le32 Channel;/* MBZ except for SMB3 or later */ __le32 RemainingBytes;
@@ -692,8 +692,8 @@ struct smb2_write_req {__le16 DataOffset;/* offset from start of SMB2 header to write data */ __le32 Length;__le64 Offset; -__le64 PersistentFileId;/* opaque endianness */ -__le64 VolatileFileId;/* opaque endianness */ +__u64 PersistentFileId;/* opaque endianness */ +__u64 VolatileFileId;/* opaque endianness */ __le32 Channel;/* MBZ unless SMB3.02 or later */ __le32 RemainingBytes;__le16 WriteChannelInfoOffset;
@@ -722,8 +722,8 @@ struct smb2_flush_req {__le16 StructureSize;/* Must be 24 */ __le16 Reserved1;__le32 Reserved2; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } __packed;struct smb2_flush_rsp {
@@ -769,8 +769,8 @@ struct smb2_change_notify_req {__le16 StructureSize;__le16 Flags;__le32 OutputBufferLength; -__le64 PersistentFileId;/* opaque endianness */ -__le64 VolatileFileId;/* opaque endianness */ +__u64 PersistentFileId;/* opaque endianness */ +__u64 VolatileFileId;/* opaque endianness */ __le32 CompletionFilter;__u32 Reserved; } __packed;
@@ -978,8 +978,8 @@ struct smb2_create_rsp {__le64 EndofFile;__le32 FileAttributes;__le32 Reserved2; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 CreateContextsOffset;__le32 CreateContextsLength;__u8 Buffer[1 ];
Signature · 1 line
2.35.1
PATCH 2/2 ksmbd: store fids as opaque u64 integers
There is no need to store the fids as le64 integers as they are opaque to the client and only used for equality.
--- fs/ksmbd/smb2pdu.c | 94 +++++++++++++++++++--------------------------- fs/ksmbd/smb2pdu.h | 34 ++++++++--------- 2 files changed, 56 insertions(+), 72 deletions(-)
fs/ksmbd/smb2pdu.c +39 -55
@@ -377,12 +377,8 @@ static void init_chained_smb2_rsp(struct ksmbd_work *work)* command in the compound request */ if (req->Command ==SMB2_CREATE && rsp->Status ==STATUS_SUCCESS ) { - work->compound_fid = -le64_to_cpu (((struct smb2_create_rsp *)rsp)-> - VolatileFileId); - work->compound_pfid = -le64_to_cpu (((struct smb2_create_rsp *)rsp)-> - PersistentFileId); + work->compound_fid = ((struct smb2_create_rsp *)rsp)->VolatileFileId; + work->compound_pfid = ((struct smb2_create_rsp *)rsp)->PersistentFileId; work->compound_sid =le64_to_cpu (rsp->SessionId); }
@@ -2129,7 +2125,7 @@ static noinline int create_smb2_pipe(struct ksmbd_work *work) rsp->EndofFile =cpu_to_le64 (0 ); rsp->FileAttributes =FILE_ATTRIBUTE_NORMAL_LE ; rsp->Reserved2 =0 ; - rsp->VolatileFileId =cpu_to_le64 (id); + rsp->VolatileFileId = id; rsp->PersistentFileId =0 ; rsp->CreateContextsOffset =0 ; rsp->CreateContextsLength =0 ;
@@ -3157,8 +3153,8 @@ int smb2_open(struct ksmbd_work *work) rsp->Reserved2 =0 ; - rsp->PersistentFileId =cpu_to_le64 (fp->persistent_id); - rsp->VolatileFileId =cpu_to_le64 (fp->volatile_id); + rsp->PersistentFileId = fp->persistent_id; + rsp->VolatileFileId = fp->volatile_id; rsp->CreateContextsOffset =0 ; rsp->CreateContextsLength =0 ;
@@ -3865,9 +3861,7 @@ int smb2_query_dir(struct ksmbd_work *work) goto err_out2; } - dir_fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + dir_fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!dir_fp) { rc = -EBADF ; goto err_out2;
@@ -4088,12 +4082,12 @@ static int smb2_get_info_file_pipe(struct ksmbd_session *sess,* Windows can sometime send query file info request on * pipe without opening it, checking error condition here */ - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (!ksmbd_session_rpc_method (sess, id))return -ENOENT ;ksmbd_debug (SMB ,"FileInfoClass %u, FileId 0x%llx\n" , - req->FileInfoClass,le64_to_cpu (req->VolatileFileId)); + req->FileInfoClass, req->VolatileFileId);switch (req->FileInfoClass) {case FILE_STANDARD_INFORMATION :
@@ -4738,7 +4732,7 @@ static int smb2_get_info_file(struct ksmbd_work *work, }if (work->next_smb2_rcv_hdr_off) { -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;
@@ -4747,8 +4741,8 @@ static int smb2_get_info_file(struct ksmbd_work *work, }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);
@@ -5113,7 +5107,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work, }if (work->next_smb2_rcv_hdr_off) { -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;
@@ -5122,8 +5116,8 @@ static int smb2_get_info_sec(struct ksmbd_work *work, }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);
@@ -5221,7 +5215,7 @@ static noinline int smb2_close_pipe(struct ksmbd_work *work)struct smb2_close_req *req =smb2_get_msg (work->request_buf);struct smb2_close_rsp *rsp =smb2_get_msg (work->response_buf); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;ksmbd_session_rpc_close (work->sess, id); rsp->StructureSize =cpu_to_le16 (60 );
@@ -5280,7 +5274,7 @@ int smb2_close(struct ksmbd_work *work) }if (work->next_smb2_rcv_hdr_off && - !has_file_id (le64_to_cpu (req->VolatileFileId))) { + !has_file_id (req->VolatileFileId)) {if (!has_file_id (work->compound_fid)) {/* file already closed, return FILE_CLOSED */ ksmbd_debug (SMB ,"file already closed\n" );
@@ -5299,7 +5293,7 @@ int smb2_close(struct ksmbd_work *work) work->compound_pfid =KSMBD_NO_FID ; } }else { - volatile_id =le64_to_cpu (req->VolatileFileId); + volatile_id = req->VolatileFileId; }ksmbd_debug (SMB ,"volatile_id = %llu\n" , volatile_id);
@@ -5988,7 +5982,7 @@ int smb2_set_info(struct ksmbd_work *work)if (work->next_smb2_rcv_hdr_off) { req =ksmbd_req_buf_next (work); rsp =ksmbd_resp_buf_next (work); -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;
@@ -6000,8 +5994,8 @@ int smb2_set_info(struct ksmbd_work *work) }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);
@@ -6079,7 +6073,7 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)struct smb2_read_req *req =smb2_get_msg (work->request_buf);struct smb2_read_rsp *rsp =smb2_get_msg (work->response_buf); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;inc_rfc1001_len (work->response_buf,16 ); rpc_resp =ksmbd_rpc_read (work->sess, id);
@@ -6215,8 +6209,7 @@ int smb2_read(struct ksmbd_work *work) goto out; } - fp =ksmbd_lookup_fd_slow (work,le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { err = -ENOENT ; goto out;
@@ -6335,7 +6328,7 @@ static noinline int smb2_write_pipe(struct ksmbd_work *work)size_t length; length =le32_to_cpu (req->Length); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (le16_to_cpu (req->DataOffset) == offsetof(struct smb2_write_req , Buffer)) {
@@ -6471,8 +6464,7 @@ int smb2_write(struct ksmbd_work *work) goto out; } - fp =ksmbd_lookup_fd_slow (work,le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { err = -ENOENT ; goto out;
@@ -6584,12 +6576,9 @@ int smb2_flush(struct ksmbd_work *work)WORK_BUFFERS (work, req, rsp); -ksmbd_debug (SMB ,"SMB2_FLUSH called for fid %llu\n" , -le64_to_cpu (req->VolatileFileId)); +ksmbd_debug (SMB ,"SMB2_FLUSH called for fid %llu\n" , req->VolatileFileId); - err =ksmbd_vfs_fsync (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + err =ksmbd_vfs_fsync (work, req->VolatileFileId, req->PersistentFileId);if (err) goto out;
@@ -6804,12 +6793,9 @@ int smb2_lock(struct ksmbd_work *work)int prior_lock =0 ;ksmbd_debug (SMB ,"Received lock request\n" ); - fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { -ksmbd_debug (SMB ,"Invalid file id for lock : %llu\n" , -le64_to_cpu (req->VolatileFileId)); +ksmbd_debug (SMB ,"Invalid file id for lock : %llu\n" , req->VolatileFileId); err = -ENOENT ; goto out2; }
@@ -7164,8 +7150,8 @@ static int fsctl_copychunk(struct ksmbd_work *work, ci_rsp = (struct copychunk_ioctl_rsp *)&rsp->Buffer[0 ]; - rsp->VolatileFileId =cpu_to_le64 (volatile_id); - rsp->PersistentFileId =cpu_to_le64 (persistent_id); + rsp->VolatileFileId = volatile_id; + rsp->PersistentFileId = persistent_id; ci_rsp->ChunksWritten =cpu_to_le32 (ksmbd_server_side_copy_max_chunk_count ()); ci_rsp->ChunkBytesWritten =
@@ -7379,8 +7365,8 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,if (nii_rsp) nii_rsp->Next =0 ; - rsp->PersistentFileId =cpu_to_le64 (SMB2_NO_FID ); - rsp->VolatileFileId =cpu_to_le64 (SMB2_NO_FID ); + rsp->PersistentFileId =SMB2_NO_FID ; + rsp->VolatileFileId =SMB2_NO_FID ;return nbytes; }
@@ -7547,9 +7533,7 @@ static int fsctl_request_resume_key(struct ksmbd_work *work, {struct ksmbd_file *fp; - fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp)return -ENOENT ;
@@ -7579,7 +7563,7 @@ int smb2_ioctl(struct ksmbd_work *work)if (work->next_smb2_rcv_hdr_off) { req =ksmbd_req_buf_next (work); rsp =ksmbd_resp_buf_next (work); -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;
@@ -7590,7 +7574,7 @@ int smb2_ioctl(struct ksmbd_work *work) }if (!has_file_id (id)) - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (req->Flags !=cpu_to_le32 (SMB2_0_IOCTL_IS_FSCTL )) { rsp->hdr.Status =STATUS_NOT_SUPPORTED ;
@@ -7656,8 +7640,8 @@ int smb2_ioctl(struct ksmbd_work *work) goto out; nbytes =sizeof (struct validate_negotiate_info_rsp ); - rsp->PersistentFileId =cpu_to_le64 (SMB2_NO_FID ); - rsp->VolatileFileId =cpu_to_le64 (SMB2_NO_FID ); + rsp->PersistentFileId =SMB2_NO_FID ; + rsp->VolatileFileId =SMB2_NO_FID ;break ;case FSCTL_QUERY_NETWORK_INTERFACE_INFO : ret =fsctl_query_iface_info_ioctl (conn, rsp, out_buf_len);
@@ -7705,8 +7689,8 @@ int smb2_ioctl(struct ksmbd_work *work) (struct copychunk_ioctl_req *)&req->Buffer[0 ],le32_to_cpu (req->CntCode),le32_to_cpu (req->InputCount), -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId), + req->VolatileFileId, + req->PersistentFileId, rsp);break ;case FSCTL_SET_SPARSE :
fs/ksmbd/smb2pdu.h +17 -17
@@ -116,8 +116,8 @@ struct create_durable_reconn_req {union {__u8 Reserved[16 ];struct { -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } Fid; } Data; } __packed;
@@ -126,8 +126,8 @@ struct create_durable_reconn_v2_req {struct create_context ccontext;__u8 Name[8 ];struct { -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } Fid;__u8 CreateGuid[16 ];__le32 Flags;
@@ -269,8 +269,8 @@ struct smb2_ioctl_req {__le16 StructureSize;/* Must be 57 */ __le16 Reserved;/* offset from start of SMB2 header to write data */ __le32 CntCode; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 InputOffset;/* Reserved MBZ */ __le32 InputCount;__le32 MaxInputResponse;
@@ -287,8 +287,8 @@ struct smb2_ioctl_rsp {__le16 StructureSize;/* Must be 49 */ __le16 Reserved;/* offset from start of SMB2 header to write data */ __le32 CntCode; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 InputOffset;/* Reserved MBZ */ __le32 InputCount;__le32 OutputOffset;
@@ -357,7 +357,7 @@ struct file_object_buf_type1_ioctl_rsp { } __packed;struct resume_key_ioctl_rsp { -__le64 ResumeKey[3 ]; +__u64 ResumeKey[3 ];__le32 ContextLength;__u8 Context[4 ];/* ignored, Windows sets to 4 bytes of zero */ } __packed;
@@ -432,8 +432,8 @@ struct smb2_lock_req {__le16 StructureSize;/* Must be 48 */ __le16 LockCount;__le32 Reserved; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;/* Followed by at least one */ struct smb2_lock_element locks[1 ]; } __packed;
@@ -468,8 +468,8 @@ struct smb2_query_directory_req {__u8 FileInformationClass;__u8 Flags;__le32 FileIndex; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le16 FileNameOffset;__le16 FileNameLength;__le32 OutputBufferLength;
@@ -515,8 +515,8 @@ struct smb2_query_info_req {__le32 InputBufferLength;__le32 AdditionalInformation;__le32 Flags; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__u8 Buffer[1 ]; } __packed;
@@ -537,8 +537,8 @@ struct smb2_set_info_req {__le16 BufferOffset;__u16 Reserved;__le32 AdditionalInformation; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__u8 Buffer[1 ]; } __packed;
Signature · 1 line
2.35.1
Re: [PATCH 2/2] ksmbd: store fids as opaque u64 integers
It is also clearer to not convert them (better matches the documentation MS-SMB2) and also slightly faster on big endian.
Quoted 407 lines · Paulo Alcantara
There is no need to store the fids as le64 integers as they are opaque to the client and only used for equality.
Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/ksmbd/smb2pdu.c | 94 +++++++++++++++++++--------------------------- fs/ksmbd/smb2pdu.h | 34 ++++++++--------- 2 files changed, 56 insertions(+), 72 deletions(-)fs/ksmbd/smb2pdu.c +39
-55@@ -377,12 +377,8 @@ static void init_chained_smb2_rsp(struct ksmbd_work *work)* command in the compound request */ if (req->Command ==SMB2_CREATE && rsp->Status ==STATUS_SUCCESS ) { - work->compound_fid = -le64_to_cpu (((struct smb2_create_rsp *)rsp)-> - VolatileFileId); - work->compound_pfid = -le64_to_cpu (((struct smb2_create_rsp *)rsp)-> - PersistentFileId); + work->compound_fid = ((struct smb2_create_rsp *)rsp)->VolatileFileId; + work->compound_pfid = ((struct smb2_create_rsp *)rsp)->PersistentFileId; work->compound_sid =le64_to_cpu (rsp->SessionId); }@@ -2129,7 +2125,7 @@ static noinline int create_smb2_pipe(struct ksmbd_work *work) rsp->EndofFile =cpu_to_le64 (0 ); rsp->FileAttributes =FILE_ATTRIBUTE_NORMAL_LE ; rsp->Reserved2 =0 ; - rsp->VolatileFileId =cpu_to_le64 (id); + rsp->VolatileFileId = id; rsp->PersistentFileId =0 ; rsp->CreateContextsOffset =0 ; rsp->CreateContextsLength =0 ;@@ -3157,8 +3153,8 @@ int smb2_open(struct ksmbd_work *work) rsp->Reserved2 =0 ; - rsp->PersistentFileId =cpu_to_le64 (fp->persistent_id); - rsp->VolatileFileId =cpu_to_le64 (fp->volatile_id); + rsp->PersistentFileId = fp->persistent_id; + rsp->VolatileFileId = fp->volatile_id; rsp->CreateContextsOffset =0 ; rsp->CreateContextsLength =0 ;@@ -3865,9 +3861,7 @@ int smb2_query_dir(struct ksmbd_work *work) goto err_out2; } - dir_fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + dir_fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!dir_fp) { rc = -EBADF ; goto err_out2;@@ -4088,12 +4082,12 @@ static int smb2_get_info_file_pipe(struct ksmbd_session *sess,* Windows can sometime send query file info request on * pipe without opening it, checking error condition here */ - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (!ksmbd_session_rpc_method (sess, id))return -ENOENT ;ksmbd_debug (SMB ,"FileInfoClass %u, FileId 0x%llx\n" , - req->FileInfoClass,le64_to_cpu (req->VolatileFileId)); + req->FileInfoClass, req->VolatileFileId);switch (req->FileInfoClass) {case FILE_STANDARD_INFORMATION :@@ -4738,7 +4732,7 @@ static int smb2_get_info_file(struct ksmbd_work *work, }if (work->next_smb2_rcv_hdr_off) { -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -4747,8 +4741,8 @@ static int smb2_get_info_file(struct ksmbd_work *work, }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);@@ -5113,7 +5107,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work, }if (work->next_smb2_rcv_hdr_off) { -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -5122,8 +5116,8 @@ static int smb2_get_info_sec(struct ksmbd_work *work, }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);@@ -5221,7 +5215,7 @@ static noinline int smb2_close_pipe(struct ksmbd_work *work)struct smb2_close_req *req =smb2_get_msg (work->request_buf);struct smb2_close_rsp *rsp =smb2_get_msg (work->response_buf); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;ksmbd_session_rpc_close (work->sess, id); rsp->StructureSize =cpu_to_le16 (60 );@@ -5280,7 +5274,7 @@ int smb2_close(struct ksmbd_work *work) }if (work->next_smb2_rcv_hdr_off && - !has_file_id (le64_to_cpu (req->VolatileFileId))) { + !has_file_id (req->VolatileFileId)) {if (!has_file_id (work->compound_fid)) {/* file already closed, return FILE_CLOSED */ ksmbd_debug (SMB ,"file already closed\n" );@@ -5299,7 +5293,7 @@ int smb2_close(struct ksmbd_work *work) work->compound_pfid =KSMBD_NO_FID ; } }else { - volatile_id =le64_to_cpu (req->VolatileFileId); + volatile_id = req->VolatileFileId; }ksmbd_debug (SMB ,"volatile_id = %llu\n" , volatile_id);@@ -5988,7 +5982,7 @@ int smb2_set_info(struct ksmbd_work *work)if (work->next_smb2_rcv_hdr_off) { req =ksmbd_req_buf_next (work); rsp =ksmbd_resp_buf_next (work); -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -6000,8 +5994,8 @@ int smb2_set_info(struct ksmbd_work *work) }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);@@ -6079,7 +6073,7 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)struct smb2_read_req *req =smb2_get_msg (work->request_buf);struct smb2_read_rsp *rsp =smb2_get_msg (work->response_buf); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;inc_rfc1001_len (work->response_buf,16 ); rpc_resp =ksmbd_rpc_read (work->sess, id);@@ -6215,8 +6209,7 @@ int smb2_read(struct ksmbd_work *work) goto out; } - fp =ksmbd_lookup_fd_slow (work,le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { err = -ENOENT ; goto out;@@ -6335,7 +6328,7 @@ static noinline int smb2_write_pipe(struct ksmbd_work *work)size_t length; length =le32_to_cpu (req->Length); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (le16_to_cpu (req->DataOffset) == offsetof(struct smb2_write_req , Buffer)) {@@ -6471,8 +6464,7 @@ int smb2_write(struct ksmbd_work *work) goto out; } - fp =ksmbd_lookup_fd_slow (work,le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { err = -ENOENT ; goto out;@@ -6584,12 +6576,9 @@ int smb2_flush(struct ksmbd_work *work)WORK_BUFFERS (work, req, rsp); -ksmbd_debug (SMB ,"SMB2_FLUSH called for fid %llu\n" , -le64_to_cpu (req->VolatileFileId)); +ksmbd_debug (SMB ,"SMB2_FLUSH called for fid %llu\n" , req->VolatileFileId); - err =ksmbd_vfs_fsync (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + err =ksmbd_vfs_fsync (work, req->VolatileFileId, req->PersistentFileId);if (err) goto out;@@ -6804,12 +6793,9 @@ int smb2_lock(struct ksmbd_work *work)int prior_lock =0 ;ksmbd_debug (SMB ,"Received lock request\n" ); - fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { -ksmbd_debug (SMB ,"Invalid file id for lock : %llu\n" , -le64_to_cpu (req->VolatileFileId)); +ksmbd_debug (SMB ,"Invalid file id for lock : %llu\n" , req->VolatileFileId); err = -ENOENT ; goto out2; }@@ -7164,8 +7150,8 @@ static int fsctl_copychunk(struct ksmbd_work *work, ci_rsp = (struct copychunk_ioctl_rsp *)&rsp->Buffer[0 ]; - rsp->VolatileFileId =cpu_to_le64 (volatile_id); - rsp->PersistentFileId =cpu_to_le64 (persistent_id); + rsp->VolatileFileId = volatile_id; + rsp->PersistentFileId = persistent_id; ci_rsp->ChunksWritten =cpu_to_le32 (ksmbd_server_side_copy_max_chunk_count ()); ci_rsp->ChunkBytesWritten =@@ -7379,8 +7365,8 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,if (nii_rsp) nii_rsp->Next =0 ; - rsp->PersistentFileId =cpu_to_le64 (SMB2_NO_FID ); - rsp->VolatileFileId =cpu_to_le64 (SMB2_NO_FID ); + rsp->PersistentFileId =SMB2_NO_FID ; + rsp->VolatileFileId =SMB2_NO_FID ;return nbytes; }@@ -7547,9 +7533,7 @@ static int fsctl_request_resume_key(struct ksmbd_work *work, {struct ksmbd_file *fp; - fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp)return -ENOENT ;@@ -7579,7 +7563,7 @@ int smb2_ioctl(struct ksmbd_work *work)if (work->next_smb2_rcv_hdr_off) { req =ksmbd_req_buf_next (work); rsp =ksmbd_resp_buf_next (work); -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -7590,7 +7574,7 @@ int smb2_ioctl(struct ksmbd_work *work) }if (!has_file_id (id)) - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (req->Flags !=cpu_to_le32 (SMB2_0_IOCTL_IS_FSCTL )) { rsp->hdr.Status =STATUS_NOT_SUPPORTED ;@@ -7656,8 +7640,8 @@ int smb2_ioctl(struct ksmbd_work *work) goto out; nbytes =sizeof (struct validate_negotiate_info_rsp ); - rsp->PersistentFileId =cpu_to_le64 (SMB2_NO_FID ); - rsp->VolatileFileId =cpu_to_le64 (SMB2_NO_FID ); + rsp->PersistentFileId =SMB2_NO_FID ; + rsp->VolatileFileId =SMB2_NO_FID ;break ;case FSCTL_QUERY_NETWORK_INTERFACE_INFO : ret =fsctl_query_iface_info_ioctl (conn, rsp, out_buf_len);@@ -7705,8 +7689,8 @@ int smb2_ioctl(struct ksmbd_work *work) (struct copychunk_ioctl_req *)&req->Buffer[0 ],le32_to_cpu (req->CntCode),le32_to_cpu (req->InputCount), -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId), + req->VolatileFileId, + req->PersistentFileId, rsp);break ;case FSCTL_SET_SPARSE :fs/ksmbd/smb2pdu.h +17
-18@@ -116,8 +116,8 @@ struct create_durable_reconn_req {union {__u8 Reserved[16 ];struct { -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } Fid; } Data; } __packed;@@ -126,8 +126,8 @@ struct create_durable_reconn_v2_req {struct create_context ccontext;__u8 Name[8 ];struct { -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } Fid;__u8 CreateGuid[16 ];__le32 Flags;@@ -269,8 +269,8 @@ struct smb2_ioctl_req {__le16 StructureSize;/* Must be 57 */ __le16 Reserved;/* offset from start of SMB2 header to write data */ __le32 CntCode; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 InputOffset;/* Reserved MBZ */ __le32 InputCount;__le32 MaxInputResponse;@@ -287,8 +287,8 @@ struct smb2_ioctl_rsp {__le16 StructureSize;/* Must be 49 */ __le16 Reserved;/* offset from start of SMB2 header to write data */ __le32 CntCode; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 InputOffset;/* Reserved MBZ */ __le32 InputCount;__le32 OutputOffset;@@ -357,7 +357,7 @@ struct file_object_buf_type1_ioctl_rsp { } __packed;struct resume_key_ioctl_rsp { -__le64 ResumeKey[3 ]; +__u64 ResumeKey[3 ];__le32 ContextLength;__u8 Context[4 ];/* ignored, Windows sets to 4 bytes of zero */ } __packed;@@ -432,8 +432,8 @@ struct smb2_lock_req {__le16 StructureSize;/* Must be 48 */ __le16 LockCount;__le32 Reserved; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;/* Followed by at least one */ struct smb2_lock_element locks[1 ]; } __packed;@@ -468,8 +468,8 @@ struct smb2_query_directory_req {__u8 FileInformationClass;__u8 Flags;__le32 FileIndex; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le16 FileNameOffset;__le16 FileNameLength;__le32 OutputBufferLength;@@ -515,8 +515,8 @@ struct smb2_query_info_req {__le32 InputBufferLength;__le32 AdditionalInformation;__le32 Flags; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__u8 Buffer[1 ]; } __packed;@@ -537,8 +537,8 @@ struct smb2_set_info_req {__le16 BufferOffset;__u16 Reserved;__le32 AdditionalInformation; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__u8 Buffer[1 ]; } __packed; --2.35.1
Signature · 3 lines
Thanks, Steve
Re: [PATCH 2/2] ksmbd: store fids as opaque u64 integers
In reply to Paulo AlcantaraSo, is this change strictly necessary? FID's are actually generated by the server, so it can choose any convenient format. If the code currently works on both endians, there's a case for not touching it now.
OTOH if you've tested and it's solid, sure, because it will ever so slightly reduce overhead on LE servers.
In any case,
Quoted 403 lines · Paulo Alcantara
There is no need to store the fids as le64 integers as they are opaque to the client and only used for equality.
Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/ksmbd/smb2pdu.c | 94 +++++++++++++++++++--------------------------- fs/ksmbd/smb2pdu.h | 34 ++++++++--------- 2 files changed, 56 insertions(+), 72 deletions(-)fs/ksmbd/smb2pdu.c +39
-55@@ -377,12 +377,8 @@ static void init_chained_smb2_rsp(struct ksmbd_work *work)* command in the compound request */ if (req->Command ==SMB2_CREATE && rsp->Status ==STATUS_SUCCESS ) { - work->compound_fid = -le64_to_cpu (((struct smb2_create_rsp *)rsp)-> - VolatileFileId); - work->compound_pfid = -le64_to_cpu (((struct smb2_create_rsp *)rsp)-> - PersistentFileId); + work->compound_fid = ((struct smb2_create_rsp *)rsp)->VolatileFileId; + work->compound_pfid = ((struct smb2_create_rsp *)rsp)->PersistentFileId; work->compound_sid =le64_to_cpu (rsp->SessionId); }@@ -2129,7 +2125,7 @@ static noinline int create_smb2_pipe(struct ksmbd_work *work) rsp->EndofFile =cpu_to_le64 (0 ); rsp->FileAttributes =FILE_ATTRIBUTE_NORMAL_LE ; rsp->Reserved2 =0 ; - rsp->VolatileFileId =cpu_to_le64 (id); + rsp->VolatileFileId = id; rsp->PersistentFileId =0 ; rsp->CreateContextsOffset =0 ; rsp->CreateContextsLength =0 ;@@ -3157,8 +3153,8 @@ int smb2_open(struct ksmbd_work *work) rsp->Reserved2 =0 ; - rsp->PersistentFileId =cpu_to_le64 (fp->persistent_id); - rsp->VolatileFileId =cpu_to_le64 (fp->volatile_id); + rsp->PersistentFileId = fp->persistent_id; + rsp->VolatileFileId = fp->volatile_id; rsp->CreateContextsOffset =0 ; rsp->CreateContextsLength =0 ;@@ -3865,9 +3861,7 @@ int smb2_query_dir(struct ksmbd_work *work) goto err_out2; } - dir_fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + dir_fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!dir_fp) { rc = -EBADF ; goto err_out2;@@ -4088,12 +4082,12 @@ static int smb2_get_info_file_pipe(struct ksmbd_session *sess,* Windows can sometime send query file info request on * pipe without opening it, checking error condition here */ - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (!ksmbd_session_rpc_method (sess, id))return -ENOENT ;ksmbd_debug (SMB ,"FileInfoClass %u, FileId 0x%llx\n" , - req->FileInfoClass,le64_to_cpu (req->VolatileFileId)); + req->FileInfoClass, req->VolatileFileId);switch (req->FileInfoClass) {case FILE_STANDARD_INFORMATION :@@ -4738,7 +4732,7 @@ static int smb2_get_info_file(struct ksmbd_work *work, }if (work->next_smb2_rcv_hdr_off) { -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -4747,8 +4741,8 @@ static int smb2_get_info_file(struct ksmbd_work *work, }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);@@ -5113,7 +5107,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work, }if (work->next_smb2_rcv_hdr_off) { -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -5122,8 +5116,8 @@ static int smb2_get_info_sec(struct ksmbd_work *work, }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);@@ -5221,7 +5215,7 @@ static noinline int smb2_close_pipe(struct ksmbd_work *work)struct smb2_close_req *req =smb2_get_msg (work->request_buf);struct smb2_close_rsp *rsp =smb2_get_msg (work->response_buf); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;ksmbd_session_rpc_close (work->sess, id); rsp->StructureSize =cpu_to_le16 (60 );@@ -5280,7 +5274,7 @@ int smb2_close(struct ksmbd_work *work) }if (work->next_smb2_rcv_hdr_off && - !has_file_id (le64_to_cpu (req->VolatileFileId))) { + !has_file_id (req->VolatileFileId)) {if (!has_file_id (work->compound_fid)) {/* file already closed, return FILE_CLOSED */ ksmbd_debug (SMB ,"file already closed\n" );@@ -5299,7 +5293,7 @@ int smb2_close(struct ksmbd_work *work) work->compound_pfid =KSMBD_NO_FID ; } }else { - volatile_id =le64_to_cpu (req->VolatileFileId); + volatile_id = req->VolatileFileId; }ksmbd_debug (SMB ,"volatile_id = %llu\n" , volatile_id);@@ -5988,7 +5982,7 @@ int smb2_set_info(struct ksmbd_work *work)if (work->next_smb2_rcv_hdr_off) { req =ksmbd_req_buf_next (work); rsp =ksmbd_resp_buf_next (work); -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -6000,8 +5994,8 @@ int smb2_set_info(struct ksmbd_work *work) }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);@@ -6079,7 +6073,7 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)struct smb2_read_req *req =smb2_get_msg (work->request_buf);struct smb2_read_rsp *rsp =smb2_get_msg (work->response_buf); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;inc_rfc1001_len (work->response_buf,16 ); rpc_resp =ksmbd_rpc_read (work->sess, id);@@ -6215,8 +6209,7 @@ int smb2_read(struct ksmbd_work *work) goto out; } - fp =ksmbd_lookup_fd_slow (work,le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { err = -ENOENT ; goto out;@@ -6335,7 +6328,7 @@ static noinline int smb2_write_pipe(struct ksmbd_work *work)size_t length; length =le32_to_cpu (req->Length); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (le16_to_cpu (req->DataOffset) == offsetof(struct smb2_write_req , Buffer)) {@@ -6471,8 +6464,7 @@ int smb2_write(struct ksmbd_work *work) goto out; } - fp =ksmbd_lookup_fd_slow (work,le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { err = -ENOENT ; goto out;@@ -6584,12 +6576,9 @@ int smb2_flush(struct ksmbd_work *work)WORK_BUFFERS (work, req, rsp); -ksmbd_debug (SMB ,"SMB2_FLUSH called for fid %llu\n" , -le64_to_cpu (req->VolatileFileId)); +ksmbd_debug (SMB ,"SMB2_FLUSH called for fid %llu\n" , req->VolatileFileId); - err =ksmbd_vfs_fsync (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + err =ksmbd_vfs_fsync (work, req->VolatileFileId, req->PersistentFileId);if (err) goto out;@@ -6804,12 +6793,9 @@ int smb2_lock(struct ksmbd_work *work)int prior_lock =0 ;ksmbd_debug (SMB ,"Received lock request\n" ); - fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { -ksmbd_debug (SMB ,"Invalid file id for lock : %llu\n" , -le64_to_cpu (req->VolatileFileId)); +ksmbd_debug (SMB ,"Invalid file id for lock : %llu\n" , req->VolatileFileId); err = -ENOENT ; goto out2; }@@ -7164,8 +7150,8 @@ static int fsctl_copychunk(struct ksmbd_work *work, ci_rsp = (struct copychunk_ioctl_rsp *)&rsp->Buffer[0 ]; - rsp->VolatileFileId =cpu_to_le64 (volatile_id); - rsp->PersistentFileId =cpu_to_le64 (persistent_id); + rsp->VolatileFileId = volatile_id; + rsp->PersistentFileId = persistent_id; ci_rsp->ChunksWritten =cpu_to_le32 (ksmbd_server_side_copy_max_chunk_count ()); ci_rsp->ChunkBytesWritten =@@ -7379,8 +7365,8 @@ static int fsctl_query_iface_info_ioctl(struct ksmbd_conn *conn,if (nii_rsp) nii_rsp->Next =0 ; - rsp->PersistentFileId =cpu_to_le64 (SMB2_NO_FID ); - rsp->VolatileFileId =cpu_to_le64 (SMB2_NO_FID ); + rsp->PersistentFileId =SMB2_NO_FID ; + rsp->VolatileFileId =SMB2_NO_FID ;return nbytes; }@@ -7547,9 +7533,7 @@ static int fsctl_request_resume_key(struct ksmbd_work *work, {struct ksmbd_file *fp; - fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp)return -ENOENT ;@@ -7579,7 +7563,7 @@ int smb2_ioctl(struct ksmbd_work *work)if (work->next_smb2_rcv_hdr_off) { req =ksmbd_req_buf_next (work); rsp =ksmbd_resp_buf_next (work); -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -7590,7 +7574,7 @@ int smb2_ioctl(struct ksmbd_work *work) }if (!has_file_id (id)) - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (req->Flags !=cpu_to_le32 (SMB2_0_IOCTL_IS_FSCTL )) { rsp->hdr.Status =STATUS_NOT_SUPPORTED ;@@ -7656,8 +7640,8 @@ int smb2_ioctl(struct ksmbd_work *work) goto out; nbytes =sizeof (struct validate_negotiate_info_rsp ); - rsp->PersistentFileId =cpu_to_le64 (SMB2_NO_FID ); - rsp->VolatileFileId =cpu_to_le64 (SMB2_NO_FID ); + rsp->PersistentFileId =SMB2_NO_FID ; + rsp->VolatileFileId =SMB2_NO_FID ;break ;case FSCTL_QUERY_NETWORK_INTERFACE_INFO : ret =fsctl_query_iface_info_ioctl (conn, rsp, out_buf_len);@@ -7705,8 +7689,8 @@ int smb2_ioctl(struct ksmbd_work *work) (struct copychunk_ioctl_req *)&req->Buffer[0 ],le32_to_cpu (req->CntCode),le32_to_cpu (req->InputCount), -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId), + req->VolatileFileId, + req->PersistentFileId, rsp);break ;case FSCTL_SET_SPARSE :fs/ksmbd/smb2pdu.h +17
-17@@ -116,8 +116,8 @@ struct create_durable_reconn_req {union {__u8 Reserved[16 ];struct { -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } Fid; } Data; } __packed;@@ -126,8 +126,8 @@ struct create_durable_reconn_v2_req {struct create_context ccontext;__u8 Name[8 ];struct { -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } Fid;__u8 CreateGuid[16 ];__le32 Flags;@@ -269,8 +269,8 @@ struct smb2_ioctl_req {__le16 StructureSize;/* Must be 57 */ __le16 Reserved;/* offset from start of SMB2 header to write data */ __le32 CntCode; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 InputOffset;/* Reserved MBZ */ __le32 InputCount;__le32 MaxInputResponse;@@ -287,8 +287,8 @@ struct smb2_ioctl_rsp {__le16 StructureSize;/* Must be 49 */ __le16 Reserved;/* offset from start of SMB2 header to write data */ __le32 CntCode; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 InputOffset;/* Reserved MBZ */ __le32 InputCount;__le32 OutputOffset;@@ -357,7 +357,7 @@ struct file_object_buf_type1_ioctl_rsp { } __packed;struct resume_key_ioctl_rsp { -__le64 ResumeKey[3 ]; +__u64 ResumeKey[3 ];__le32 ContextLength;__u8 Context[4 ];/* ignored, Windows sets to 4 bytes of zero */ } __packed;@@ -432,8 +432,8 @@ struct smb2_lock_req {__le16 StructureSize;/* Must be 48 */ __le16 LockCount;__le32 Reserved; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;/* Followed by at least one */ struct smb2_lock_element locks[1 ]; } __packed;@@ -468,8 +468,8 @@ struct smb2_query_directory_req {__u8 FileInformationClass;__u8 Flags;__le32 FileIndex; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le16 FileNameOffset;__le16 FileNameLength;__le32 OutputBufferLength;@@ -515,8 +515,8 @@ struct smb2_query_info_req {__le32 InputBufferLength;__le32 AdditionalInformation;__le32 Flags; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__u8 Buffer[1 ]; } __packed;@@ -537,8 +537,8 @@ struct smb2_set_info_req {__le16 BufferOffset;__u16 Reserved;__le32 AdditionalInformation; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__u8 Buffer[1 ]; } __packed;
Re: [PATCH 2/2] ksmbd: store fids as opaque u64 integers
2022-03-22 3:40 GMT+09:00, Tom Talpey <[email protected]>:
Quoted 7 lines
So, is this change strictly necessary? FID's are actually generated by the server, so it can choose any convenient format. If the code currently works on both endians, there's a case for not touching it now.
OTOH if you've tested and it's solid, sure, because it will ever so slightly reduce overhead on LE servers.
Agreed, looks good to me if it work well between BE ksmbd and LE windows client.
Thanks!
Quoted 431 lines
In any case,
Reviewed-by Tom Talpey <[email protected]>Quoted 424 lines · Paulo Alcantara
There is no need to store the fids as le64 integers as they are opaque to the client and only used for equality.
Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/ksmbd/smb2pdu.c | 94 +++++++++++++++++++--------------------------- fs/ksmbd/smb2pdu.h | 34 ++++++++--------- 2 files changed, 56 insertions(+), 72 deletions(-)fs/ksmbd/smb2pdu.c +2
-6@@ -377,12 +377,8 @@ static void init_chained_smb2_rsp(struct ksmbd_work*work) * command in the compound request */ if (req->Command ==SMB2_CREATE && rsp->Status ==STATUS_SUCCESS ) { - work->compound_fid = -le64_to_cpu (((struct smb2_create_rsp *)rsp)-> - VolatileFileId); - work->compound_pfid = -le64_to_cpu (((struct smb2_create_rsp *)rsp)-> - PersistentFileId); + work->compound_fid = ((struct smb2_create_rsp *)rsp)->VolatileFileId; + work->compound_pfid = ((struct smb2_create_rsp *)rsp)->PersistentFileId; work->compound_sid =le64_to_cpu (rsp->SessionId);}fs/ksmbd/smb2pdu.c +1
-1@@ -2129,7 +2125,7 @@ static noinline int create_smb2_pipe(struct ksmbd_work *work) rsp->EndofFile = cpu_to_le64(0); rsp->FileAttributes =FILE_ATTRIBUTE_NORMAL_LE ; rsp->Reserved2 =0 ; - rsp->VolatileFileId =cpu_to_le64 (id); + rsp->VolatileFileId = id; rsp->PersistentFileId =0 ; rsp->CreateContextsOffset =0 ;rsp->CreateContextsLength = 0;fs/ksmbd/smb2pdu.c +3
-5@@ -3157,8 +3153,8 @@ int smb2_open(struct ksmbd_work *work) rsp->Reserved2 =0 ; - rsp->PersistentFileId =cpu_to_le64 (fp->persistent_id); - rsp->VolatileFileId =cpu_to_le64 (fp->volatile_id); + rsp->PersistentFileId = fp->persistent_id; + rsp->VolatileFileId = fp->volatile_id; rsp->CreateContextsOffset =0 ; rsp->CreateContextsLength =0 ;@@ -3865,9 +3861,7 @@ int smb2_query_dir(struct ksmbd_work *work) goto err_out2; } - dir_fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + dir_fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!dir_fp) { rc = -EBADF ;goto
err_out2;fs/ksmbd/smb2pdu.c +2
-2@@ -4088,12 +4082,12 @@ static int smb2_get_info_file_pipe(structksmbd_session *sess, * Windows can sometime send query file info request on * pipe without opening it, checking error condition here */ - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (!ksmbd_session_rpc_method (sess, id))return -ENOENT ;ksmbd_debug (SMB ,"FileInfoClass %u, FileId 0x%llx\n" , - req->FileInfoClass,le64_to_cpu (req->VolatileFileId)); + req->FileInfoClass, req->VolatileFileId);switch (req->FileInfoClass) {case
FILE_STANDARD_INFORMATION:fs/ksmbd/smb2pdu.c +1
-1@@ -4738,7 +4732,7 @@ static int smb2_get_info_file(struct ksmbd_work *work, }if (work->next_smb2_rcv_hdr_off) { -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid);id = work->compound_fid;fs/ksmbd/smb2pdu.c +2
-2@@ -4747,8 +4741,8 @@ static int smb2_get_info_file(struct ksmbd_work *work, }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; }fp = ksmbd_lookup_fd_slow(work, id, pid);fs/ksmbd/smb2pdu.c +1
-1@@ -5113,7 +5107,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work, }if (work->next_smb2_rcv_hdr_off) { -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid);id = work->compound_fid;fs/ksmbd/smb2pdu.c +2
-2@@ -5122,8 +5116,8 @@ static int smb2_get_info_sec(struct ksmbd_work *work, }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; }fp = ksmbd_lookup_fd_slow(work, id, pid);fs/ksmbd/smb2pdu.c +1
-1@@ -5221,7 +5215,7 @@ static noinline int smb2_close_pipe(struct ksmbd_work *work)struct smb2_close_req *req =smb2_get_msg (work->request_buf);struct smb2_close_rsp *rsp =smb2_get_msg (work->response_buf); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;ksmbd_session_rpc_close (work->sess, id);rsp->StructureSize = cpu_to_le16(60);fs/ksmbd/smb2pdu.c +6
-6@@ -5280,7 +5274,7 @@ int smb2_close(struct ksmbd_work *work) }if (work->next_smb2_rcv_hdr_off && - !has_file_id (le64_to_cpu (req->VolatileFileId))) { + !has_file_id (req->VolatileFileId)) {if (!has_file_id (work->compound_fid)) {/* file already closed, return FILE_CLOSED */ ksmbd_debug (SMB ,"file already closed\n" );@@ -5299,7 +5293,7 @@ int smb2_close(struct ksmbd_work *work) work->compound_pfid =KSMBD_NO_FID ; } }else { - volatile_id =le64_to_cpu (req->VolatileFileId); + volatile_id = req->VolatileFileId; }ksmbd_debug (SMB ,"volatile_id = %llu\n" , volatile_id);@@ -5988,7 +5982,7 @@ int smb2_set_info(struct ksmbd_work *work)if (work->next_smb2_rcv_hdr_off) { req =ksmbd_req_buf_next (work); rsp =ksmbd_resp_buf_next (work); -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -6000,8 +5994,8 @@ int smb2_set_info(struct ksmbd_work *work) }if (!has_file_id (id)) { - id =le64_to_cpu (req->VolatileFileId); - pid =le64_to_cpu (req->PersistentFileId); + id = req->VolatileFileId; + pid = req->PersistentFileId; } fp =ksmbd_lookup_fd_slow (work, id, pid);@@ -6079,7 +6073,7 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)struct smb2_read_req *req =smb2_get_msg (work->request_buf);struct smb2_read_rsp *rsp =smb2_get_msg (work->response_buf); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;inc_rfc1001_len (work->response_buf,16 );rpc_resp = ksmbd_rpc_read(work->sess, id);fs/ksmbd/smb2pdu.c +1
-2@@ -6215,8 +6209,7 @@ int smb2_read(struct ksmbd_work *work) goto out; } - fp =ksmbd_lookup_fd_slow (work,le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { err = -ENOENT ;goto out;
fs/ksmbd/smb2pdu.c +1
-1@@ -6335,7 +6328,7 @@ static noinline int smb2_write_pipe(struct ksmbd_work *work)size_t length; length =le32_to_cpu (req->Length); - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId; if (le16_to_cpu(req->DataOffset) ==offsetof(struct smb2_write_req, Buffer)) {fs/ksmbd/smb2pdu.c +1
-2@@ -6471,8 +6464,7 @@ int smb2_write(struct ksmbd_work *work) goto out; } - fp =ksmbd_lookup_fd_slow (work,le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { err = -ENOENT ;goto out;
fs/ksmbd/smb2pdu.c +2
-5@@ -6584,12 +6576,9 @@ int smb2_flush(struct ksmbd_work *work)WORK_BUFFERS (work, req, rsp); -ksmbd_debug (SMB ,"SMB2_FLUSH called for fid %llu\n" , -le64_to_cpu (req->VolatileFileId)); +ksmbd_debug (SMB ,"SMB2_FLUSH called for fid %llu\n" , req->VolatileFileId); - err =ksmbd_vfs_fsync (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + err =ksmbd_vfs_fsync (work, req->VolatileFileId, req->PersistentFileId);if (err)goto out;
fs/ksmbd/smb2pdu.c +2
-5@@ -6804,12 +6793,9 @@ int smb2_lock(struct ksmbd_work *work)int prior_lock =0 ;ksmbd_debug (SMB ,"Received lock request\n" ); - fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp) { -ksmbd_debug (SMB ,"Invalid file id for lock : %llu\n" , -le64_to_cpu (req->VolatileFileId)); +ksmbd_debug (SMB ,"Invalid file id for lock : %llu\n" , req->VolatileFileId); err = -ENOENT ;goto out2; }fs/ksmbd/smb2pdu.c +5
-7@@ -7164,8 +7150,8 @@ static int fsctl_copychunk(struct ksmbd_work *work, ci_rsp = (struct copychunk_ioctl_rsp *)&rsp->Buffer[0 ]; - rsp->VolatileFileId =cpu_to_le64 (volatile_id); - rsp->PersistentFileId =cpu_to_le64 (persistent_id); + rsp->VolatileFileId = volatile_id; + rsp->PersistentFileId = persistent_id; ci_rsp->ChunksWritten =cpu_to_le32 (ksmbd_server_side_copy_max_chunk_count ()); ci_rsp->ChunkBytesWritten =@@ -7379,8 +7365,8 @@ static int fsctl_query_iface_info_ioctl(structksmbd_conn *conn, if (nii_rsp) nii_rsp->Next = 0; - rsp->PersistentFileId =cpu_to_le64 (SMB2_NO_FID ); - rsp->VolatileFileId =cpu_to_le64 (SMB2_NO_FID ); + rsp->PersistentFileId =SMB2_NO_FID ; + rsp->VolatileFileId =SMB2_NO_FID ;return nbytes; }@@ -7547,9 +7533,7 @@ static int fsctl_request_resume_key(struct ksmbd_work *work, {struct ksmbd_file *fp; - fp =ksmbd_lookup_fd_slow (work, -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId)); + fp =ksmbd_lookup_fd_slow (work, req->VolatileFileId, req->PersistentFileId);if (!fp)return
-ENOENT;fs/ksmbd/smb2pdu.c +6
-6@@ -7579,7 +7563,7 @@ int smb2_ioctl(struct ksmbd_work *work)if (work->next_smb2_rcv_hdr_off) { req =ksmbd_req_buf_next (work); rsp =ksmbd_resp_buf_next (work); -if (!has_file_id (le64_to_cpu (req->VolatileFileId))) { +if (!has_file_id (req->VolatileFileId)) {ksmbd_debug (SMB ,"Compound request set FID = %llu\n" , work->compound_fid); id = work->compound_fid;@@ -7590,7 +7574,7 @@ int smb2_ioctl(struct ksmbd_work *work) }if (!has_file_id (id)) - id =le64_to_cpu (req->VolatileFileId); + id = req->VolatileFileId;if (req->Flags !=cpu_to_le32 (SMB2_0_IOCTL_IS_FSCTL )) { rsp->hdr.Status =STATUS_NOT_SUPPORTED ;@@ -7656,8 +7640,8 @@ int smb2_ioctl(struct ksmbd_work *work) goto out; nbytes =sizeof (struct validate_negotiate_info_rsp ); - rsp->PersistentFileId =cpu_to_le64 (SMB2_NO_FID ); - rsp->VolatileFileId =cpu_to_le64 (SMB2_NO_FID ); + rsp->PersistentFileId =SMB2_NO_FID ; + rsp->VolatileFileId =SMB2_NO_FID ;break ;case FSCTL_QUERY_NETWORK_INTERFACE_INFO : ret =fsctl_query_iface_info_ioctl (conn, rsp, out_buf_len);@@ -7705,8 +7689,8 @@ int smb2_ioctl(struct ksmbd_work *work) (struct copychunk_ioctl_req *)&req->Buffer[0 ],le32_to_cpu (req->CntCode),le32_to_cpu (req->InputCount), -le64_to_cpu (req->VolatileFileId), -le64_to_cpu (req->PersistentFileId), + req->VolatileFileId, + req->PersistentFileId, rsp);break ;case FSCTL_SET_SPARSE :fs/ksmbd/smb2pdu.h +17
-17@@ -116,8 +116,8 @@ struct create_durable_reconn_req {union {__u8 Reserved[16 ];struct { -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } Fid; } Data; } __packed;@@ -126,8 +126,8 @@ struct create_durable_reconn_v2_req {struct create_context ccontext;__u8 Name[8 ];struct { -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } Fid;__u8 CreateGuid[16 ];__le32 Flags;@@ -269,8 +269,8 @@ struct smb2_ioctl_req {__le16 StructureSize;/* Must be 57 */ __le16 Reserved;/* offset from start of SMB2 header to write data */ __le32 CntCode; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 InputOffset;/* Reserved MBZ */ __le32 InputCount;__le32 MaxInputResponse;@@ -287,8 +287,8 @@ struct smb2_ioctl_rsp {__le16 StructureSize;/* Must be 49 */ __le16 Reserved;/* offset from start of SMB2 header to write data */ __le32 CntCode; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 InputOffset;/* Reserved MBZ */ __le32 InputCount;__le32 OutputOffset;@@ -357,7 +357,7 @@ struct file_object_buf_type1_ioctl_rsp { } __packed;struct resume_key_ioctl_rsp { -__le64 ResumeKey[3 ]; +__u64 ResumeKey[3 ];__le32 ContextLength;__u8 Context[4 ];/* ignored, Windows sets to 4 bytes of zero */ } __packed;@@ -432,8 +432,8 @@ struct smb2_lock_req {__le16 StructureSize;/* Must be 48 */ __le16 LockCount;__le32 Reserved; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;/* Followed by at least one */ struct smb2_lock_element locks[1 ]; } __packed;@@ -468,8 +468,8 @@ struct smb2_query_directory_req {__u8 FileInformationClass;__u8 Flags;__le32 FileIndex; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le16 FileNameOffset;__le16 FileNameLength;__le32 OutputBufferLength;@@ -515,8 +515,8 @@ struct smb2_query_info_req {__le32 InputBufferLength;__le32 AdditionalInformation;__le32 Flags; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__u8 Buffer[1 ]; } __packed;@@ -537,8 +537,8 @@ struct smb2_set_info_req {__le16 BufferOffset;__u16 Reserved;__le32 AdditionalInformation; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__u8 Buffer[1 ]; } __packed;
I agree this is the most practical way to address the issue, and any potential static checker warnings.
Have you tested on both endian clients I assume? Might be tricky to catch all the ops/cases, especially that cancel.
Quoted 295 lines · Paulo Alcantara
The client used to partially convert the fids to le64, while storing or sending them by using host endianness. This broke the client on big-endian machines. Instead of converting them to le64, store them as opaque integers and then avoid byteswapping when sending them over wire.
Signed-off-by Paulo Alcantara (SUSE) <[email protected]>--- fs/cifs/smb2misc.c | 4 +-- fs/cifs/smb2ops.c | 8 ++--- fs/cifs/smb2pdu.c | 63 +++++++++++++++++---------------------- fs/smbfs_common/smb2pdu.h | 24 +++++++-------- 4 files changed, 46 insertions(+), 53 deletions(-)fs/cifs/smb2misc.c +2
-2@@ -832,8 +832,8 @@ smb2_handle_cancelled_mid(struct mid_q_entry *mid, struct TCP_Server_Info *serve rc =__smb2_handle_cancelled_cmd (tcon,le16_to_cpu (hdr->Command),le64_to_cpu (hdr->MessageId), -le64_to_cpu (rsp->PersistentFileId), -le64_to_cpu (rsp->VolatileFileId)); + rsp->PersistentFileId, + rsp->VolatileFileId);if (rc)cifs_put_tcon (tcon);fs/cifs/smb2ops.c +4
-4@@ -900,8 +900,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,atomic_inc (&tcon->num_remote_opens); o_rsp = (struct smb2_create_rsp *)rsp_iov[0 ].iov_base; - oparms.fid->persistent_fid =le64_to_cpu (o_rsp->PersistentFileId); - oparms.fid->volatile_fid =le64_to_cpu (o_rsp->VolatileFileId); + oparms.fid->persistent_fid = o_rsp->PersistentFileId; + oparms.fid->volatile_fid = o_rsp->VolatileFileId;#ifdef CONFIG_CIFS_DEBUG2 oparms.fid->mid =le64_to_cpu (o_rsp->hdr.MessageId);#endif /* CIFS_DEBUG2 */ @@ -2410,8 +2410,8 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,cifs_dbg (FYI ,"query_dir_first: open failed rc=%d\n" , rc); goto qdf_free; } - fid->persistent_fid =le64_to_cpu (op_rsp->PersistentFileId); - fid->volatile_fid =le64_to_cpu (op_rsp->VolatileFileId); + fid->persistent_fid = op_rsp->PersistentFileId; + fid->volatile_fid = op_rsp->VolatileFileId;/* Anything else than ENODATA means a genuine error */ if (rc && rc != -ENODATA ) {fs/cifs/smb2pdu.c +28
-35@@ -2734,13 +2734,10 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode, goto err_free_req; } -trace_smb3_posix_mkdir_done (xid,le64_to_cpu (rsp->PersistentFileId), - tcon->tid, - ses->Suid,CREATE_NOT_FILE , -FILE_WRITE_ATTRIBUTES ); +trace_smb3_posix_mkdir_done (xid, rsp->PersistentFileId, tcon->tid, ses->Suid, +CREATE_NOT_FILE ,FILE_WRITE_ATTRIBUTES ); -SMB2_close (xid, tcon,le64_to_cpu (rsp->PersistentFileId), -le64_to_cpu (rsp->VolatileFileId)); +SMB2_close (xid, tcon, rsp->PersistentFileId, rsp->VolatileFileId);/* Eventually save off posix specific response info and timestaps */ @@ -3009,14 +3006,12 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, }else if (rsp ==NULL )/* unlikely to happen, but safer to check */ goto creat_exit;else -trace_smb3_open_done (xid,le64_to_cpu (rsp->PersistentFileId), - tcon->tid, - ses->Suid, oparms->create_options, - oparms->desired_access); +trace_smb3_open_done (xid, rsp->PersistentFileId, tcon->tid, ses->Suid, + oparms->create_options, oparms->desired_access);atomic_inc (&tcon->num_remote_opens); - oparms->fid->persistent_fid =le64_to_cpu (rsp->PersistentFileId); - oparms->fid->volatile_fid =le64_to_cpu (rsp->VolatileFileId); + oparms->fid->persistent_fid = rsp->PersistentFileId; + oparms->fid->volatile_fid = rsp->VolatileFileId; oparms->fid->access = oparms->desired_access;#ifdef CONFIG_CIFS_DEBUG2 oparms->fid->mid =le64_to_cpu (rsp->hdr.MessageId);@@ -3313,8 +3308,8 @@ SMB2_close_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,if (rc)return rc; - req->PersistentFileId =cpu_to_le64 (persistent_fid); - req->VolatileFileId =cpu_to_le64 (volatile_fid); + req->PersistentFileId = persistent_fid; + req->VolatileFileId = volatile_fid;if (query_attrs) req->Flags =SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB ;else @@ -3677,8 +3672,8 @@ SMB2_notify_init(const unsigned int xid, struct smb_rqst *rqst,if (rc)return rc; - req->PersistentFileId =cpu_to_le64 (persistent_fid); - req->VolatileFileId =cpu_to_le64 (volatile_fid); + req->PersistentFileId = persistent_fid; + req->VolatileFileId = volatile_fid;/* See note 354 of MS-SMB2, 64K max */ req->OutputBufferLength =cpu_to_le32 (SMB2_MAX_BUFFER_SIZE -MAX_SMB2_HDR_SIZE );@@ -3951,8 +3946,8 @@ SMB2_flush_init(const unsigned int xid, struct smb_rqst *rqst,if (rc)return rc; - req->PersistentFileId =cpu_to_le64 (persistent_fid); - req->VolatileFileId =cpu_to_le64 (volatile_fid); + req->PersistentFileId = persistent_fid; + req->VolatileFileId = volatile_fid; iov[0 ].iov_base = (char *)req; iov[0 ].iov_len = total_len;@@ -4033,8 +4028,8 @@ smb2_new_read_req(void **buf, unsigned int *total_len, shdr = &req->hdr; shdr->Id.SyncId.ProcessId =cpu_to_le32 (io_parms->pid); - req->PersistentFileId =cpu_to_le64 (io_parms->persistent_fid); - req->VolatileFileId =cpu_to_le64 (io_parms->volatile_fid); + req->PersistentFileId = io_parms->persistent_fid; + req->VolatileFileId = io_parms->volatile_fid; req->ReadChannelInfoOffset =0 ;/* reserved */ req->ReadChannelInfoLength =0 ;/* reserved */ req->Channel =0 ;/* reserved */ @@ -4094,8 +4089,8 @@ smb2_new_read_req(void **buf, unsigned int *total_len,*/ shdr->SessionId =cpu_to_le64 (0xFFFFFFFFFFFFFFFF ); shdr->Id.SyncId.TreeId =cpu_to_le32 (0xFFFFFFFF ); - req->PersistentFileId =cpu_to_le64 (0xFFFFFFFFFFFFFFFF ); - req->VolatileFileId =cpu_to_le64 (0xFFFFFFFFFFFFFFFF ); + req->PersistentFileId = (u64)-1 ; + req->VolatileFileId = (u64)-1 ; } }if (remaining_bytes > io_parms->length)@@ -4307,21 +4302,19 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,cifs_stats_fail_inc (io_parms->tcon,SMB2_READ_HE );cifs_dbg (VFS ,"Send error in read = %d\n" , rc);trace_smb3_read_err (xid, -le64_to_cpu (req->PersistentFileId), + req->PersistentFileId, io_parms->tcon->tid, ses->Suid, io_parms->offset, io_parms->length, rc); }else -trace_smb3_read_done (xid, -le64_to_cpu (req->PersistentFileId), - io_parms->tcon->tid, ses->Suid, - io_parms->offset,0 ); +trace_smb3_read_done (xid, req->PersistentFileId, io_parms->tcon->tid, + ses->Suid, io_parms->offset,0 );free_rsp_buf (resp_buftype, rsp_iov.iov_base);cifs_small_buf_release (req);return rc == -ENODATA ?0 : rc; }else trace_smb3_read_done (xid, -le64_to_cpu (req->PersistentFileId), + req->PersistentFileId, io_parms->tcon->tid, ses->Suid, io_parms->offset, io_parms->length);@@ -4463,8 +4456,8 @@ smb2_async_writev(struct cifs_writedata *wdata, shdr = (struct smb2_hdr *)req; shdr->Id.SyncId.ProcessId =cpu_to_le32 (wdata->cfile->pid); - req->PersistentFileId =cpu_to_le64 (wdata->cfile->fid.persistent_fid); - req->VolatileFileId =cpu_to_le64 (wdata->cfile->fid.volatile_fid); + req->PersistentFileId = wdata->cfile->fid.persistent_fid; + req->VolatileFileId = wdata->cfile->fid.volatile_fid; req->WriteChannelInfoOffset =0 ; req->WriteChannelInfoLength =0 ; req->Channel =0 ;@@ -4562,7 +4555,7 @@ smb2_async_writev(struct cifs_writedata *wdata,if (rc) {trace_smb3_write_err (0 /* no xid */ , -le64_to_cpu (req->PersistentFileId), + req->PersistentFileId, tcon->tid, tcon->ses->Suid, wdata->offset, wdata->bytes, rc);kref_put (&wdata->refcount, release);@@ -4615,8 +4608,8 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, req->hdr.Id.SyncId.ProcessId =cpu_to_le32 (io_parms->pid); - req->PersistentFileId =cpu_to_le64 (io_parms->persistent_fid); - req->VolatileFileId =cpu_to_le64 (io_parms->volatile_fid); + req->PersistentFileId = io_parms->persistent_fid; + req->VolatileFileId = io_parms->volatile_fid; req->WriteChannelInfoOffset =0 ; req->WriteChannelInfoLength =0 ; req->Channel =0 ;@@ -4645,7 +4638,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,if (rc) {trace_smb3_write_err (xid, -le64_to_cpu (req->PersistentFileId), + req->PersistentFileId, io_parms->tcon->tid, io_parms->tcon->ses->Suid, io_parms->offset, io_parms->length, rc);@@ -4654,7 +4647,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms, }else { *nbytes =le32_to_cpu (rsp->DataLength);trace_smb3_write_done (xid, -le64_to_cpu (req->PersistentFileId), + req->PersistentFileId, io_parms->tcon->tid, io_parms->tcon->ses->Suid, io_parms->offset, *nbytes);fs/smbfs_common/smb2pdu.h +12
-12@@ -608,8 +608,8 @@ struct smb2_close_req {__le16 StructureSize;/* Must be 24 */ __le16 Flags;__le32 Reserved; -__le64 PersistentFileId;/* opaque endianness */ -__le64 VolatileFileId;/* opaque endianness */ +__u64 PersistentFileId;/* opaque endianness */ +__u64 VolatileFileId;/* opaque endianness */ } __packed;/* @@ -653,8 +653,8 @@ struct smb2_read_req {__u8 Flags;/* MBZ unless SMB3.02 or later */ __le32 Length;__le64 Offset; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 MinimumCount;__le32 Channel;/* MBZ except for SMB3 or later */ __le32 RemainingBytes;@@ -692,8 +692,8 @@ struct smb2_write_req {__le16 DataOffset;/* offset from start of SMB2 header to write data */ __le32 Length;__le64 Offset; -__le64 PersistentFileId;/* opaque endianness */ -__le64 VolatileFileId;/* opaque endianness */ +__u64 PersistentFileId;/* opaque endianness */ +__u64 VolatileFileId;/* opaque endianness */ __le32 Channel;/* MBZ unless SMB3.02 or later */ __le32 RemainingBytes;__le16 WriteChannelInfoOffset;@@ -722,8 +722,8 @@ struct smb2_flush_req {__le16 StructureSize;/* Must be 24 */ __le16 Reserved1;__le32 Reserved2; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId; } __packed;struct smb2_flush_rsp {@@ -769,8 +769,8 @@ struct smb2_change_notify_req {__le16 StructureSize;__le16 Flags;__le32 OutputBufferLength; -__le64 PersistentFileId;/* opaque endianness */ -__le64 VolatileFileId;/* opaque endianness */ +__u64 PersistentFileId;/* opaque endianness */ +__u64 VolatileFileId;/* opaque endianness */ __le32 CompletionFilter;__u32 Reserved; } __packed;@@ -978,8 +978,8 @@ struct smb2_create_rsp {__le64 EndofFile;__le32 FileAttributes;__le32 Reserved2; -__le64 PersistentFileId; -__le64 VolatileFileId; +__u64 PersistentFileId; +__u64 VolatileFileId;__le32 CreateContextsOffset;__le32 CreateContextsLength;__u8 Buffer[1 ];
Quoted 5 lines · Tom Talpey
I agree this is the most practical way to address the issue, and any potential static checker warnings.
Have you tested on both endian clients I assume? Might be tricky to catch all the ops/cases, especially that cancel.
I did some quick tests on x86_64 and s390x under QEMU against Windows 2022 server and ksmbd and all seemed to work. Hopefully Steve & Namjae can also help with more tests.
Quoted 1 line
Reviewed-by Tom Talpey <[email protected]>
Thanks!
Namjae Jeon
maintainer2022-03-22 6:48 GMT+09:00, Paulo Alcantara <[email protected]>:
Quoted 5 lines
Quoted 3 lines · Tom Talpey
I agree this is the most practical way to address the issue, and any potential static checker warnings.
Quoted 8 lines
Quoted 2 lines
Have you tested on both endian clients I assume? Might be tricky to catch all the ops/cases, especially that cancel.
I did some quick tests on
x86_64and s390x under QEMU against Windows 2022 server and ksmbd and all seemed to work. Hopefully Steve & Namjae can also help with more tests.Quoted 1 line
Reviewed-by Tom Talpey <[email protected]>
^
Minor nit, B must be lowercase. This will cause a warning from checkpatch.pl.
And looks good to me too, Reviewed-by: Namjae Jeon <[email protected]>
Thanks:)
Quoted 3 lines
Thanks!