aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Shilovsky <pshilov@microsoft.com>2016-10-24 18:33:04 -0400
committerSteve French <smfrench@gmail.com>2017-02-01 17:46:34 -0500
commit31473fc4f9653b73750d3792ffce6a6e1bdf0da7 (patch)
treebb789f590f828d3da748de876a7fafa43e654e7a
parent9c25702cee1405099f982894c865c163de7909a8 (diff)
CIFS: Separate SMB2 header structure
In order to support compounding and encryption we need to separate RFC1001 length field and SMB2 header structure because the protocol treats them differently. This change will allow to simplify parsing of such complex SMB2 packets further. Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
-rw-r--r--fs/cifs/smb2glob.h5
-rw-r--r--fs/cifs/smb2maperror.c5
-rw-r--r--fs/cifs/smb2misc.c61
-rw-r--r--fs/cifs/smb2ops.c26
-rw-r--r--fs/cifs/smb2pdu.c132
-rw-r--r--fs/cifs/smb2pdu.h12
-rw-r--r--fs/cifs/smb2transport.c81
7 files changed, 174 insertions, 148 deletions
diff --git a/fs/cifs/smb2glob.h b/fs/cifs/smb2glob.h
index 0ffa18094335..401a5d856636 100644
--- a/fs/cifs/smb2glob.h
+++ b/fs/cifs/smb2glob.h
@@ -61,4 +61,9 @@
61/* Maximum buffer size value we can send with 1 credit */ 61/* Maximum buffer size value we can send with 1 credit */
62#define SMB2_MAX_BUFFER_SIZE 65536 62#define SMB2_MAX_BUFFER_SIZE 65536
63 63
64static inline struct smb2_sync_hdr *get_sync_hdr(void *buf)
65{
66 return &(((struct smb2_hdr *)buf)->sync_hdr);
67}
68
64#endif /* _SMB2_GLOB_H */ 69#endif /* _SMB2_GLOB_H */
diff --git a/fs/cifs/smb2maperror.c b/fs/cifs/smb2maperror.c
index 8257a5a97cc0..3030a9dfb0dd 100644
--- a/fs/cifs/smb2maperror.c
+++ b/fs/cifs/smb2maperror.c
@@ -26,6 +26,7 @@
26#include "smb2pdu.h" 26#include "smb2pdu.h"
27#include "smb2proto.h" 27#include "smb2proto.h"
28#include "smb2status.h" 28#include "smb2status.h"
29#include "smb2glob.h"
29 30
30struct status_to_posix_error { 31struct status_to_posix_error {
31 __le32 smb2_status; 32 __le32 smb2_status;
@@ -2449,10 +2450,10 @@ smb2_print_status(__le32 status)
2449int 2450int
2450map_smb2_to_linux_error(char *buf, bool log_err) 2451map_smb2_to_linux_error(char *buf, bool log_err)
2451{ 2452{
2452 struct smb2_hdr *hdr = (struct smb2_hdr *)buf; 2453 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
2453 unsigned int i; 2454 unsigned int i;
2454 int rc = -EIO; 2455 int rc = -EIO;
2455 __le32 smb2err = hdr->Status; 2456 __le32 smb2err = shdr->Status;
2456 2457
2457 if (smb2err == 0) 2458 if (smb2err == 0)
2458 return 0; 2459 return 0;
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
index 3d383489b9cf..fd516ea8b8f8 100644
--- a/fs/cifs/smb2misc.c
+++ b/fs/cifs/smb2misc.c
@@ -28,31 +28,32 @@
28#include "cifs_debug.h" 28#include "cifs_debug.h"
29#include "cifs_unicode.h" 29#include "cifs_unicode.h"
30#include "smb2status.h" 30#include "smb2status.h"
31#include "smb2glob.h"
31 32
32static int 33static int
33check_smb2_hdr(struct smb2_hdr *hdr, __u64 mid) 34check_smb2_hdr(struct smb2_sync_hdr *shdr, __u64 mid)
34{ 35{
35 __u64 wire_mid = le64_to_cpu(hdr->MessageId); 36 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
36 37
37 /* 38 /*
38 * Make sure that this really is an SMB, that it is a response, 39 * Make sure that this really is an SMB, that it is a response,
39 * and that the message ids match. 40 * and that the message ids match.
40 */ 41 */
41 if ((hdr->ProtocolId == SMB2_PROTO_NUMBER) && 42 if ((shdr->ProtocolId == SMB2_PROTO_NUMBER) &&
42 (mid == wire_mid)) { 43 (mid == wire_mid)) {
43 if (hdr->Flags & SMB2_FLAGS_SERVER_TO_REDIR) 44 if (shdr->Flags & SMB2_FLAGS_SERVER_TO_REDIR)
44 return 0; 45 return 0;
45 else { 46 else {
46 /* only one valid case where server sends us request */ 47 /* only one valid case where server sends us request */
47 if (hdr->Command == SMB2_OPLOCK_BREAK) 48 if (shdr->Command == SMB2_OPLOCK_BREAK)
48 return 0; 49 return 0;
49 else 50 else
50 cifs_dbg(VFS, "Received Request not response\n"); 51 cifs_dbg(VFS, "Received Request not response\n");
51 } 52 }
52 } else { /* bad signature or mid */ 53 } else { /* bad signature or mid */
53 if (hdr->ProtocolId != SMB2_PROTO_NUMBER) 54 if (shdr->ProtocolId != SMB2_PROTO_NUMBER)
54 cifs_dbg(VFS, "Bad protocol string signature header %x\n", 55 cifs_dbg(VFS, "Bad protocol string signature header %x\n",
55 le32_to_cpu(hdr->ProtocolId)); 56 le32_to_cpu(shdr->ProtocolId));
56 if (mid != wire_mid) 57 if (mid != wire_mid)
57 cifs_dbg(VFS, "Mids do not match: %llu and %llu\n", 58 cifs_dbg(VFS, "Mids do not match: %llu and %llu\n",
58 mid, wire_mid); 59 mid, wire_mid);
@@ -95,8 +96,9 @@ static const __le16 smb2_rsp_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = {
95int 96int
96smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *srvr) 97smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *srvr)
97{ 98{
98 struct smb2_hdr *hdr = (struct smb2_hdr *)buf; 99 struct smb2_pdu *pdu = (struct smb2_pdu *)buf;
99 struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; 100 struct smb2_hdr *hdr = &pdu->hdr;
101 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
100 __u64 mid; 102 __u64 mid;
101 __u32 len = get_rfc1002_length(buf); 103 __u32 len = get_rfc1002_length(buf);
102 __u32 clc_len; /* calculated length */ 104 __u32 clc_len; /* calculated length */
@@ -111,7 +113,7 @@ smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *srvr)
111 * ie Validate the wct via smb2_struct_sizes table above 113 * ie Validate the wct via smb2_struct_sizes table above
112 */ 114 */
113 115
114 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { 116 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
115 struct smb2_transform_hdr *thdr = 117 struct smb2_transform_hdr *thdr =
116 (struct smb2_transform_hdr *)buf; 118 (struct smb2_transform_hdr *)buf;
117 struct cifs_ses *ses = NULL; 119 struct cifs_ses *ses = NULL;
@@ -133,10 +135,10 @@ smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *srvr)
133 } 135 }
134 } 136 }
135 137
136 138 mid = le64_to_cpu(shdr->MessageId);
137 mid = le64_to_cpu(hdr->MessageId);
138 if (length < sizeof(struct smb2_pdu)) { 139 if (length < sizeof(struct smb2_pdu)) {
139 if ((length >= sizeof(struct smb2_hdr)) && (hdr->Status != 0)) { 140 if ((length >= sizeof(struct smb2_hdr))
141 && (shdr->Status != 0)) {
140 pdu->StructureSize2 = 0; 142 pdu->StructureSize2 = 0;
141 /* 143 /*
142 * As with SMB/CIFS, on some error cases servers may 144 * As with SMB/CIFS, on some error cases servers may
@@ -154,29 +156,30 @@ smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *srvr)
154 return 1; 156 return 1;
155 } 157 }
156 158
157 if (check_smb2_hdr(hdr, mid)) 159 if (check_smb2_hdr(shdr, mid))
158 return 1; 160 return 1;
159 161
160 if (hdr->StructureSize != SMB2_HEADER_STRUCTURE_SIZE) { 162 if (shdr->StructureSize != SMB2_HEADER_STRUCTURE_SIZE) {
161 cifs_dbg(VFS, "Illegal structure size %u\n", 163 cifs_dbg(VFS, "Illegal structure size %u\n",
162 le16_to_cpu(hdr->StructureSize)); 164 le16_to_cpu(shdr->StructureSize));
163 return 1; 165 return 1;
164 } 166 }
165 167
166 command = le16_to_cpu(hdr->Command); 168 command = le16_to_cpu(shdr->Command);
167 if (command >= NUMBER_OF_SMB2_COMMANDS) { 169 if (command >= NUMBER_OF_SMB2_COMMANDS) {
168 cifs_dbg(VFS, "Illegal SMB2 command %d\n", command); 170 cifs_dbg(VFS, "Illegal SMB2 command %d\n", command);
169 return 1; 171 return 1;
170 } 172 }
171 173
172 if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) { 174 if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) {
173 if (command != SMB2_OPLOCK_BREAK_HE && (hdr->Status == 0 || 175 if (command != SMB2_OPLOCK_BREAK_HE && (shdr->Status == 0 ||
174 pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2)) { 176 pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2)) {
175 /* error packets have 9 byte structure size */ 177 /* error packets have 9 byte structure size */
176 cifs_dbg(VFS, "Illegal response size %u for command %d\n", 178 cifs_dbg(VFS, "Illegal response size %u for command %d\n",
177 le16_to_cpu(pdu->StructureSize2), command); 179 le16_to_cpu(pdu->StructureSize2), command);
178 return 1; 180 return 1;
179 } else if (command == SMB2_OPLOCK_BREAK_HE && (hdr->Status == 0) 181 } else if (command == SMB2_OPLOCK_BREAK_HE
182 && (shdr->Status == 0)
180 && (le16_to_cpu(pdu->StructureSize2) != 44) 183 && (le16_to_cpu(pdu->StructureSize2) != 44)
181 && (le16_to_cpu(pdu->StructureSize2) != 36)) { 184 && (le16_to_cpu(pdu->StructureSize2) != 36)) {
182 /* special case for SMB2.1 lease break message */ 185 /* special case for SMB2.1 lease break message */
@@ -199,7 +202,7 @@ smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *srvr)
199 clc_len, 4 + len, mid); 202 clc_len, 4 + len, mid);
200 /* create failed on symlink */ 203 /* create failed on symlink */
201 if (command == SMB2_CREATE_HE && 204 if (command == SMB2_CREATE_HE &&
202 hdr->Status == STATUS_STOPPED_ON_SYMLINK) 205 shdr->Status == STATUS_STOPPED_ON_SYMLINK)
203 return 0; 206 return 0;
204 /* Windows 7 server returns 24 bytes more */ 207 /* Windows 7 server returns 24 bytes more */
205 if (clc_len + 20 == len && command == SMB2_OPLOCK_BREAK_HE) 208 if (clc_len + 20 == len && command == SMB2_OPLOCK_BREAK_HE)
@@ -261,11 +264,12 @@ static const bool has_smb2_data_area[NUMBER_OF_SMB2_COMMANDS] = {
261char * 264char *
262smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr) 265smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
263{ 266{
267 struct smb2_sync_hdr *shdr = get_sync_hdr(hdr);
264 *off = 0; 268 *off = 0;
265 *len = 0; 269 *len = 0;
266 270
267 /* error responses do not have data area */ 271 /* error responses do not have data area */
268 if (hdr->Status && hdr->Status != STATUS_MORE_PROCESSING_REQUIRED && 272 if (shdr->Status && shdr->Status != STATUS_MORE_PROCESSING_REQUIRED &&
269 (((struct smb2_err_rsp *)hdr)->StructureSize) == 273 (((struct smb2_err_rsp *)hdr)->StructureSize) ==
270 SMB2_ERROR_STRUCTURE_SIZE2) 274 SMB2_ERROR_STRUCTURE_SIZE2)
271 return NULL; 275 return NULL;
@@ -275,7 +279,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
275 * of the data buffer offset and data buffer length for the particular 279 * of the data buffer offset and data buffer length for the particular
276 * command. 280 * command.
277 */ 281 */
278 switch (hdr->Command) { 282 switch (shdr->Command) {
279 case SMB2_NEGOTIATE: 283 case SMB2_NEGOTIATE:
280 *off = le16_to_cpu( 284 *off = le16_to_cpu(
281 ((struct smb2_negotiate_rsp *)hdr)->SecurityBufferOffset); 285 ((struct smb2_negotiate_rsp *)hdr)->SecurityBufferOffset);
@@ -346,7 +350,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
346 350
347 /* return pointer to beginning of data area, ie offset from SMB start */ 351 /* return pointer to beginning of data area, ie offset from SMB start */
348 if ((*off != 0) && (*len != 0)) 352 if ((*off != 0) && (*len != 0))
349 return (char *)(&hdr->ProtocolId) + *off; 353 return (char *)shdr + *off;
350 else 354 else
351 return NULL; 355 return NULL;
352} 356}
@@ -358,12 +362,13 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
358unsigned int 362unsigned int
359smb2_calc_size(void *buf) 363smb2_calc_size(void *buf)
360{ 364{
361 struct smb2_hdr *hdr = (struct smb2_hdr *)buf; 365 struct smb2_pdu *pdu = (struct smb2_pdu *)buf;
362 struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; 366 struct smb2_hdr *hdr = &pdu->hdr;
367 struct smb2_sync_hdr *shdr = get_sync_hdr(hdr);
363 int offset; /* the offset from the beginning of SMB to data area */ 368 int offset; /* the offset from the beginning of SMB to data area */
364 int data_length; /* the length of the variable length data area */ 369 int data_length; /* the length of the variable length data area */
365 /* Structure Size has already been checked to make sure it is 64 */ 370 /* Structure Size has already been checked to make sure it is 64 */
366 int len = 4 + le16_to_cpu(pdu->hdr.StructureSize); 371 int len = 4 + le16_to_cpu(shdr->StructureSize);
367 372
368 /* 373 /*
369 * StructureSize2, ie length of fixed parameter area has already 374 * StructureSize2, ie length of fixed parameter area has already
@@ -371,7 +376,7 @@ smb2_calc_size(void *buf)
371 */ 376 */
372 len += le16_to_cpu(pdu->StructureSize2); 377 len += le16_to_cpu(pdu->StructureSize2);
373 378
374 if (has_smb2_data_area[le16_to_cpu(hdr->Command)] == false) 379 if (has_smb2_data_area[le16_to_cpu(shdr->Command)] == false)
375 goto calc_size_exit; 380 goto calc_size_exit;
376 381
377 smb2_get_data_area_len(&offset, &data_length, hdr); 382 smb2_get_data_area_len(&offset, &data_length, hdr);
@@ -582,7 +587,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
582 587
583 cifs_dbg(FYI, "Checking for oplock break\n"); 588 cifs_dbg(FYI, "Checking for oplock break\n");
584 589
585 if (rsp->hdr.Command != SMB2_OPLOCK_BREAK) 590 if (rsp->hdr.sync_hdr.Command != SMB2_OPLOCK_BREAK)
586 return false; 591 return false;
587 592
588 if (rsp->StructureSize != 593 if (rsp->StructureSize !=
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 5d456ebb3813..ef8b2a8363b3 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -119,7 +119,9 @@ smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
119static unsigned int 119static unsigned int
120smb2_get_credits(struct mid_q_entry *mid) 120smb2_get_credits(struct mid_q_entry *mid)
121{ 121{
122 return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest); 122 struct smb2_sync_hdr *shdr = get_sync_hdr(mid->resp_buf);
123
124 return le16_to_cpu(shdr->CreditRequest);
123} 125}
124 126
125static int 127static int
@@ -184,10 +186,10 @@ static struct mid_q_entry *
184smb2_find_mid(struct TCP_Server_Info *server, char *buf) 186smb2_find_mid(struct TCP_Server_Info *server, char *buf)
185{ 187{
186 struct mid_q_entry *mid; 188 struct mid_q_entry *mid;
187 struct smb2_hdr *hdr = (struct smb2_hdr *)buf; 189 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
188 __u64 wire_mid = le64_to_cpu(hdr->MessageId); 190 __u64 wire_mid = le64_to_cpu(shdr->MessageId);
189 191
190 if (hdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) { 192 if (shdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM) {
191 cifs_dbg(VFS, "encrypted frame parsing not supported yet"); 193 cifs_dbg(VFS, "encrypted frame parsing not supported yet");
192 return NULL; 194 return NULL;
193 } 195 }
@@ -196,7 +198,7 @@ smb2_find_mid(struct TCP_Server_Info *server, char *buf)
196 list_for_each_entry(mid, &server->pending_mid_q, qhead) { 198 list_for_each_entry(mid, &server->pending_mid_q, qhead) {
197 if ((mid->mid == wire_mid) && 199 if ((mid->mid == wire_mid) &&
198 (mid->mid_state == MID_REQUEST_SUBMITTED) && 200 (mid->mid_state == MID_REQUEST_SUBMITTED) &&
199 (mid->command == hdr->Command)) { 201 (mid->command == shdr->Command)) {
200 spin_unlock(&GlobalMid_Lock); 202 spin_unlock(&GlobalMid_Lock);
201 return mid; 203 return mid;
202 } 204 }
@@ -209,12 +211,12 @@ static void
209smb2_dump_detail(void *buf) 211smb2_dump_detail(void *buf)
210{ 212{
211#ifdef CONFIG_CIFS_DEBUG2 213#ifdef CONFIG_CIFS_DEBUG2
212 struct smb2_hdr *smb = (struct smb2_hdr *)buf; 214 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
213 215
214 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n", 216 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
215 smb->Command, smb->Status, smb->Flags, smb->MessageId, 217 shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId,
216 smb->ProcessId); 218 shdr->ProcessId);
217 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb)); 219 cifs_dbg(VFS, "smb buf %p len %u\n", buf, smb2_calc_size(buf));
218#endif 220#endif
219} 221}
220 222
@@ -1002,14 +1004,14 @@ smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
1002static bool 1004static bool
1003smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length) 1005smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
1004{ 1006{
1005 struct smb2_hdr *hdr = (struct smb2_hdr *)buf; 1007 struct smb2_sync_hdr *shdr = get_sync_hdr(buf);
1006 1008
1007 if (hdr->Status != STATUS_PENDING) 1009 if (shdr->Status != STATUS_PENDING)
1008 return false; 1010 return false;
1009 1011
1010 if (!length) { 1012 if (!length) {
1011 spin_lock(&server->req_lock); 1013 spin_lock(&server->req_lock);
1012 server->credits += le16_to_cpu(hdr->CreditRequest); 1014 server->credits += le16_to_cpu(shdr->CreditRequest);
1013 spin_unlock(&server->req_lock); 1015 spin_unlock(&server->req_lock);
1014 wake_up(&server->request_q); 1016 wake_up(&server->request_q);
1015 } 1017 }
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 87457227812c..0a668c756d56 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -83,6 +83,7 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
83 const struct cifs_tcon *tcon) 83 const struct cifs_tcon *tcon)
84{ 84{
85 struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; 85 struct smb2_pdu *pdu = (struct smb2_pdu *)hdr;
86 struct smb2_sync_hdr *shdr = get_sync_hdr(hdr);
86 char *temp = (char *)hdr; 87 char *temp = (char *)hdr;
87 /* lookup word count ie StructureSize from table */ 88 /* lookup word count ie StructureSize from table */
88 __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_cmd)]; 89 __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_cmd)];
@@ -94,28 +95,28 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
94 memset(temp, 0, 256); 95 memset(temp, 0, 256);
95 96
96 /* Note this is only network field converted to big endian */ 97 /* Note this is only network field converted to big endian */
97 hdr->smb2_buf_length = cpu_to_be32(parmsize + sizeof(struct smb2_hdr) 98 hdr->smb2_buf_length =
98 - 4 /* RFC 1001 length field itself not counted */); 99 cpu_to_be32(parmsize + sizeof(struct smb2_sync_hdr));
99 100
100 hdr->ProtocolId = SMB2_PROTO_NUMBER; 101 shdr->ProtocolId = SMB2_PROTO_NUMBER;
101 hdr->StructureSize = cpu_to_le16(64); 102 shdr->StructureSize = cpu_to_le16(64);
102 hdr->Command = smb2_cmd; 103 shdr->Command = smb2_cmd;
103 if (tcon && tcon->ses && tcon->ses->server) { 104 if (tcon && tcon->ses && tcon->ses->server) {
104 struct TCP_Server_Info *server = tcon->ses->server; 105 struct TCP_Server_Info *server = tcon->ses->server;
105 106
106 spin_lock(&server->req_lock); 107 spin_lock(&server->req_lock);
107 /* Request up to 2 credits but don't go over the limit. */ 108 /* Request up to 2 credits but don't go over the limit. */
108 if (server->credits >= server->max_credits) 109 if (server->credits >= server->max_credits)
109 hdr->CreditRequest = cpu_to_le16(0); 110 shdr->CreditRequest = cpu_to_le16(0);
110 else 111 else
111 hdr->CreditRequest = cpu_to_le16( 112 shdr->CreditRequest = cpu_to_le16(
112 min_t(int, server->max_credits - 113 min_t(int, server->max_credits -
113 server->credits, 2)); 114 server->credits, 2));
114 spin_unlock(&server->req_lock); 115 spin_unlock(&server->req_lock);
115 } else { 116 } else {
116 hdr->CreditRequest = cpu_to_le16(2); 117 shdr->CreditRequest = cpu_to_le16(2);
117 } 118 }
118 hdr->ProcessId = cpu_to_le32((__u16)current->tgid); 119 shdr->ProcessId = cpu_to_le32((__u16)current->tgid);
119 120
120 if (!tcon) 121 if (!tcon)
121 goto out; 122 goto out;
@@ -124,13 +125,13 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
124 /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */ 125 /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */
125 if ((tcon->ses) && (tcon->ses->server) && 126 if ((tcon->ses) && (tcon->ses->server) &&
126 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU)) 127 (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
127 hdr->CreditCharge = cpu_to_le16(1); 128 shdr->CreditCharge = cpu_to_le16(1);
128 /* else CreditCharge MBZ */ 129 /* else CreditCharge MBZ */
129 130
130 hdr->TreeId = tcon->tid; 131 shdr->TreeId = tcon->tid;
131 /* Uid is not converted */ 132 /* Uid is not converted */
132 if (tcon->ses) 133 if (tcon->ses)
133 hdr->SessionId = tcon->ses->Suid; 134 shdr->SessionId = tcon->ses->Suid;
134 135
135 /* 136 /*
136 * If we would set SMB2_FLAGS_DFS_OPERATIONS on open we also would have 137 * If we would set SMB2_FLAGS_DFS_OPERATIONS on open we also would have
@@ -143,10 +144,10 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
143 * but it is safer to net set it for now. 144 * but it is safer to net set it for now.
144 */ 145 */
145/* if (tcon->share_flags & SHI1005_FLAGS_DFS) 146/* if (tcon->share_flags & SHI1005_FLAGS_DFS)
146 hdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */ 147 shdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */
147 148
148 if (tcon->ses && tcon->ses->server && tcon->ses->server->sign) 149 if (tcon->ses && tcon->ses->server && tcon->ses->server->sign)
149 hdr->Flags |= SMB2_FLAGS_SIGNED; 150 shdr->Flags |= SMB2_FLAGS_SIGNED;
150out: 151out:
151 pdu->StructureSize2 = cpu_to_le16(parmsize); 152 pdu->StructureSize2 = cpu_to_le16(parmsize);
152 return; 153 return;
@@ -416,7 +417,7 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
416 if (rc) 417 if (rc)
417 return rc; 418 return rc;
418 419
419 req->hdr.SessionId = 0; 420 req->hdr.sync_hdr.SessionId = 0;
420 421
421 req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id); 422 req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id);
422 423
@@ -627,14 +628,15 @@ SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data)
627 if (rc) 628 if (rc)
628 return rc; 629 return rc;
629 630
630 req->hdr.SessionId = 0; /* First session, not a reauthenticate */ 631 /* First session, not a reauthenticate */
632 req->hdr.sync_hdr.SessionId = 0;
631 633
632 /* if reconnect, we need to send previous sess id, otherwise it is 0 */ 634 /* if reconnect, we need to send previous sess id, otherwise it is 0 */
633 req->PreviousSessionId = sess_data->previous_session; 635 req->PreviousSessionId = sess_data->previous_session;
634 636
635 req->Flags = 0; /* MBZ */ 637 req->Flags = 0; /* MBZ */
636 /* to enable echos and oplocks */ 638 /* to enable echos and oplocks */
637 req->hdr.CreditRequest = cpu_to_le16(3); 639 req->hdr.sync_hdr.CreditRequest = cpu_to_le16(3);
638 640
639 /* only one of SMB2 signing flags may be set in SMB2 request */ 641 /* only one of SMB2 signing flags may be set in SMB2 request */
640 if (server->sign) 642 if (server->sign)
@@ -781,7 +783,7 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
781 goto out_put_spnego_key; 783 goto out_put_spnego_key;
782 784
783 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; 785 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base;
784 ses->Suid = rsp->hdr.SessionId; 786 ses->Suid = rsp->hdr.sync_hdr.SessionId;
785 787
786 ses->session_flags = le16_to_cpu(rsp->SessionFlags); 788 ses->session_flags = le16_to_cpu(rsp->SessionFlags);
787 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) 789 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
@@ -859,7 +861,7 @@ SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data)
859 861
860 /* If true, rc here is expected and not an error */ 862 /* If true, rc here is expected and not an error */
861 if (sess_data->buf0_type != CIFS_NO_BUFFER && 863 if (sess_data->buf0_type != CIFS_NO_BUFFER &&
862 rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED) 864 rsp->hdr.sync_hdr.Status == STATUS_MORE_PROCESSING_REQUIRED)
863 rc = 0; 865 rc = 0;
864 866
865 if (rc) 867 if (rc)
@@ -880,7 +882,7 @@ SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data)
880 cifs_dbg(FYI, "rawntlmssp session setup challenge phase\n"); 882 cifs_dbg(FYI, "rawntlmssp session setup challenge phase\n");
881 883
882 884
883 ses->Suid = rsp->hdr.SessionId; 885 ses->Suid = rsp->hdr.sync_hdr.SessionId;
884 ses->session_flags = le16_to_cpu(rsp->SessionFlags); 886 ses->session_flags = le16_to_cpu(rsp->SessionFlags);
885 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) 887 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
886 cifs_dbg(VFS, "SMB3 encryption not supported yet\n"); 888 cifs_dbg(VFS, "SMB3 encryption not supported yet\n");
@@ -916,7 +918,7 @@ SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data)
916 goto out; 918 goto out;
917 919
918 req = (struct smb2_sess_setup_req *) sess_data->iov[0].iov_base; 920 req = (struct smb2_sess_setup_req *) sess_data->iov[0].iov_base;
919 req->hdr.SessionId = ses->Suid; 921 req->hdr.sync_hdr.SessionId = ses->Suid;
920 922
921 rc = build_ntlmssp_auth_blob(&ntlmssp_blob, &blob_length, ses, 923 rc = build_ntlmssp_auth_blob(&ntlmssp_blob, &blob_length, ses,
922 sess_data->nls_cp); 924 sess_data->nls_cp);
@@ -940,7 +942,7 @@ SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data)
940 942
941 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base; 943 rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base;
942 944
943 ses->Suid = rsp->hdr.SessionId; 945 ses->Suid = rsp->hdr.sync_hdr.SessionId;
944 ses->session_flags = le16_to_cpu(rsp->SessionFlags); 946 ses->session_flags = le16_to_cpu(rsp->SessionFlags);
945 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) 947 if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
946 cifs_dbg(VFS, "SMB3 encryption not supported yet\n"); 948 cifs_dbg(VFS, "SMB3 encryption not supported yet\n");
@@ -1035,9 +1037,9 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses)
1035 return rc; 1037 return rc;
1036 1038
1037 /* since no tcon, smb2_init can not do this, so do here */ 1039 /* since no tcon, smb2_init can not do this, so do here */
1038 req->hdr.SessionId = ses->Suid; 1040 req->hdr.sync_hdr.SessionId = ses->Suid;
1039 if (server->sign) 1041 if (server->sign)
1040 req->hdr.Flags |= SMB2_FLAGS_SIGNED; 1042 req->hdr.sync_hdr.Flags |= SMB2_FLAGS_SIGNED;
1041 1043
1042 rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0); 1044 rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0);
1043 /* 1045 /*
@@ -1112,7 +1114,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
1112 1114
1113 if (tcon == NULL) { 1115 if (tcon == NULL) {
1114 /* since no tcon, smb2_init can not do this, so do here */ 1116 /* since no tcon, smb2_init can not do this, so do here */
1115 req->hdr.SessionId = ses->Suid; 1117 req->hdr.sync_hdr.SessionId = ses->Suid;
1116 /* if (ses->server->sec_mode & SECMODE_SIGN_REQUIRED) 1118 /* if (ses->server->sec_mode & SECMODE_SIGN_REQUIRED)
1117 req->hdr.Flags |= SMB2_FLAGS_SIGNED; */ 1119 req->hdr.Flags |= SMB2_FLAGS_SIGNED; */
1118 } 1120 }
@@ -1142,7 +1144,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
1142 } 1144 }
1143 1145
1144 if (tcon == NULL) { 1146 if (tcon == NULL) {
1145 ses->ipc_tid = rsp->hdr.TreeId; 1147 ses->ipc_tid = rsp->hdr.sync_hdr.TreeId;
1146 goto tcon_exit; 1148 goto tcon_exit;
1147 } 1149 }
1148 1150
@@ -1165,7 +1167,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
1165 tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess); 1167 tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess);
1166 tcon->tidStatus = CifsGood; 1168 tcon->tidStatus = CifsGood;
1167 tcon->need_reconnect = false; 1169 tcon->need_reconnect = false;
1168 tcon->tid = rsp->hdr.TreeId; 1170 tcon->tid = rsp->hdr.sync_hdr.TreeId;
1169 strlcpy(tcon->treeName, tree, sizeof(tcon->treeName)); 1171 strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
1170 1172
1171 if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) && 1173 if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
@@ -1182,7 +1184,7 @@ tcon_exit:
1182 return rc; 1184 return rc;
1183 1185
1184tcon_error_exit: 1186tcon_error_exit:
1185 if (rsp->hdr.Status == STATUS_BAD_NETWORK_NAME) { 1187 if (rsp->hdr.sync_hdr.Status == STATUS_BAD_NETWORK_NAME) {
1186 cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree); 1188 cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree);
1187 if (tcon) 1189 if (tcon)
1188 tcon->bad_network_name = true; 1190 tcon->bad_network_name = true;
@@ -1618,6 +1620,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
1618{ 1620{
1619 struct smb2_ioctl_req *req; 1621 struct smb2_ioctl_req *req;
1620 struct smb2_ioctl_rsp *rsp; 1622 struct smb2_ioctl_rsp *rsp;
1623 struct smb2_sync_hdr *shdr;
1621 struct TCP_Server_Info *server; 1624 struct TCP_Server_Info *server;
1622 struct cifs_ses *ses; 1625 struct cifs_ses *ses;
1623 struct kvec iov[2]; 1626 struct kvec iov[2];
@@ -1742,9 +1745,8 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
1742 goto ioctl_exit; 1745 goto ioctl_exit;
1743 } 1746 }
1744 1747
1745 memcpy(*out_data, 1748 shdr = get_sync_hdr(rsp);
1746 (char *)&rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset), 1749 memcpy(*out_data, (char *)shdr + le32_to_cpu(rsp->OutputOffset), *plen);
1747 *plen);
1748ioctl_exit: 1750ioctl_exit:
1749 free_rsp_buf(resp_buftype, rsp); 1751 free_rsp_buf(resp_buftype, rsp);
1750 return rc; 1752 return rc;
@@ -1963,11 +1965,11 @@ static void
1963smb2_echo_callback(struct mid_q_entry *mid) 1965smb2_echo_callback(struct mid_q_entry *mid)
1964{ 1966{
1965 struct TCP_Server_Info *server = mid->callback_data; 1967 struct TCP_Server_Info *server = mid->callback_data;
1966 struct smb2_echo_rsp *smb2 = (struct smb2_echo_rsp *)mid->resp_buf; 1968 struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf;
1967 unsigned int credits_received = 1; 1969 unsigned int credits_received = 1;
1968 1970
1969 if (mid->mid_state == MID_RESPONSE_RECEIVED) 1971 if (mid->mid_state == MID_RESPONSE_RECEIVED)
1970 credits_received = le16_to_cpu(smb2->hdr.CreditRequest); 1972 credits_received = le16_to_cpu(rsp->hdr.sync_hdr.CreditRequest);
1971 1973
1972 mutex_lock(&server->srv_mutex); 1974 mutex_lock(&server->srv_mutex);
1973 DeleteMidQEntry(mid); 1975 DeleteMidQEntry(mid);
@@ -2045,7 +2047,7 @@ SMB2_echo(struct TCP_Server_Info *server)
2045 if (rc) 2047 if (rc)
2046 return rc; 2048 return rc;
2047 2049
2048 req->hdr.CreditRequest = cpu_to_le16(1); 2050 req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1);
2049 2051
2050 iov.iov_base = (char *)req; 2052 iov.iov_base = (char *)req;
2051 /* 4 for rfc1002 length field */ 2053 /* 4 for rfc1002 length field */
@@ -2108,6 +2110,7 @@ smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms,
2108{ 2110{
2109 int rc = -EACCES; 2111 int rc = -EACCES;
2110 struct smb2_read_req *req = NULL; 2112 struct smb2_read_req *req = NULL;
2113 struct smb2_sync_hdr *shdr;
2111 2114
2112 rc = small_smb2_init(SMB2_READ, io_parms->tcon, (void **) &req); 2115 rc = small_smb2_init(SMB2_READ, io_parms->tcon, (void **) &req);
2113 if (rc) 2116 if (rc)
@@ -2115,7 +2118,8 @@ smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms,
2115 if (io_parms->tcon->ses->server == NULL) 2118 if (io_parms->tcon->ses->server == NULL)
2116 return -ECONNABORTED; 2119 return -ECONNABORTED;
2117 2120
2118 req->hdr.ProcessId = cpu_to_le32(io_parms->pid); 2121 shdr = get_sync_hdr(req);
2122 shdr->ProcessId = cpu_to_le32(io_parms->pid);
2119 2123
2120 req->PersistentFileId = io_parms->persistent_fid; 2124 req->PersistentFileId = io_parms->persistent_fid;
2121 req->VolatileFileId = io_parms->volatile_fid; 2125 req->VolatileFileId = io_parms->volatile_fid;
@@ -2129,18 +2133,18 @@ smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms,
2129 if (request_type & CHAINED_REQUEST) { 2133 if (request_type & CHAINED_REQUEST) {
2130 if (!(request_type & END_OF_CHAIN)) { 2134 if (!(request_type & END_OF_CHAIN)) {
2131 /* 4 for rfc1002 length field */ 2135 /* 4 for rfc1002 length field */
2132 req->hdr.NextCommand = 2136 shdr->NextCommand =
2133 cpu_to_le32(get_rfc1002_length(req) + 4); 2137 cpu_to_le32(get_rfc1002_length(req) + 4);
2134 } else /* END_OF_CHAIN */ 2138 } else /* END_OF_CHAIN */
2135 req->hdr.NextCommand = 0; 2139 shdr->NextCommand = 0;
2136 if (request_type & RELATED_REQUEST) { 2140 if (request_type & RELATED_REQUEST) {
2137 req->hdr.Flags |= SMB2_FLAGS_RELATED_OPERATIONS; 2141 shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
2138 /* 2142 /*
2139 * Related requests use info from previous read request 2143 * Related requests use info from previous read request
2140 * in chain. 2144 * in chain.
2141 */ 2145 */
2142 req->hdr.SessionId = 0xFFFFFFFF; 2146 shdr->SessionId = 0xFFFFFFFF;
2143 req->hdr.TreeId = 0xFFFFFFFF; 2147 shdr->TreeId = 0xFFFFFFFF;
2144 req->PersistentFileId = 0xFFFFFFFF; 2148 req->PersistentFileId = 0xFFFFFFFF;
2145 req->VolatileFileId = 0xFFFFFFFF; 2149 req->VolatileFileId = 0xFFFFFFFF;
2146 } 2150 }
@@ -2162,7 +2166,7 @@ smb2_readv_callback(struct mid_q_entry *mid)
2162 struct cifs_readdata *rdata = mid->callback_data; 2166 struct cifs_readdata *rdata = mid->callback_data;
2163 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); 2167 struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
2164 struct TCP_Server_Info *server = tcon->ses->server; 2168 struct TCP_Server_Info *server = tcon->ses->server;
2165 struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov.iov_base; 2169 struct smb2_sync_hdr *shdr = get_sync_hdr(rdata->iov.iov_base);
2166 unsigned int credits_received = 1; 2170 unsigned int credits_received = 1;
2167 struct smb_rqst rqst = { .rq_iov = &rdata->iov, 2171 struct smb_rqst rqst = { .rq_iov = &rdata->iov,
2168 .rq_nvec = 1, 2172 .rq_nvec = 1,
@@ -2177,7 +2181,7 @@ smb2_readv_callback(struct mid_q_entry *mid)
2177 2181
2178 switch (mid->mid_state) { 2182 switch (mid->mid_state) {
2179 case MID_RESPONSE_RECEIVED: 2183 case MID_RESPONSE_RECEIVED:
2180 credits_received = le16_to_cpu(buf->CreditRequest); 2184 credits_received = le16_to_cpu(shdr->CreditRequest);
2181 /* result already set, check signature */ 2185 /* result already set, check signature */
2182 if (server->sign) { 2186 if (server->sign) {
2183 int rc; 2187 int rc;
@@ -2221,7 +2225,8 @@ int
2221smb2_async_readv(struct cifs_readdata *rdata) 2225smb2_async_readv(struct cifs_readdata *rdata)
2222{ 2226{
2223 int rc, flags = 0; 2227 int rc, flags = 0;
2224 struct smb2_hdr *buf; 2228 char *buf;
2229 struct smb2_sync_hdr *shdr;
2225 struct cifs_io_parms io_parms; 2230 struct cifs_io_parms io_parms;
2226 struct smb_rqst rqst = { .rq_iov = &rdata->iov, 2231 struct smb_rqst rqst = { .rq_iov = &rdata->iov,
2227 .rq_nvec = 1 }; 2232 .rq_nvec = 1 };
@@ -2252,17 +2257,18 @@ smb2_async_readv(struct cifs_readdata *rdata)
2252 return rc; 2257 return rc;
2253 } 2258 }
2254 2259
2255 buf = (struct smb2_hdr *)rdata->iov.iov_base; 2260 buf = rdata->iov.iov_base;
2261 shdr = get_sync_hdr(buf);
2256 /* 4 for rfc1002 length field */ 2262 /* 4 for rfc1002 length field */
2257 rdata->iov.iov_len = get_rfc1002_length(rdata->iov.iov_base) + 4; 2263 rdata->iov.iov_len = get_rfc1002_length(rdata->iov.iov_base) + 4;
2258 2264
2259 if (rdata->credits) { 2265 if (rdata->credits) {
2260 buf->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes, 2266 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes,
2261 SMB2_MAX_BUFFER_SIZE)); 2267 SMB2_MAX_BUFFER_SIZE));
2262 buf->CreditRequest = buf->CreditCharge; 2268 shdr->CreditRequest = shdr->CreditCharge;
2263 spin_lock(&server->req_lock); 2269 spin_lock(&server->req_lock);
2264 server->credits += rdata->credits - 2270 server->credits += rdata->credits -
2265 le16_to_cpu(buf->CreditCharge); 2271 le16_to_cpu(shdr->CreditCharge);
2266 spin_unlock(&server->req_lock); 2272 spin_unlock(&server->req_lock);
2267 wake_up(&server->request_q); 2273 wake_up(&server->request_q);
2268 flags = CIFS_HAS_CREDITS; 2274 flags = CIFS_HAS_CREDITS;
@@ -2287,6 +2293,7 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
2287{ 2293{
2288 int resp_buftype, rc = -EACCES; 2294 int resp_buftype, rc = -EACCES;
2289 struct smb2_read_rsp *rsp = NULL; 2295 struct smb2_read_rsp *rsp = NULL;
2296 struct smb2_sync_hdr *shdr;
2290 struct kvec iov[1]; 2297 struct kvec iov[1];
2291 2298
2292 *nbytes = 0; 2299 *nbytes = 0;
@@ -2298,8 +2305,9 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
2298 &resp_buftype, CIFS_LOG_ERROR); 2305 &resp_buftype, CIFS_LOG_ERROR);
2299 2306
2300 rsp = (struct smb2_read_rsp *)iov[0].iov_base; 2307 rsp = (struct smb2_read_rsp *)iov[0].iov_base;
2308 shdr = get_sync_hdr(rsp);
2301 2309
2302 if (rsp->hdr.Status == STATUS_END_OF_FILE) { 2310 if (shdr->Status == STATUS_END_OF_FILE) {
2303 free_rsp_buf(resp_buftype, iov[0].iov_base); 2311 free_rsp_buf(resp_buftype, iov[0].iov_base);
2304 return 0; 2312 return 0;
2305 } 2313 }
@@ -2319,8 +2327,7 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
2319 } 2327 }
2320 2328
2321 if (*buf) { 2329 if (*buf) {
2322 memcpy(*buf, (char *)&rsp->hdr.ProtocolId + rsp->DataOffset, 2330 memcpy(*buf, (char *)shdr + rsp->DataOffset, *nbytes);
2323 *nbytes);
2324 free_rsp_buf(resp_buftype, iov[0].iov_base); 2331 free_rsp_buf(resp_buftype, iov[0].iov_base);
2325 } else if (resp_buftype != CIFS_NO_BUFFER) { 2332 } else if (resp_buftype != CIFS_NO_BUFFER) {
2326 *buf = iov[0].iov_base; 2333 *buf = iov[0].iov_base;
@@ -2348,7 +2355,7 @@ smb2_writev_callback(struct mid_q_entry *mid)
2348 2355
2349 switch (mid->mid_state) { 2356 switch (mid->mid_state) {
2350 case MID_RESPONSE_RECEIVED: 2357 case MID_RESPONSE_RECEIVED:
2351 credits_received = le16_to_cpu(rsp->hdr.CreditRequest); 2358 credits_received = le16_to_cpu(rsp->hdr.sync_hdr.CreditRequest);
2352 wdata->result = smb2_check_receive(mid, tcon->ses->server, 0); 2359 wdata->result = smb2_check_receive(mid, tcon->ses->server, 0);
2353 if (wdata->result != 0) 2360 if (wdata->result != 0)
2354 break; 2361 break;
@@ -2394,6 +2401,7 @@ smb2_async_writev(struct cifs_writedata *wdata,
2394{ 2401{
2395 int rc = -EACCES, flags = 0; 2402 int rc = -EACCES, flags = 0;
2396 struct smb2_write_req *req = NULL; 2403 struct smb2_write_req *req = NULL;
2404 struct smb2_sync_hdr *shdr;
2397 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink); 2405 struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
2398 struct TCP_Server_Info *server = tcon->ses->server; 2406 struct TCP_Server_Info *server = tcon->ses->server;
2399 struct kvec iov; 2407 struct kvec iov;
@@ -2412,7 +2420,8 @@ smb2_async_writev(struct cifs_writedata *wdata,
2412 goto async_writev_out; 2420 goto async_writev_out;
2413 } 2421 }
2414 2422
2415 req->hdr.ProcessId = cpu_to_le32(wdata->cfile->pid); 2423 shdr = get_sync_hdr(req);
2424 shdr->ProcessId = cpu_to_le32(wdata->cfile->pid);
2416 2425
2417 req->PersistentFileId = wdata->cfile->fid.persistent_fid; 2426 req->PersistentFileId = wdata->cfile->fid.persistent_fid;
2418 req->VolatileFileId = wdata->cfile->fid.volatile_fid; 2427 req->VolatileFileId = wdata->cfile->fid.volatile_fid;
@@ -2444,12 +2453,12 @@ smb2_async_writev(struct cifs_writedata *wdata,
2444 inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */); 2453 inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */);
2445 2454
2446 if (wdata->credits) { 2455 if (wdata->credits) {
2447 req->hdr.CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes, 2456 shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes,
2448 SMB2_MAX_BUFFER_SIZE)); 2457 SMB2_MAX_BUFFER_SIZE));
2449 req->hdr.CreditRequest = req->hdr.CreditCharge; 2458 shdr->CreditRequest = shdr->CreditCharge;
2450 spin_lock(&server->req_lock); 2459 spin_lock(&server->req_lock);
2451 server->credits += wdata->credits - 2460 server->credits += wdata->credits -
2452 le16_to_cpu(req->hdr.CreditCharge); 2461 le16_to_cpu(shdr->CreditCharge);
2453 spin_unlock(&server->req_lock); 2462 spin_unlock(&server->req_lock);
2454 wake_up(&server->request_q); 2463 wake_up(&server->request_q);
2455 flags = CIFS_HAS_CREDITS; 2464 flags = CIFS_HAS_CREDITS;
@@ -2495,7 +2504,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
2495 if (io_parms->tcon->ses->server == NULL) 2504 if (io_parms->tcon->ses->server == NULL)
2496 return -ECONNABORTED; 2505 return -ECONNABORTED;
2497 2506
2498 req->hdr.ProcessId = cpu_to_le32(io_parms->pid); 2507 req->hdr.sync_hdr.ProcessId = cpu_to_le32(io_parms->pid);
2499 2508
2500 req->PersistentFileId = io_parms->persistent_fid; 2509 req->PersistentFileId = io_parms->persistent_fid;
2501 req->VolatileFileId = io_parms->volatile_fid; 2510 req->VolatileFileId = io_parms->volatile_fid;
@@ -2649,7 +2658,8 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
2649 rsp = (struct smb2_query_directory_rsp *)iov[0].iov_base; 2658 rsp = (struct smb2_query_directory_rsp *)iov[0].iov_base;
2650 2659
2651 if (rc) { 2660 if (rc) {
2652 if (rc == -ENODATA && rsp->hdr.Status == STATUS_NO_MORE_FILES) { 2661 if (rc == -ENODATA &&
2662 rsp->hdr.sync_hdr.Status == STATUS_NO_MORE_FILES) {
2653 srch_inf->endOfSearch = true; 2663 srch_inf->endOfSearch = true;
2654 rc = 0; 2664 rc = 0;
2655 } 2665 }
@@ -2729,7 +2739,7 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
2729 return rc; 2739 return rc;
2730 } 2740 }
2731 2741
2732 req->hdr.ProcessId = cpu_to_le32(pid); 2742 req->hdr.sync_hdr.ProcessId = cpu_to_le32(pid);
2733 2743
2734 req->InfoType = SMB2_O_INFO_FILE; 2744 req->InfoType = SMB2_O_INFO_FILE;
2735 req->FileInfoClass = info_class; 2745 req->FileInfoClass = info_class;
@@ -2895,7 +2905,7 @@ SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
2895 req->VolatileFid = volatile_fid; 2905 req->VolatileFid = volatile_fid;
2896 req->PersistentFid = persistent_fid; 2906 req->PersistentFid = persistent_fid;
2897 req->OplockLevel = oplock_level; 2907 req->OplockLevel = oplock_level;
2898 req->hdr.CreditRequest = cpu_to_le16(1); 2908 req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1);
2899 2909
2900 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP); 2910 rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP);
2901 /* SMB2 buffer freed by function above */ 2911 /* SMB2 buffer freed by function above */
@@ -3069,7 +3079,7 @@ smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
3069 if (rc) 3079 if (rc)
3070 return rc; 3080 return rc;
3071 3081
3072 req->hdr.ProcessId = cpu_to_le32(pid); 3082 req->hdr.sync_hdr.ProcessId = cpu_to_le32(pid);
3073 req->LockCount = cpu_to_le16(num_lock); 3083 req->LockCount = cpu_to_le16(num_lock);
3074 3084
3075 req->PersistentFileId = persist_fid; 3085 req->PersistentFileId = persist_fid;
@@ -3124,7 +3134,7 @@ SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
3124 if (rc) 3134 if (rc)
3125 return rc; 3135 return rc;
3126 3136
3127 req->hdr.CreditRequest = cpu_to_le16(1); 3137 req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1);
3128 req->StructureSize = cpu_to_le16(36); 3138 req->StructureSize = cpu_to_le16(36);
3129 inc_rfc1001_len(req, 12); 3139 inc_rfc1001_len(req, 12);
3130 3140
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
index dc0d141f33e2..8dd24b73d974 100644
--- a/fs/cifs/smb2pdu.h
+++ b/fs/cifs/smb2pdu.h
@@ -101,10 +101,7 @@
101 101
102#define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64) 102#define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
103 103
104struct smb2_hdr { 104struct smb2_sync_hdr {
105 __be32 smb2_buf_length; /* big endian on wire */
106 /* length is only two or three bytes - with
107 one or two byte type preceding it that MBZ */
108 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */ 105 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
109 __le16 StructureSize; /* 64 */ 106 __le16 StructureSize; /* 64 */
110 __le16 CreditCharge; /* MBZ */ 107 __le16 CreditCharge; /* MBZ */
@@ -120,6 +117,13 @@ struct smb2_hdr {
120 __u8 Signature[16]; 117 __u8 Signature[16];
121} __packed; 118} __packed;
122 119
120struct smb2_hdr {
121 __be32 smb2_buf_length; /* big endian on wire */
122 /* length is only two or three bytes - with */
123 /* one or two byte type preceding it that MBZ */
124 struct smb2_sync_hdr sync_hdr;
125} __packed;
126
123struct smb2_pdu { 127struct smb2_pdu {
124 struct smb2_hdr hdr; 128 struct smb2_hdr hdr;
125 __le16 StructureSize2; /* size of wct area (varies, request specific) */ 129 __le16 StructureSize2; /* size of wct area (varies, request specific) */
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
index bc9a7b634643..52ff937fd1ed 100644
--- a/fs/cifs/smb2transport.c
+++ b/fs/cifs/smb2transport.c
@@ -115,13 +115,13 @@ smb3_crypto_shash_allocate(struct TCP_Server_Info *server)
115} 115}
116 116
117static struct cifs_ses * 117static struct cifs_ses *
118smb2_find_smb_ses(struct smb2_hdr *smb2hdr, struct TCP_Server_Info *server) 118smb2_find_smb_ses(struct smb2_sync_hdr *shdr, struct TCP_Server_Info *server)
119{ 119{
120 struct cifs_ses *ses; 120 struct cifs_ses *ses;
121 121
122 spin_lock(&cifs_tcp_ses_lock); 122 spin_lock(&cifs_tcp_ses_lock);
123 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { 123 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
124 if (ses->Suid != smb2hdr->SessionId) 124 if (ses->Suid != shdr->SessionId)
125 continue; 125 continue;
126 spin_unlock(&cifs_tcp_ses_lock); 126 spin_unlock(&cifs_tcp_ses_lock);
127 return ses; 127 return ses;
@@ -131,7 +131,6 @@ smb2_find_smb_ses(struct smb2_hdr *smb2hdr, struct TCP_Server_Info *server)
131 return NULL; 131 return NULL;
132} 132}
133 133
134
135int 134int
136smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) 135smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
137{ 136{
@@ -139,17 +138,17 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
139 unsigned char smb2_signature[SMB2_HMACSHA256_SIZE]; 138 unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
140 unsigned char *sigptr = smb2_signature; 139 unsigned char *sigptr = smb2_signature;
141 struct kvec *iov = rqst->rq_iov; 140 struct kvec *iov = rqst->rq_iov;
142 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base; 141 struct smb2_sync_hdr *shdr = get_sync_hdr(iov[0].iov_base);
143 struct cifs_ses *ses; 142 struct cifs_ses *ses;
144 143
145 ses = smb2_find_smb_ses(smb2_pdu, server); 144 ses = smb2_find_smb_ses(shdr, server);
146 if (!ses) { 145 if (!ses) {
147 cifs_dbg(VFS, "%s: Could not find session\n", __func__); 146 cifs_dbg(VFS, "%s: Could not find session\n", __func__);
148 return 0; 147 return 0;
149 } 148 }
150 149
151 memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE); 150 memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE);
152 memset(smb2_pdu->Signature, 0x0, SMB2_SIGNATURE_SIZE); 151 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
153 152
154 rc = smb2_crypto_shash_allocate(server); 153 rc = smb2_crypto_shash_allocate(server);
155 if (rc) { 154 if (rc) {
@@ -174,7 +173,7 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
174 &server->secmech.sdeschmacsha256->shash); 173 &server->secmech.sdeschmacsha256->shash);
175 174
176 if (!rc) 175 if (!rc)
177 memcpy(smb2_pdu->Signature, sigptr, SMB2_SIGNATURE_SIZE); 176 memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE);
178 177
179 return rc; 178 return rc;
180} 179}
@@ -356,17 +355,17 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
356 unsigned char smb3_signature[SMB2_CMACAES_SIZE]; 355 unsigned char smb3_signature[SMB2_CMACAES_SIZE];
357 unsigned char *sigptr = smb3_signature; 356 unsigned char *sigptr = smb3_signature;
358 struct kvec *iov = rqst->rq_iov; 357 struct kvec *iov = rqst->rq_iov;
359 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base; 358 struct smb2_sync_hdr *shdr = get_sync_hdr(iov[0].iov_base);
360 struct cifs_ses *ses; 359 struct cifs_ses *ses;
361 360
362 ses = smb2_find_smb_ses(smb2_pdu, server); 361 ses = smb2_find_smb_ses(shdr, server);
363 if (!ses) { 362 if (!ses) {
364 cifs_dbg(VFS, "%s: Could not find session\n", __func__); 363 cifs_dbg(VFS, "%s: Could not find session\n", __func__);
365 return 0; 364 return 0;
366 } 365 }
367 366
368 memset(smb3_signature, 0x0, SMB2_CMACAES_SIZE); 367 memset(smb3_signature, 0x0, SMB2_CMACAES_SIZE);
369 memset(smb2_pdu->Signature, 0x0, SMB2_SIGNATURE_SIZE); 368 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
370 369
371 rc = crypto_shash_setkey(server->secmech.cmacaes, 370 rc = crypto_shash_setkey(server->secmech.cmacaes,
372 ses->smb3signingkey, SMB2_CMACAES_SIZE); 371 ses->smb3signingkey, SMB2_CMACAES_SIZE);
@@ -391,7 +390,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
391 &server->secmech.sdesccmacaes->shash); 390 &server->secmech.sdesccmacaes->shash);
392 391
393 if (!rc) 392 if (!rc)
394 memcpy(smb2_pdu->Signature, sigptr, SMB2_SIGNATURE_SIZE); 393 memcpy(shdr->Signature, sigptr, SMB2_SIGNATURE_SIZE);
395 394
396 return rc; 395 return rc;
397} 396}
@@ -401,14 +400,14 @@ static int
401smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) 400smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
402{ 401{
403 int rc = 0; 402 int rc = 0;
404 struct smb2_hdr *smb2_pdu = rqst->rq_iov[0].iov_base; 403 struct smb2_sync_hdr *shdr = get_sync_hdr(rqst->rq_iov[0].iov_base);
405 404
406 if (!(smb2_pdu->Flags & SMB2_FLAGS_SIGNED) || 405 if (!(shdr->Flags & SMB2_FLAGS_SIGNED) ||
407 server->tcpStatus == CifsNeedNegotiate) 406 server->tcpStatus == CifsNeedNegotiate)
408 return rc; 407 return rc;
409 408
410 if (!server->session_estab) { 409 if (!server->session_estab) {
411 strncpy(smb2_pdu->Signature, "BSRSPYL", 8); 410 strncpy(shdr->Signature, "BSRSPYL", 8);
412 return rc; 411 return rc;
413 } 412 }
414 413
@@ -422,11 +421,11 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
422{ 421{
423 unsigned int rc; 422 unsigned int rc;
424 char server_response_sig[16]; 423 char server_response_sig[16];
425 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; 424 struct smb2_sync_hdr *shdr = get_sync_hdr(rqst->rq_iov[0].iov_base);
426 425
427 if ((smb2_pdu->Command == SMB2_NEGOTIATE) || 426 if ((shdr->Command == SMB2_NEGOTIATE) ||
428 (smb2_pdu->Command == SMB2_SESSION_SETUP) || 427 (shdr->Command == SMB2_SESSION_SETUP) ||
429 (smb2_pdu->Command == SMB2_OPLOCK_BREAK) || 428 (shdr->Command == SMB2_OPLOCK_BREAK) ||
430 (!server->session_estab)) 429 (!server->session_estab))
431 return 0; 430 return 0;
432 431
@@ -436,17 +435,17 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
436 */ 435 */
437 436
438 /* Do not need to verify session setups with signature "BSRSPYL " */ 437 /* Do not need to verify session setups with signature "BSRSPYL " */
439 if (memcmp(smb2_pdu->Signature, "BSRSPYL ", 8) == 0) 438 if (memcmp(shdr->Signature, "BSRSPYL ", 8) == 0)
440 cifs_dbg(FYI, "dummy signature received for smb command 0x%x\n", 439 cifs_dbg(FYI, "dummy signature received for smb command 0x%x\n",
441 smb2_pdu->Command); 440 shdr->Command);
442 441
443 /* 442 /*
444 * Save off the origiginal signature so we can modify the smb and check 443 * Save off the origiginal signature so we can modify the smb and check
445 * our calculated signature against what the server sent. 444 * our calculated signature against what the server sent.
446 */ 445 */
447 memcpy(server_response_sig, smb2_pdu->Signature, SMB2_SIGNATURE_SIZE); 446 memcpy(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE);
448 447
449 memset(smb2_pdu->Signature, 0, SMB2_SIGNATURE_SIZE); 448 memset(shdr->Signature, 0, SMB2_SIGNATURE_SIZE);
450 449
451 mutex_lock(&server->srv_mutex); 450 mutex_lock(&server->srv_mutex);
452 rc = server->ops->calc_signature(rqst, server); 451 rc = server->ops->calc_signature(rqst, server);
@@ -455,8 +454,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
455 if (rc) 454 if (rc)
456 return rc; 455 return rc;
457 456
458 if (memcmp(server_response_sig, smb2_pdu->Signature, 457 if (memcmp(server_response_sig, shdr->Signature, SMB2_SIGNATURE_SIZE))
459 SMB2_SIGNATURE_SIZE))
460 return -EACCES; 458 return -EACCES;
461 else 459 else
462 return 0; 460 return 0;
@@ -467,18 +465,19 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
467 * and when srv_mutex is held. 465 * and when srv_mutex is held.
468 */ 466 */
469static inline void 467static inline void
470smb2_seq_num_into_buf(struct TCP_Server_Info *server, struct smb2_hdr *hdr) 468smb2_seq_num_into_buf(struct TCP_Server_Info *server,
469 struct smb2_sync_hdr *shdr)
471{ 470{
472 unsigned int i, num = le16_to_cpu(hdr->CreditCharge); 471 unsigned int i, num = le16_to_cpu(shdr->CreditCharge);
473 472
474 hdr->MessageId = get_next_mid64(server); 473 shdr->MessageId = get_next_mid64(server);
475 /* skip message numbers according to CreditCharge field */ 474 /* skip message numbers according to CreditCharge field */
476 for (i = 1; i < num; i++) 475 for (i = 1; i < num; i++)
477 get_next_mid(server); 476 get_next_mid(server);
478} 477}
479 478
480static struct mid_q_entry * 479static struct mid_q_entry *
481smb2_mid_entry_alloc(const struct smb2_hdr *smb_buffer, 480smb2_mid_entry_alloc(const struct smb2_sync_hdr *shdr,
482 struct TCP_Server_Info *server) 481 struct TCP_Server_Info *server)
483{ 482{
484 struct mid_q_entry *temp; 483 struct mid_q_entry *temp;
@@ -493,9 +492,9 @@ smb2_mid_entry_alloc(const struct smb2_hdr *smb_buffer,
493 return temp; 492 return temp;
494 else { 493 else {
495 memset(temp, 0, sizeof(struct mid_q_entry)); 494 memset(temp, 0, sizeof(struct mid_q_entry));
496 temp->mid = le64_to_cpu(smb_buffer->MessageId); 495 temp->mid = le64_to_cpu(shdr->MessageId);
497 temp->pid = current->pid; 496 temp->pid = current->pid;
498 temp->command = smb_buffer->Command; /* Always LE */ 497 temp->command = shdr->Command; /* Always LE */
499 temp->when_alloc = jiffies; 498 temp->when_alloc = jiffies;
500 temp->server = server; 499 temp->server = server;
501 500
@@ -513,7 +512,7 @@ smb2_mid_entry_alloc(const struct smb2_hdr *smb_buffer,
513} 512}
514 513
515static int 514static int
516smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf, 515smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_sync_hdr *shdr,
517 struct mid_q_entry **mid) 516 struct mid_q_entry **mid)
518{ 517{
519 if (ses->server->tcpStatus == CifsExiting) 518 if (ses->server->tcpStatus == CifsExiting)
@@ -525,19 +524,19 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf,
525 } 524 }
526 525
527 if (ses->status == CifsNew) { 526 if (ses->status == CifsNew) {
528 if ((buf->Command != SMB2_SESSION_SETUP) && 527 if ((shdr->Command != SMB2_SESSION_SETUP) &&
529 (buf->Command != SMB2_NEGOTIATE)) 528 (shdr->Command != SMB2_NEGOTIATE))
530 return -EAGAIN; 529 return -EAGAIN;
531 /* else ok - we are setting up session */ 530 /* else ok - we are setting up session */
532 } 531 }
533 532
534 if (ses->status == CifsExiting) { 533 if (ses->status == CifsExiting) {
535 if (buf->Command != SMB2_LOGOFF) 534 if (shdr->Command != SMB2_LOGOFF)
536 return -EAGAIN; 535 return -EAGAIN;
537 /* else ok - we are shutting down the session */ 536 /* else ok - we are shutting down the session */
538 } 537 }
539 538
540 *mid = smb2_mid_entry_alloc(buf, ses->server); 539 *mid = smb2_mid_entry_alloc(shdr, ses->server);
541 if (*mid == NULL) 540 if (*mid == NULL)
542 return -ENOMEM; 541 return -ENOMEM;
543 spin_lock(&GlobalMid_Lock); 542 spin_lock(&GlobalMid_Lock);
@@ -576,12 +575,12 @@ struct mid_q_entry *
576smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) 575smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)
577{ 576{
578 int rc; 577 int rc;
579 struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; 578 struct smb2_sync_hdr *shdr = get_sync_hdr(rqst->rq_iov[0].iov_base);
580 struct mid_q_entry *mid; 579 struct mid_q_entry *mid;
581 580
582 smb2_seq_num_into_buf(ses->server, hdr); 581 smb2_seq_num_into_buf(ses->server, shdr);
583 582
584 rc = smb2_get_mid_entry(ses, hdr, &mid); 583 rc = smb2_get_mid_entry(ses, shdr, &mid);
585 if (rc) 584 if (rc)
586 return ERR_PTR(rc); 585 return ERR_PTR(rc);
587 rc = smb2_sign_rqst(rqst, ses->server); 586 rc = smb2_sign_rqst(rqst, ses->server);
@@ -596,12 +595,12 @@ struct mid_q_entry *
596smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) 595smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)
597{ 596{
598 int rc; 597 int rc;
599 struct smb2_hdr *hdr = (struct smb2_hdr *)rqst->rq_iov[0].iov_base; 598 struct smb2_sync_hdr *shdr = get_sync_hdr(rqst->rq_iov[0].iov_base);
600 struct mid_q_entry *mid; 599 struct mid_q_entry *mid;
601 600
602 smb2_seq_num_into_buf(server, hdr); 601 smb2_seq_num_into_buf(server, shdr);
603 602
604 mid = smb2_mid_entry_alloc(hdr, server); 603 mid = smb2_mid_entry_alloc(shdr, server);
605 if (mid == NULL) 604 if (mid == NULL)
606 return ERR_PTR(-ENOMEM); 605 return ERR_PTR(-ENOMEM);
607 606