Skip to content

Commit c7803b0

Browse files
committed
smb3: fix ksmbd bigendian bug in oplock break, and move its struct to smbfs_common
Fix an endian bug in ksmbd for one remaining use of Persistent/VolatileFid that unnecessarily converted it (it is an opaque endian field that does not need to be and should not be converted) in oplock_break for ksmbd, and move the definitions for the oplock and lease break protocol requests and responses to fs/smbfs_common/smb2pdu.h Also move a few more definitions for various protocol requests that were duplicated (in fs/cifs/smb2pdu.h and fs/ksmbd/smb2pdu.h) into fs/smbfs_common/smb2pdu.h including: - various ioctls and reparse structures - validate negotiate request and response structs - duplicate extents structs Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Reviewed-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent fdf59eb commit c7803b0

5 files changed

Lines changed: 119 additions & 191 deletions

File tree

fs/cifs/smb2pdu.h

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,6 @@ struct copychunk_ioctl {
229229
__u32 Reserved2;
230230
} __packed;
231231

232-
/* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
233-
struct file_zero_data_information {
234-
__le64 FileOffset;
235-
__le64 BeyondFinalZero;
236-
} __packed;
237-
238232
struct copychunk_ioctl_rsp {
239233
__le32 ChunksWritten;
240234
__le32 ChunkBytesWritten;
@@ -288,53 +282,6 @@ struct fsctl_get_integrity_information_rsp {
288282
/* Integrity flags for above */
289283
#define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
290284

291-
/* Reparse structures - see MS-FSCC 2.1.2 */
292-
293-
/* struct fsctl_reparse_info_req is empty, only response structs (see below) */
294-
295-
struct reparse_data_buffer {
296-
__le32 ReparseTag;
297-
__le16 ReparseDataLength;
298-
__u16 Reserved;
299-
__u8 DataBuffer[]; /* Variable Length */
300-
} __packed;
301-
302-
struct reparse_guid_data_buffer {
303-
__le32 ReparseTag;
304-
__le16 ReparseDataLength;
305-
__u16 Reserved;
306-
__u8 ReparseGuid[16];
307-
__u8 DataBuffer[]; /* Variable Length */
308-
} __packed;
309-
310-
struct reparse_mount_point_data_buffer {
311-
__le32 ReparseTag;
312-
__le16 ReparseDataLength;
313-
__u16 Reserved;
314-
__le16 SubstituteNameOffset;
315-
__le16 SubstituteNameLength;
316-
__le16 PrintNameOffset;
317-
__le16 PrintNameLength;
318-
__u8 PathBuffer[]; /* Variable Length */
319-
} __packed;
320-
321-
#define SYMLINK_FLAG_RELATIVE 0x00000001
322-
323-
struct reparse_symlink_data_buffer {
324-
__le32 ReparseTag;
325-
__le16 ReparseDataLength;
326-
__u16 Reserved;
327-
__le16 SubstituteNameOffset;
328-
__le16 SubstituteNameLength;
329-
__le16 PrintNameOffset;
330-
__le16 PrintNameLength;
331-
__le32 Flags;
332-
__u8 PathBuffer[]; /* Variable Length */
333-
} __packed;
334-
335-
/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
336-
337-
338285
/* See MS-DFSC 2.2.2 */
339286
struct fsctl_get_dfs_referral_req {
340287
__le16 MaxReferralLevel;
@@ -350,22 +297,6 @@ struct network_resiliency_req {
350297
} __packed;
351298
/* There is no buffer for the response ie no struct network_resiliency_rsp */
352299

353-
354-
struct validate_negotiate_info_req {
355-
__le32 Capabilities;
356-
__u8 Guid[SMB2_CLIENT_GUID_SIZE];
357-
__le16 SecurityMode;
358-
__le16 DialectCount;
359-
__le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
360-
} __packed;
361-
362-
struct validate_negotiate_info_rsp {
363-
__le32 Capabilities;
364-
__u8 Guid[SMB2_CLIENT_GUID_SIZE];
365-
__le16 SecurityMode;
366-
__le16 Dialect; /* Dialect in use for the connection */
367-
} __packed;
368-
369300
#define RSS_CAPABLE cpu_to_le32(0x00000001)
370301
#define RDMA_CAPABLE cpu_to_le32(0x00000002)
371302

@@ -401,56 +332,13 @@ struct compress_ioctl {
401332
__le16 CompressionState; /* See cifspdu.h for possible flag values */
402333
} __packed;
403334

404-
struct duplicate_extents_to_file {
405-
__u64 PersistentFileHandle; /* source file handle, opaque endianness */
406-
__u64 VolatileFileHandle;
407-
__le64 SourceFileOffset;
408-
__le64 TargetFileOffset;
409-
__le64 ByteCount; /* Bytes to be copied */
410-
} __packed;
411-
412335
/*
413336
* Maximum number of iovs we need for an ioctl request.
414337
* [0] : struct smb2_ioctl_req
415338
* [1] : in_data
416339
*/
417340
#define SMB2_IOCTL_IOV_SIZE 2
418341

419-
struct smb2_oplock_break {
420-
struct smb2_hdr hdr;
421-
__le16 StructureSize; /* Must be 24 */
422-
__u8 OplockLevel;
423-
__u8 Reserved;
424-
__le32 Reserved2;
425-
__u64 PersistentFid;
426-
__u64 VolatileFid;
427-
} __packed;
428-
429-
#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
430-
431-
struct smb2_lease_break {
432-
struct smb2_hdr hdr;
433-
__le16 StructureSize; /* Must be 44 */
434-
__le16 Epoch;
435-
__le32 Flags;
436-
__u8 LeaseKey[16];
437-
__le32 CurrentLeaseState;
438-
__le32 NewLeaseState;
439-
__le32 BreakReason;
440-
__le32 AccessMaskHint;
441-
__le32 ShareMaskHint;
442-
} __packed;
443-
444-
struct smb2_lease_ack {
445-
struct smb2_hdr hdr;
446-
__le16 StructureSize; /* Must be 36 */
447-
__le16 Reserved;
448-
__le32 Flags;
449-
__u8 LeaseKey[16];
450-
__le32 LeaseState;
451-
__le64 LeaseDuration;
452-
} __packed;
453-
454342
/*
455343
* PDU query infolevel structure definitions
456344
* BB consider moving to a different header

fs/ksmbd/oplock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,8 @@ static void __smb2_oplock_break_noti(struct work_struct *wk)
656656
rsp->OplockLevel = SMB2_OPLOCK_LEVEL_NONE;
657657
rsp->Reserved = 0;
658658
rsp->Reserved2 = 0;
659-
rsp->PersistentFid = cpu_to_le64(fp->persistent_id);
660-
rsp->VolatileFid = cpu_to_le64(fp->volatile_id);
659+
rsp->PersistentFid = fp->persistent_id;
660+
rsp->VolatileFid = fp->volatile_id;
661661

662662
inc_rfc1001_len(work->response_buf, 24);
663663

fs/ksmbd/smb2pdu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7887,8 +7887,8 @@ static void smb20_oplock_break_ack(struct ksmbd_work *work)
78877887
char req_oplevel = 0, rsp_oplevel = 0;
78887888
unsigned int oplock_change_type;
78897889

7890-
volatile_id = le64_to_cpu(req->VolatileFid);
7891-
persistent_id = le64_to_cpu(req->PersistentFid);
7890+
volatile_id = req->VolatileFid;
7891+
persistent_id = req->PersistentFid;
78927892
req_oplevel = req->OplockLevel;
78937893
ksmbd_debug(OPLOCK, "v_id %llu, p_id %llu request oplock level %d\n",
78947894
volatile_id, persistent_id, req_oplevel);
@@ -7983,8 +7983,8 @@ static void smb20_oplock_break_ack(struct ksmbd_work *work)
79837983
rsp->OplockLevel = rsp_oplevel;
79847984
rsp->Reserved = 0;
79857985
rsp->Reserved2 = 0;
7986-
rsp->VolatileFid = cpu_to_le64(volatile_id);
7987-
rsp->PersistentFid = cpu_to_le64(persistent_id);
7986+
rsp->VolatileFid = volatile_id;
7987+
rsp->PersistentFid = persistent_id;
79887988
inc_rfc1001_len(work->response_buf, 24);
79897989
return;
79907990

fs/ksmbd/smb2pdu.h

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -169,29 +169,6 @@ struct smb2_buffer_desc_v1 {
169169

170170
#define SMB2_0_IOCTL_IS_FSCTL 0x00000001
171171

172-
struct duplicate_extents_to_file {
173-
__u64 PersistentFileHandle; /* source file handle, opaque endianness */
174-
__u64 VolatileFileHandle;
175-
__le64 SourceFileOffset;
176-
__le64 TargetFileOffset;
177-
__le64 ByteCount; /* Bytes to be copied */
178-
} __packed;
179-
180-
struct validate_negotiate_info_req {
181-
__le32 Capabilities;
182-
__u8 Guid[SMB2_CLIENT_GUID_SIZE];
183-
__le16 SecurityMode;
184-
__le16 DialectCount;
185-
__le16 Dialects[1]; /* dialect (someday maybe list) client asked for */
186-
} __packed;
187-
188-
struct validate_negotiate_info_rsp {
189-
__le32 Capabilities;
190-
__u8 Guid[SMB2_CLIENT_GUID_SIZE];
191-
__le16 SecurityMode;
192-
__le16 Dialect; /* Dialect in use for the connection */
193-
} __packed;
194-
195172
struct smb_sockaddr_in {
196173
__be16 Port;
197174
__be32 IPv4address;
@@ -265,18 +242,6 @@ struct file_sparse {
265242
__u8 SetSparse;
266243
} __packed;
267244

268-
struct file_zero_data_information {
269-
__le64 FileOffset;
270-
__le64 BeyondFinalZero;
271-
} __packed;
272-
273-
struct reparse_data_buffer {
274-
__le32 ReparseTag;
275-
__le16 ReparseDataLength;
276-
__u16 Reserved;
277-
__u8 DataBuffer[]; /* Variable Length */
278-
} __packed;
279-
280245
/* FILE Info response size */
281246
#define FILE_DIRECTORY_INFORMATION_SIZE 1
282247
#define FILE_FULL_DIRECTORY_INFORMATION_SIZE 2
@@ -332,49 +297,11 @@ struct fs_type_info {
332297
long magic_number;
333298
} __packed;
334299

335-
struct smb2_oplock_break {
336-
struct smb2_hdr hdr;
337-
__le16 StructureSize; /* Must be 24 */
338-
__u8 OplockLevel;
339-
__u8 Reserved;
340-
__le32 Reserved2;
341-
__le64 PersistentFid;
342-
__le64 VolatileFid;
343-
} __packed;
344-
345-
#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
346-
347-
struct smb2_lease_break {
348-
struct smb2_hdr hdr;
349-
__le16 StructureSize; /* Must be 44 */
350-
__le16 Epoch;
351-
__le32 Flags;
352-
__u8 LeaseKey[16];
353-
__le32 CurrentLeaseState;
354-
__le32 NewLeaseState;
355-
__le32 BreakReason;
356-
__le32 AccessMaskHint;
357-
__le32 ShareMaskHint;
358-
} __packed;
359-
360-
struct smb2_lease_ack {
361-
struct smb2_hdr hdr;
362-
__le16 StructureSize; /* Must be 36 */
363-
__le16 Reserved;
364-
__le32 Flags;
365-
__u8 LeaseKey[16];
366-
__le32 LeaseState;
367-
__le64 LeaseDuration;
368-
} __packed;
369-
370300
/*
371301
* PDU query infolevel structure definitions
372302
* BB consider moving to a different header
373303
*/
374304

375-
#define OP_BREAK_STRUCT_SIZE_20 24
376-
#define OP_BREAK_STRUCT_SIZE_21 36
377-
378305
struct smb2_file_access_info {
379306
__le32 AccessFlags;
380307
} __packed;

0 commit comments

Comments
 (0)