Skip to content

Commit 351a59d

Browse files
Paulo Alcantarasmfrench
authored andcommitted
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. Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Reviewed-by: Namjae Jeon <linkinjeon@kernel.org> Reviewed-by: Tom Talpey <tom@talpey.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 8708b10 commit 351a59d

4 files changed

Lines changed: 46 additions & 53 deletions

File tree

fs/cifs/smb2misc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,8 @@ smb2_handle_cancelled_mid(struct mid_q_entry *mid, struct TCP_Server_Info *serve
832832
rc = __smb2_handle_cancelled_cmd(tcon,
833833
le16_to_cpu(hdr->Command),
834834
le64_to_cpu(hdr->MessageId),
835-
le64_to_cpu(rsp->PersistentFileId),
836-
le64_to_cpu(rsp->VolatileFileId));
835+
rsp->PersistentFileId,
836+
rsp->VolatileFileId);
837837
if (rc)
838838
cifs_put_tcon(tcon);
839839

fs/cifs/smb2ops.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,8 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
897897
atomic_inc(&tcon->num_remote_opens);
898898

899899
o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
900-
oparms.fid->persistent_fid = le64_to_cpu(o_rsp->PersistentFileId);
901-
oparms.fid->volatile_fid = le64_to_cpu(o_rsp->VolatileFileId);
900+
oparms.fid->persistent_fid = o_rsp->PersistentFileId;
901+
oparms.fid->volatile_fid = o_rsp->VolatileFileId;
902902
#ifdef CONFIG_CIFS_DEBUG2
903903
oparms.fid->mid = le64_to_cpu(o_rsp->hdr.MessageId);
904904
#endif /* CIFS_DEBUG2 */
@@ -2401,8 +2401,8 @@ smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
24012401
cifs_dbg(FYI, "query_dir_first: open failed rc=%d\n", rc);
24022402
goto qdf_free;
24032403
}
2404-
fid->persistent_fid = le64_to_cpu(op_rsp->PersistentFileId);
2405-
fid->volatile_fid = le64_to_cpu(op_rsp->VolatileFileId);
2404+
fid->persistent_fid = op_rsp->PersistentFileId;
2405+
fid->volatile_fid = op_rsp->VolatileFileId;
24062406

24072407
/* Anything else than ENODATA means a genuine error */
24082408
if (rc && rc != -ENODATA) {

fs/cifs/smb2pdu.c

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,13 +2734,10 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,
27342734
goto err_free_req;
27352735
}
27362736

2737-
trace_smb3_posix_mkdir_done(xid, le64_to_cpu(rsp->PersistentFileId),
2738-
tcon->tid,
2739-
ses->Suid, CREATE_NOT_FILE,
2740-
FILE_WRITE_ATTRIBUTES);
2737+
trace_smb3_posix_mkdir_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid,
2738+
CREATE_NOT_FILE, FILE_WRITE_ATTRIBUTES);
27412739

2742-
SMB2_close(xid, tcon, le64_to_cpu(rsp->PersistentFileId),
2743-
le64_to_cpu(rsp->VolatileFileId));
2740+
SMB2_close(xid, tcon, rsp->PersistentFileId, rsp->VolatileFileId);
27442741

27452742
/* Eventually save off posix specific response info and timestaps */
27462743

@@ -3009,14 +3006,12 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
30093006
} else if (rsp == NULL) /* unlikely to happen, but safer to check */
30103007
goto creat_exit;
30113008
else
3012-
trace_smb3_open_done(xid, le64_to_cpu(rsp->PersistentFileId),
3013-
tcon->tid,
3014-
ses->Suid, oparms->create_options,
3015-
oparms->desired_access);
3009+
trace_smb3_open_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid,
3010+
oparms->create_options, oparms->desired_access);
30163011

30173012
atomic_inc(&tcon->num_remote_opens);
3018-
oparms->fid->persistent_fid = le64_to_cpu(rsp->PersistentFileId);
3019-
oparms->fid->volatile_fid = le64_to_cpu(rsp->VolatileFileId);
3013+
oparms->fid->persistent_fid = rsp->PersistentFileId;
3014+
oparms->fid->volatile_fid = rsp->VolatileFileId;
30203015
oparms->fid->access = oparms->desired_access;
30213016
#ifdef CONFIG_CIFS_DEBUG2
30223017
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,
33133308
if (rc)
33143309
return rc;
33153310

3316-
req->PersistentFileId = cpu_to_le64(persistent_fid);
3317-
req->VolatileFileId = cpu_to_le64(volatile_fid);
3311+
req->PersistentFileId = persistent_fid;
3312+
req->VolatileFileId = volatile_fid;
33183313
if (query_attrs)
33193314
req->Flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB;
33203315
else
@@ -3677,8 +3672,8 @@ SMB2_notify_init(const unsigned int xid, struct smb_rqst *rqst,
36773672
if (rc)
36783673
return rc;
36793674

3680-
req->PersistentFileId = cpu_to_le64(persistent_fid);
3681-
req->VolatileFileId = cpu_to_le64(volatile_fid);
3675+
req->PersistentFileId = persistent_fid;
3676+
req->VolatileFileId = volatile_fid;
36823677
/* See note 354 of MS-SMB2, 64K max */
36833678
req->OutputBufferLength =
36843679
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,
39513946
if (rc)
39523947
return rc;
39533948

3954-
req->PersistentFileId = cpu_to_le64(persistent_fid);
3955-
req->VolatileFileId = cpu_to_le64(volatile_fid);
3949+
req->PersistentFileId = persistent_fid;
3950+
req->VolatileFileId = volatile_fid;
39563951

39573952
iov[0].iov_base = (char *)req;
39583953
iov[0].iov_len = total_len;
@@ -4033,8 +4028,8 @@ smb2_new_read_req(void **buf, unsigned int *total_len,
40334028
shdr = &req->hdr;
40344029
shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid);
40354030

4036-
req->PersistentFileId = cpu_to_le64(io_parms->persistent_fid);
4037-
req->VolatileFileId = cpu_to_le64(io_parms->volatile_fid);
4031+
req->PersistentFileId = io_parms->persistent_fid;
4032+
req->VolatileFileId = io_parms->volatile_fid;
40384033
req->ReadChannelInfoOffset = 0; /* reserved */
40394034
req->ReadChannelInfoLength = 0; /* reserved */
40404035
req->Channel = 0; /* reserved */
@@ -4094,8 +4089,8 @@ smb2_new_read_req(void **buf, unsigned int *total_len,
40944089
*/
40954090
shdr->SessionId = cpu_to_le64(0xFFFFFFFFFFFFFFFF);
40964091
shdr->Id.SyncId.TreeId = cpu_to_le32(0xFFFFFFFF);
4097-
req->PersistentFileId = cpu_to_le64(0xFFFFFFFFFFFFFFFF);
4098-
req->VolatileFileId = cpu_to_le64(0xFFFFFFFFFFFFFFFF);
4092+
req->PersistentFileId = (u64)-1;
4093+
req->VolatileFileId = (u64)-1;
40994094
}
41004095
}
41014096
if (remaining_bytes > io_parms->length)
@@ -4307,21 +4302,19 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
43074302
cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE);
43084303
cifs_dbg(VFS, "Send error in read = %d\n", rc);
43094304
trace_smb3_read_err(xid,
4310-
le64_to_cpu(req->PersistentFileId),
4305+
req->PersistentFileId,
43114306
io_parms->tcon->tid, ses->Suid,
43124307
io_parms->offset, io_parms->length,
43134308
rc);
43144309
} else
4315-
trace_smb3_read_done(xid,
4316-
le64_to_cpu(req->PersistentFileId),
4317-
io_parms->tcon->tid, ses->Suid,
4318-
io_parms->offset, 0);
4310+
trace_smb3_read_done(xid, req->PersistentFileId, io_parms->tcon->tid,
4311+
ses->Suid, io_parms->offset, 0);
43194312
free_rsp_buf(resp_buftype, rsp_iov.iov_base);
43204313
cifs_small_buf_release(req);
43214314
return rc == -ENODATA ? 0 : rc;
43224315
} else
43234316
trace_smb3_read_done(xid,
4324-
le64_to_cpu(req->PersistentFileId),
4317+
req->PersistentFileId,
43254318
io_parms->tcon->tid, ses->Suid,
43264319
io_parms->offset, io_parms->length);
43274320

@@ -4463,8 +4456,8 @@ smb2_async_writev(struct cifs_writedata *wdata,
44634456
shdr = (struct smb2_hdr *)req;
44644457
shdr->Id.SyncId.ProcessId = cpu_to_le32(wdata->cfile->pid);
44654458

4466-
req->PersistentFileId = cpu_to_le64(wdata->cfile->fid.persistent_fid);
4467-
req->VolatileFileId = cpu_to_le64(wdata->cfile->fid.volatile_fid);
4459+
req->PersistentFileId = wdata->cfile->fid.persistent_fid;
4460+
req->VolatileFileId = wdata->cfile->fid.volatile_fid;
44684461
req->WriteChannelInfoOffset = 0;
44694462
req->WriteChannelInfoLength = 0;
44704463
req->Channel = 0;
@@ -4562,7 +4555,7 @@ smb2_async_writev(struct cifs_writedata *wdata,
45624555

45634556
if (rc) {
45644557
trace_smb3_write_err(0 /* no xid */,
4565-
le64_to_cpu(req->PersistentFileId),
4558+
req->PersistentFileId,
45664559
tcon->tid, tcon->ses->Suid, wdata->offset,
45674560
wdata->bytes, rc);
45684561
kref_put(&wdata->refcount, release);
@@ -4615,8 +4608,8 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
46154608

46164609
req->hdr.Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid);
46174610

4618-
req->PersistentFileId = cpu_to_le64(io_parms->persistent_fid);
4619-
req->VolatileFileId = cpu_to_le64(io_parms->volatile_fid);
4611+
req->PersistentFileId = io_parms->persistent_fid;
4612+
req->VolatileFileId = io_parms->volatile_fid;
46204613
req->WriteChannelInfoOffset = 0;
46214614
req->WriteChannelInfoLength = 0;
46224615
req->Channel = 0;
@@ -4645,7 +4638,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
46454638

46464639
if (rc) {
46474640
trace_smb3_write_err(xid,
4648-
le64_to_cpu(req->PersistentFileId),
4641+
req->PersistentFileId,
46494642
io_parms->tcon->tid,
46504643
io_parms->tcon->ses->Suid,
46514644
io_parms->offset, io_parms->length, rc);
@@ -4654,7 +4647,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
46544647
} else {
46554648
*nbytes = le32_to_cpu(rsp->DataLength);
46564649
trace_smb3_write_done(xid,
4657-
le64_to_cpu(req->PersistentFileId),
4650+
req->PersistentFileId,
46584651
io_parms->tcon->tid,
46594652
io_parms->tcon->ses->Suid,
46604653
io_parms->offset, *nbytes);

fs/smbfs_common/smb2pdu.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,8 @@ struct smb2_close_req {
608608
__le16 StructureSize; /* Must be 24 */
609609
__le16 Flags;
610610
__le32 Reserved;
611-
__le64 PersistentFileId; /* opaque endianness */
612-
__le64 VolatileFileId; /* opaque endianness */
611+
__u64 PersistentFileId; /* opaque endianness */
612+
__u64 VolatileFileId; /* opaque endianness */
613613
} __packed;
614614

615615
/*
@@ -653,8 +653,8 @@ struct smb2_read_req {
653653
__u8 Flags; /* MBZ unless SMB3.02 or later */
654654
__le32 Length;
655655
__le64 Offset;
656-
__le64 PersistentFileId;
657-
__le64 VolatileFileId;
656+
__u64 PersistentFileId;
657+
__u64 VolatileFileId;
658658
__le32 MinimumCount;
659659
__le32 Channel; /* MBZ except for SMB3 or later */
660660
__le32 RemainingBytes;
@@ -692,8 +692,8 @@ struct smb2_write_req {
692692
__le16 DataOffset; /* offset from start of SMB2 header to write data */
693693
__le32 Length;
694694
__le64 Offset;
695-
__le64 PersistentFileId; /* opaque endianness */
696-
__le64 VolatileFileId; /* opaque endianness */
695+
__u64 PersistentFileId; /* opaque endianness */
696+
__u64 VolatileFileId; /* opaque endianness */
697697
__le32 Channel; /* MBZ unless SMB3.02 or later */
698698
__le32 RemainingBytes;
699699
__le16 WriteChannelInfoOffset;
@@ -722,8 +722,8 @@ struct smb2_flush_req {
722722
__le16 StructureSize; /* Must be 24 */
723723
__le16 Reserved1;
724724
__le32 Reserved2;
725-
__le64 PersistentFileId;
726-
__le64 VolatileFileId;
725+
__u64 PersistentFileId;
726+
__u64 VolatileFileId;
727727
} __packed;
728728

729729
struct smb2_flush_rsp {
@@ -769,8 +769,8 @@ struct smb2_change_notify_req {
769769
__le16 StructureSize;
770770
__le16 Flags;
771771
__le32 OutputBufferLength;
772-
__le64 PersistentFileId; /* opaque endianness */
773-
__le64 VolatileFileId; /* opaque endianness */
772+
__u64 PersistentFileId; /* opaque endianness */
773+
__u64 VolatileFileId; /* opaque endianness */
774774
__le32 CompletionFilter;
775775
__u32 Reserved;
776776
} __packed;
@@ -978,8 +978,8 @@ struct smb2_create_rsp {
978978
__le64 EndofFile;
979979
__le32 FileAttributes;
980980
__le32 Reserved2;
981-
__le64 PersistentFileId;
982-
__le64 VolatileFileId;
981+
__u64 PersistentFileId;
982+
__u64 VolatileFileId;
983983
__le32 CreateContextsOffset;
984984
__le32 CreateContextsLength;
985985
__u8 Buffer[1];

0 commit comments

Comments
 (0)