aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/smb2transport.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2012-09-18 19:20:34 -0400
committerSteve French <smfrench@gmail.com>2012-09-24 22:46:30 -0400
commit0b688cfc8b3472f5bad104abe0675a060e32ad7b (patch)
treed8bde5c8470c9abe92aac5d467883b5c44043089 /fs/cifs/smb2transport.c
parentbf5ea0e2f29b00d4fe5f203d8e59120f797ce451 (diff)
cifs: change smb2 signing routines to use smb_rqst structs
Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <smfrench@gmail.com>
Diffstat (limited to 'fs/cifs/smb2transport.c')
-rw-r--r--fs/cifs/smb2transport.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
index 66479f252ae5..1850d9ec3c90 100644
--- a/fs/cifs/smb2transport.c
+++ b/fs/cifs/smb2transport.c
@@ -39,12 +39,13 @@
39#include "smb2glob.h" 39#include "smb2glob.h"
40 40
41static int 41static int
42smb2_calc_signature2(const struct kvec *iov, int n_vec, 42smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
43 struct TCP_Server_Info *server)
44{ 43{
45 int i, rc; 44 int i, rc;
46 unsigned char smb2_signature[SMB2_HMACSHA256_SIZE]; 45 unsigned char smb2_signature[SMB2_HMACSHA256_SIZE];
47 unsigned char *sigptr = smb2_signature; 46 unsigned char *sigptr = smb2_signature;
47 struct kvec *iov = rqst->rq_iov;
48 int n_vec = rqst->rq_nvec;
48 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base; 49 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base;
49 50
50 memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE); 51 memset(smb2_signature, 0x0, SMB2_HMACSHA256_SIZE);
@@ -106,10 +107,10 @@ smb2_calc_signature2(const struct kvec *iov, int n_vec,
106 107
107/* must be called with server->srv_mutex held */ 108/* must be called with server->srv_mutex held */
108static int 109static int
109smb2_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server) 110smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
110{ 111{
111 int rc = 0; 112 int rc = 0;
112 struct smb2_hdr *smb2_pdu = iov[0].iov_base; 113 struct smb2_hdr *smb2_pdu = rqst->rq_iov[0].iov_base;
113 114
114 if (!(smb2_pdu->Flags & SMB2_FLAGS_SIGNED) || 115 if (!(smb2_pdu->Flags & SMB2_FLAGS_SIGNED) ||
115 server->tcpStatus == CifsNeedNegotiate) 116 server->tcpStatus == CifsNeedNegotiate)
@@ -120,18 +121,17 @@ smb2_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server)
120 return rc; 121 return rc;
121 } 122 }
122 123
123 rc = smb2_calc_signature2(iov, n_vec, server); 124 rc = smb2_calc_signature(rqst, server);
124 125
125 return rc; 126 return rc;
126} 127}
127 128
128int 129int
129smb2_verify_signature2(struct kvec *iov, unsigned int n_vec, 130smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
130 struct TCP_Server_Info *server)
131{ 131{
132 unsigned int rc; 132 unsigned int rc;
133 char server_response_sig[16]; 133 char server_response_sig[16];
134 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)iov[0].iov_base; 134 struct smb2_hdr *smb2_pdu = (struct smb2_hdr *)rqst->rq_iov[0].iov_base;
135 135
136 if ((smb2_pdu->Command == SMB2_NEGOTIATE) || 136 if ((smb2_pdu->Command == SMB2_NEGOTIATE) ||
137 (smb2_pdu->Command == SMB2_OPLOCK_BREAK) || 137 (smb2_pdu->Command == SMB2_OPLOCK_BREAK) ||
@@ -157,7 +157,7 @@ smb2_verify_signature2(struct kvec *iov, unsigned int n_vec,
157 memset(smb2_pdu->Signature, 0, SMB2_SIGNATURE_SIZE); 157 memset(smb2_pdu->Signature, 0, SMB2_SIGNATURE_SIZE);
158 158
159 mutex_lock(&server->srv_mutex); 159 mutex_lock(&server->srv_mutex);
160 rc = smb2_calc_signature2(iov, n_vec, server); 160 rc = smb2_calc_signature(rqst, server);
161 mutex_unlock(&server->srv_mutex); 161 mutex_unlock(&server->srv_mutex);
162 162
163 if (rc) 163 if (rc)
@@ -170,16 +170,6 @@ smb2_verify_signature2(struct kvec *iov, unsigned int n_vec,
170 return 0; 170 return 0;
171} 171}
172 172
173static int
174smb2_verify_signature(struct smb2_hdr *smb2_pdu, struct TCP_Server_Info *server)
175{
176 struct kvec iov;
177
178 iov.iov_base = (char *)smb2_pdu;
179 iov.iov_len = get_rfc1002_length(smb2_pdu) + 4;
180 return smb2_verify_signature2(&iov, 1, server);
181}
182
183/* 173/*
184 * Set message id for the request. Should be called after wait_for_free_request 174 * Set message id for the request. Should be called after wait_for_free_request
185 * and when srv_mutex is held. 175 * and when srv_mutex is held.
@@ -258,6 +248,12 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
258 bool log_error) 248 bool log_error)
259{ 249{
260 unsigned int len = get_rfc1002_length(mid->resp_buf); 250 unsigned int len = get_rfc1002_length(mid->resp_buf);
251 struct kvec iov;
252 struct smb_rqst rqst = { .rq_iov = &iov,
253 .rq_nvec = 1 };
254
255 iov.iov_base = (char *)mid->resp_buf;
256 iov.iov_len = get_rfc1002_length(mid->resp_buf) + 4;
261 257
262 dump_smb(mid->resp_buf, min_t(u32, 80, len)); 258 dump_smb(mid->resp_buf, min_t(u32, 80, len));
263 /* convert the length into a more usable form */ 259 /* convert the length into a more usable form */
@@ -265,7 +261,7 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
265 (server->sec_mode & (SECMODE_SIGN_REQUIRED|SECMODE_SIGN_ENABLED))) { 261 (server->sec_mode & (SECMODE_SIGN_REQUIRED|SECMODE_SIGN_ENABLED))) {
266 int rc; 262 int rc;
267 263
268 rc = smb2_verify_signature(mid->resp_buf, server); 264 rc = smb2_verify_signature(&rqst, server);
269 if (rc) 265 if (rc)
270 cERROR(1, "SMB signature verification returned error = " 266 cERROR(1, "SMB signature verification returned error = "
271 "%d", rc); 267 "%d", rc);
@@ -281,13 +277,15 @@ smb2_setup_request(struct cifs_ses *ses, struct kvec *iov,
281 int rc; 277 int rc;
282 struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0].iov_base; 278 struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0].iov_base;
283 struct mid_q_entry *mid; 279 struct mid_q_entry *mid;
280 struct smb_rqst rqst = { .rq_iov = iov,
281 .rq_nvec = nvec };
284 282
285 smb2_seq_num_into_buf(ses->server, hdr); 283 smb2_seq_num_into_buf(ses->server, hdr);
286 284
287 rc = smb2_get_mid_entry(ses, hdr, &mid); 285 rc = smb2_get_mid_entry(ses, hdr, &mid);
288 if (rc) 286 if (rc)
289 return rc; 287 return rc;
290 rc = smb2_sign_smb2(iov, nvec, ses->server); 288 rc = smb2_sign_rqst(&rqst, ses->server);
291 if (rc) 289 if (rc)
292 cifs_delete_mid(mid); 290 cifs_delete_mid(mid);
293 *ret_mid = mid; 291 *ret_mid = mid;
@@ -301,6 +299,8 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov,
301 int rc = 0; 299 int rc = 0;
302 struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0].iov_base; 300 struct smb2_hdr *hdr = (struct smb2_hdr *)iov[0].iov_base;
303 struct mid_q_entry *mid; 301 struct mid_q_entry *mid;
302 struct smb_rqst rqst = { .rq_iov = iov,
303 .rq_nvec = nvec };
304 304
305 smb2_seq_num_into_buf(server, hdr); 305 smb2_seq_num_into_buf(server, hdr);
306 306
@@ -308,7 +308,7 @@ smb2_setup_async_request(struct TCP_Server_Info *server, struct kvec *iov,
308 if (mid == NULL) 308 if (mid == NULL)
309 return -ENOMEM; 309 return -ENOMEM;
310 310
311 rc = smb2_sign_smb2(iov, nvec, server); 311 rc = smb2_sign_rqst(&rqst, server);
312 if (rc) { 312 if (rc) {
313 DeleteMidQEntry(mid); 313 DeleteMidQEntry(mid);
314 return rc; 314 return rc;