Commit 977b6170 authored by Ronnie Sahlberg's avatar Ronnie Sahlberg Committed by Steve French

cifs: remove rfc1002 header from all SMB2 response structures

Separate out all the 4 byte rfc1002 headers so that they are no longer
part of the SMB2 header structures to prepare for future work to add
compounding support.

Update the smb3 transform header processing that we no longer have
a rfc1002 header at the start of this structure.

Update smb2_readv_callback to accommodate that the first iovector in the
response is no the smb2 header and no longer a rfc1002 header.
Signed-off-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent b2adf22f
...@@ -882,7 +882,11 @@ cifs_demultiplex_thread(void *p) ...@@ -882,7 +882,11 @@ cifs_demultiplex_thread(void *p)
length = cifs_read_from_socket(server, buf, pdu_length); length = cifs_read_from_socket(server, buf, pdu_length);
if (length < 0) if (length < 0)
continue; continue;
server->total_read = length;
if (server->vals->header_preamble_size == 0)
server->total_read = 0;
else
server->total_read = length;
/* /*
* The right amount was read from socket - 4 bytes, * The right amount was read from socket - 4 bytes,
......
...@@ -2144,12 +2144,11 @@ smb2_dir_needs_close(struct cifsFileInfo *cfile) ...@@ -2144,12 +2144,11 @@ smb2_dir_needs_close(struct cifsFileInfo *cfile)
} }
static void static void
fill_transform_hdr(struct TCP_Server_Info *server, fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
struct smb2_transform_hdr *tr_hdr, struct smb_rqst *old_rq) struct smb_rqst *old_rq)
{ {
struct smb2_sync_hdr *shdr = struct smb2_sync_hdr *shdr =
(struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base; (struct smb2_sync_hdr *)old_rq->rq_iov[1].iov_base;
unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base);
memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr)); memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr));
tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
...@@ -2157,8 +2156,6 @@ fill_transform_hdr(struct TCP_Server_Info *server, ...@@ -2157,8 +2156,6 @@ fill_transform_hdr(struct TCP_Server_Info *server,
tr_hdr->Flags = cpu_to_le16(0x01); tr_hdr->Flags = cpu_to_le16(0x01);
get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE); get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CMM_NONCE);
memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8); memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - server->vals->header_preamble_size);
inc_rfc1001_len(tr_hdr, orig_len);
} }
/* We can not use the normal sg_set_buf() as we will sometimes pass a /* We can not use the normal sg_set_buf() as we will sometimes pass a
...@@ -2170,11 +2167,16 @@ static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf, ...@@ -2170,11 +2167,16 @@ static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
} }
/* Assumes:
* rqst->rq_iov[0] is rfc1002 length
* rqst->rq_iov[1] is tranform header
* rqst->rq_iov[2+] data to be encrypted/decrypted
*/
static struct scatterlist * static struct scatterlist *
init_sg(struct smb_rqst *rqst, u8 *sign) init_sg(struct smb_rqst *rqst, u8 *sign)
{ {
unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages + 1; unsigned int sg_len = rqst->rq_nvec + rqst->rq_npages;
unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24; unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
struct scatterlist *sg; struct scatterlist *sg;
unsigned int i; unsigned int i;
unsigned int j; unsigned int j;
...@@ -2184,10 +2186,10 @@ init_sg(struct smb_rqst *rqst, u8 *sign) ...@@ -2184,10 +2186,10 @@ init_sg(struct smb_rqst *rqst, u8 *sign)
return NULL; return NULL;
sg_init_table(sg, sg_len); sg_init_table(sg, sg_len);
smb2_sg_set_buf(&sg[0], rqst->rq_iov[0].iov_base + 24, assoc_data_len); smb2_sg_set_buf(&sg[0], rqst->rq_iov[1].iov_base + 20, assoc_data_len);
for (i = 1; i < rqst->rq_nvec; i++) for (i = 1; i < rqst->rq_nvec - 1; i++)
smb2_sg_set_buf(&sg[i], rqst->rq_iov[i].iov_base, smb2_sg_set_buf(&sg[i], rqst->rq_iov[i+1].iov_base,
rqst->rq_iov[i].iov_len); rqst->rq_iov[i+1].iov_len);
for (j = 0; i < sg_len - 1; i++, j++) { for (j = 0; i < sg_len - 1; i++, j++) {
unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz unsigned int len = (j < rqst->rq_npages - 1) ? rqst->rq_pagesz
: rqst->rq_tailsz; : rqst->rq_tailsz;
...@@ -2219,9 +2221,10 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key) ...@@ -2219,9 +2221,10 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
} }
/* /*
* Encrypt or decrypt @rqst message. @rqst has the following format: * Encrypt or decrypt @rqst message. @rqst has the following format:
* iov[0] - transform header (associate data), * iov[0] - rfc1002 length
* iov[1-N] and pages - data to encrypt. * iov[1] - transform header (associate data),
* On success return encrypted data in iov[1-N] and pages, leave iov[0] * iov[2-N] and pages - data to encrypt.
* On success return encrypted data in iov[2-N] and pages, leave iov[0-1]
* untouched. * untouched.
*/ */
static int static int
...@@ -2316,6 +2319,10 @@ crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc) ...@@ -2316,6 +2319,10 @@ crypt_message(struct TCP_Server_Info *server, struct smb_rqst *rqst, int enc)
return rc; return rc;
} }
/*
* This is called from smb_send_rqst. At this point we have the rfc1002
* header as the first element in the vector.
*/
static int static int
smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
struct smb_rqst *old_rq) struct smb_rqst *old_rq)
...@@ -2324,6 +2331,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, ...@@ -2324,6 +2331,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
struct page **pages; struct page **pages;
struct smb2_transform_hdr *tr_hdr; struct smb2_transform_hdr *tr_hdr;
unsigned int npages = old_rq->rq_npages; unsigned int npages = old_rq->rq_npages;
unsigned int orig_len = get_rfc1002_length(old_rq->rq_iov[0].iov_base);
int i; int i;
int rc = -ENOMEM; int rc = -ENOMEM;
...@@ -2342,24 +2350,34 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq, ...@@ -2342,24 +2350,34 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, struct smb_rqst *new_rq,
goto err_free_pages; goto err_free_pages;
} }
iov = kmalloc_array(old_rq->rq_nvec, sizeof(struct kvec), GFP_KERNEL); /* Make space for one extra iov to hold the transform header */
iov = kmalloc_array(old_rq->rq_nvec + 1, sizeof(struct kvec),
GFP_KERNEL);
if (!iov) if (!iov)
goto err_free_pages; goto err_free_pages;
/* copy all iovs from the old except the 1st one (rfc1002 length) */ /* copy all iovs from the old except the 1st one (rfc1002 length) */
memcpy(&iov[1], &old_rq->rq_iov[1], memcpy(&iov[2], &old_rq->rq_iov[1],
sizeof(struct kvec) * (old_rq->rq_nvec - 1)); sizeof(struct kvec) * (old_rq->rq_nvec - 1));
/* copy the rfc1002 iov */
iov[0].iov_base = old_rq->rq_iov[0].iov_base;
iov[0].iov_len = old_rq->rq_iov[0].iov_len;
new_rq->rq_iov = iov; new_rq->rq_iov = iov;
new_rq->rq_nvec = old_rq->rq_nvec; new_rq->rq_nvec = old_rq->rq_nvec + 1;
tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL); tr_hdr = kmalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL);
if (!tr_hdr) if (!tr_hdr)
goto err_free_iov; goto err_free_iov;
/* fill the 1st iov with a transform header */ /* fill the 2nd iov with a transform header */
fill_transform_hdr(server, tr_hdr, old_rq); fill_transform_hdr(tr_hdr, orig_len, old_rq);
new_rq->rq_iov[0].iov_base = tr_hdr; new_rq->rq_iov[1].iov_base = tr_hdr;
new_rq->rq_iov[0].iov_len = sizeof(struct smb2_transform_hdr); new_rq->rq_iov[1].iov_len = sizeof(struct smb2_transform_hdr);
/* Update rfc1002 header */
inc_rfc1001_len(new_rq->rq_iov[0].iov_base,
sizeof(struct smb2_transform_hdr));
/* copy pages form the old */ /* copy pages form the old */
for (i = 0; i < npages; i++) { for (i = 0; i < npages; i++) {
...@@ -2399,7 +2417,7 @@ smb3_free_transform_rq(struct smb_rqst *rqst) ...@@ -2399,7 +2417,7 @@ smb3_free_transform_rq(struct smb_rqst *rqst)
put_page(rqst->rq_pages[i]); put_page(rqst->rq_pages[i]);
kfree(rqst->rq_pages); kfree(rqst->rq_pages);
/* free transform header */ /* free transform header */
kfree(rqst->rq_iov[0].iov_base); kfree(rqst->rq_iov[1].iov_base);
kfree(rqst->rq_iov); kfree(rqst->rq_iov);
} }
...@@ -2416,18 +2434,19 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf, ...@@ -2416,18 +2434,19 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
unsigned int buf_data_size, struct page **pages, unsigned int buf_data_size, struct page **pages,
unsigned int npages, unsigned int page_data_size) unsigned int npages, unsigned int page_data_size)
{ {
struct kvec iov[2]; struct kvec iov[3];
struct smb_rqst rqst = {NULL}; struct smb_rqst rqst = {NULL};
struct smb2_hdr *hdr;
int rc; int rc;
iov[0].iov_base = buf; iov[0].iov_base = NULL;
iov[0].iov_len = sizeof(struct smb2_transform_hdr); iov[0].iov_len = 0;
iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr); iov[1].iov_base = buf;
iov[1].iov_len = buf_data_size; iov[1].iov_len = sizeof(struct smb2_transform_hdr);
iov[2].iov_base = buf + sizeof(struct smb2_transform_hdr);
iov[2].iov_len = buf_data_size;
rqst.rq_iov = iov; rqst.rq_iov = iov;
rqst.rq_nvec = 2; rqst.rq_nvec = 3;
rqst.rq_pages = pages; rqst.rq_pages = pages;
rqst.rq_npages = npages; rqst.rq_npages = npages;
rqst.rq_pagesz = PAGE_SIZE; rqst.rq_pagesz = PAGE_SIZE;
...@@ -2439,10 +2458,9 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf, ...@@ -2439,10 +2458,9 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
if (rc) if (rc)
return rc; return rc;
memmove(buf + server->vals->header_preamble_size, iov[1].iov_base, buf_data_size); memmove(buf + server->vals->header_preamble_size, iov[2].iov_base, buf_data_size);
hdr = (struct smb2_hdr *)buf;
hdr->smb2_buf_length = cpu_to_be32(buf_data_size + page_data_size); server->total_read = buf_data_size + page_data_size;
server->total_read = buf_data_size + page_data_size + server->vals->header_preamble_size;
return rc; return rc;
} }
...@@ -3196,8 +3214,8 @@ struct smb_version_values smb20_values = { ...@@ -3196,8 +3214,8 @@ struct smb_version_values smb20_values = {
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
.shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
.unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
.header_size = sizeof(struct smb2_hdr), .header_size = sizeof(struct smb2_sync_hdr),
.header_preamble_size = 4, .header_preamble_size = 0,
.max_header_size = MAX_SMB2_HDR_SIZE, .max_header_size = MAX_SMB2_HDR_SIZE,
.read_rsp_size = sizeof(struct smb2_read_rsp) - 1, .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
.lock_cmd = SMB2_LOCK, .lock_cmd = SMB2_LOCK,
...@@ -3217,8 +3235,8 @@ struct smb_version_values smb21_values = { ...@@ -3217,8 +3235,8 @@ struct smb_version_values smb21_values = {
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
.shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
.unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
.header_size = sizeof(struct smb2_hdr), .header_size = sizeof(struct smb2_sync_hdr),
.header_preamble_size = 4, .header_preamble_size = 0,
.max_header_size = MAX_SMB2_HDR_SIZE, .max_header_size = MAX_SMB2_HDR_SIZE,
.read_rsp_size = sizeof(struct smb2_read_rsp) - 1, .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
.lock_cmd = SMB2_LOCK, .lock_cmd = SMB2_LOCK,
...@@ -3238,8 +3256,8 @@ struct smb_version_values smb3any_values = { ...@@ -3238,8 +3256,8 @@ struct smb_version_values smb3any_values = {
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
.shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
.unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
.header_size = sizeof(struct smb2_hdr), .header_size = sizeof(struct smb2_sync_hdr),
.header_preamble_size = 4, .header_preamble_size = 0,
.max_header_size = MAX_SMB2_HDR_SIZE, .max_header_size = MAX_SMB2_HDR_SIZE,
.read_rsp_size = sizeof(struct smb2_read_rsp) - 1, .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
.lock_cmd = SMB2_LOCK, .lock_cmd = SMB2_LOCK,
...@@ -3259,8 +3277,8 @@ struct smb_version_values smbdefault_values = { ...@@ -3259,8 +3277,8 @@ struct smb_version_values smbdefault_values = {
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
.shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
.unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
.header_size = sizeof(struct smb2_hdr), .header_size = sizeof(struct smb2_sync_hdr),
.header_preamble_size = 4, .header_preamble_size = 0,
.max_header_size = MAX_SMB2_HDR_SIZE, .max_header_size = MAX_SMB2_HDR_SIZE,
.read_rsp_size = sizeof(struct smb2_read_rsp) - 1, .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
.lock_cmd = SMB2_LOCK, .lock_cmd = SMB2_LOCK,
...@@ -3280,8 +3298,8 @@ struct smb_version_values smb30_values = { ...@@ -3280,8 +3298,8 @@ struct smb_version_values smb30_values = {
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
.shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
.unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
.header_size = sizeof(struct smb2_hdr), .header_size = sizeof(struct smb2_sync_hdr),
.header_preamble_size = 4, .header_preamble_size = 0,
.max_header_size = MAX_SMB2_HDR_SIZE, .max_header_size = MAX_SMB2_HDR_SIZE,
.read_rsp_size = sizeof(struct smb2_read_rsp) - 1, .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
.lock_cmd = SMB2_LOCK, .lock_cmd = SMB2_LOCK,
...@@ -3301,8 +3319,8 @@ struct smb_version_values smb302_values = { ...@@ -3301,8 +3319,8 @@ struct smb_version_values smb302_values = {
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
.shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
.unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
.header_size = sizeof(struct smb2_hdr), .header_size = sizeof(struct smb2_sync_hdr),
.header_preamble_size = 4, .header_preamble_size = 0,
.max_header_size = MAX_SMB2_HDR_SIZE, .max_header_size = MAX_SMB2_HDR_SIZE,
.read_rsp_size = sizeof(struct smb2_read_rsp) - 1, .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
.lock_cmd = SMB2_LOCK, .lock_cmd = SMB2_LOCK,
...@@ -3323,8 +3341,8 @@ struct smb_version_values smb311_values = { ...@@ -3323,8 +3341,8 @@ struct smb_version_values smb311_values = {
.exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK, .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
.shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK, .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
.unlock_lock_type = SMB2_LOCKFLAG_UNLOCK, .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
.header_size = sizeof(struct smb2_hdr), .header_size = sizeof(struct smb2_sync_hdr),
.header_preamble_size = 4, .header_preamble_size = 0,
.max_header_size = MAX_SMB2_HDR_SIZE, .max_header_size = MAX_SMB2_HDR_SIZE,
.read_rsp_size = sizeof(struct smb2_read_rsp) - 1, .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
.lock_cmd = SMB2_LOCK, .lock_cmd = SMB2_LOCK,
......
...@@ -465,12 +465,12 @@ static int decode_encrypt_ctx(struct TCP_Server_Info *server, ...@@ -465,12 +465,12 @@ static int decode_encrypt_ctx(struct TCP_Server_Info *server,
} }
static int smb311_decode_neg_context(struct smb2_negotiate_rsp *rsp, static int smb311_decode_neg_context(struct smb2_negotiate_rsp *rsp,
struct TCP_Server_Info *server) struct TCP_Server_Info *server,
unsigned int len_of_smb)
{ {
struct smb2_neg_context *pctx; struct smb2_neg_context *pctx;
unsigned int offset = le32_to_cpu(rsp->NegotiateContextOffset); unsigned int offset = le32_to_cpu(rsp->NegotiateContextOffset);
unsigned int ctxt_cnt = le16_to_cpu(rsp->NegotiateContextCount); unsigned int ctxt_cnt = le16_to_cpu(rsp->NegotiateContextCount);
unsigned int len_of_smb = be32_to_cpu(rsp->hdr.smb2_buf_length);
unsigned int len_of_ctxts, i; unsigned int len_of_ctxts, i;
int rc = 0; int rc = 0;
...@@ -794,7 +794,8 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses) ...@@ -794,7 +794,8 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
#ifdef CONFIG_CIFS_SMB311 #ifdef CONFIG_CIFS_SMB311
if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) { if (rsp->DialectRevision == cpu_to_le16(SMB311_PROT_ID)) {
if (rsp->NegotiateContextCount) if (rsp->NegotiateContextCount)
rc = smb311_decode_neg_context(rsp, server); rc = smb311_decode_neg_context(rsp, server,
rsp_iov.iov_len);
else else
cifs_dbg(VFS, "Missing expected negotiate contexts\n"); cifs_dbg(VFS, "Missing expected negotiate contexts\n");
} }
...@@ -2100,7 +2101,6 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, ...@@ -2100,7 +2101,6 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
{ {
struct smb2_ioctl_req *req; struct smb2_ioctl_req *req;
struct smb2_ioctl_rsp *rsp; struct smb2_ioctl_rsp *rsp;
struct smb2_sync_hdr *shdr;
struct cifs_ses *ses; struct cifs_ses *ses;
struct kvec iov[2]; struct kvec iov[2];
struct kvec rsp_iov; struct kvec rsp_iov;
...@@ -2225,7 +2225,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, ...@@ -2225,7 +2225,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
goto ioctl_exit; goto ioctl_exit;
} }
if (get_rfc1002_length(rsp) < le32_to_cpu(rsp->OutputOffset) + *plen) { if (rsp_iov.iov_len < le32_to_cpu(rsp->OutputOffset) + *plen) {
cifs_dbg(VFS, "Malformed ioctl resp: len %d offset %d\n", *plen, cifs_dbg(VFS, "Malformed ioctl resp: len %d offset %d\n", *plen,
le32_to_cpu(rsp->OutputOffset)); le32_to_cpu(rsp->OutputOffset));
*plen = 0; *plen = 0;
...@@ -2239,8 +2239,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, ...@@ -2239,8 +2239,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
goto ioctl_exit; goto ioctl_exit;
} }
shdr = get_sync_hdr(rsp); memcpy(*out_data, (char *)rsp + le32_to_cpu(rsp->OutputOffset), *plen);
memcpy(*out_data, (char *)shdr + le32_to_cpu(rsp->OutputOffset), *plen);
ioctl_exit: ioctl_exit:
free_rsp_buf(resp_buftype, rsp); free_rsp_buf(resp_buftype, rsp);
return rc; return rc;
...@@ -2781,7 +2780,7 @@ smb2_readv_callback(struct mid_q_entry *mid) ...@@ -2781,7 +2780,7 @@ smb2_readv_callback(struct mid_q_entry *mid)
struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink); struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
struct TCP_Server_Info *server = tcon->ses->server; struct TCP_Server_Info *server = tcon->ses->server;
struct smb2_sync_hdr *shdr = struct smb2_sync_hdr *shdr =
(struct smb2_sync_hdr *)rdata->iov[1].iov_base; (struct smb2_sync_hdr *)rdata->iov[0].iov_base;
unsigned int credits_received = 1; unsigned int credits_received = 1;
struct smb_rqst rqst = { .rq_iov = rdata->iov, struct smb_rqst rqst = { .rq_iov = rdata->iov,
.rq_nvec = 2, .rq_nvec = 2,
...@@ -2933,7 +2932,6 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, ...@@ -2933,7 +2932,6 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
int resp_buftype, rc = -EACCES; int resp_buftype, rc = -EACCES;
struct smb2_read_plain_req *req = NULL; struct smb2_read_plain_req *req = NULL;
struct smb2_read_rsp *rsp = NULL; struct smb2_read_rsp *rsp = NULL;
struct smb2_sync_hdr *shdr;
struct kvec iov[1]; struct kvec iov[1];
struct kvec rsp_iov; struct kvec rsp_iov;
unsigned int total_len; unsigned int total_len;
...@@ -2980,10 +2978,8 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, ...@@ -2980,10 +2978,8 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
*nbytes = 0; *nbytes = 0;
} }
shdr = get_sync_hdr(rsp);
if (*buf) { if (*buf) {
memcpy(*buf, (char *)shdr + rsp->DataOffset, *nbytes); memcpy(*buf, (char *)rsp + rsp->DataOffset, *nbytes);
free_rsp_buf(resp_buftype, rsp_iov.iov_base); free_rsp_buf(resp_buftype, rsp_iov.iov_base);
} else if (resp_buftype != CIFS_NO_BUFFER) { } else if (resp_buftype != CIFS_NO_BUFFER) {
*buf = rsp_iov.iov_base; *buf = rsp_iov.iov_base;
...@@ -3426,10 +3422,9 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -3426,10 +3422,9 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
cifs_buf_release(srch_inf->ntwrk_buf_start); cifs_buf_release(srch_inf->ntwrk_buf_start);
} }
srch_inf->ntwrk_buf_start = (char *)rsp; srch_inf->ntwrk_buf_start = (char *)rsp;
srch_inf->srch_entries_start = srch_inf->last_entry = 4 /* rfclen */ + srch_inf->srch_entries_start = srch_inf->last_entry =
(char *)&rsp->hdr + le16_to_cpu(rsp->OutputBufferOffset); (char *)rsp + le16_to_cpu(rsp->OutputBufferOffset);
/* 4 for rfc1002 length field */ end_of_smb = rsp_iov.iov_len + (char *)rsp;
end_of_smb = get_rfc1002_length(rsp) + 4 + (char *)&rsp->hdr;
srch_inf->entries_in_buffer = srch_inf->entries_in_buffer =
num_entries(srch_inf->srch_entries_start, end_of_smb, num_entries(srch_inf->srch_entries_start, end_of_smb,
&srch_inf->last_entry, info_buf_size); &srch_inf->last_entry, info_buf_size);
......
...@@ -123,9 +123,6 @@ struct smb2_sync_pdu { ...@@ -123,9 +123,6 @@ struct smb2_sync_pdu {
} __packed; } __packed;
struct smb2_hdr { struct smb2_hdr {
__be32 smb2_buf_length; /* big endian on wire */
/* length is only two or three bytes - with */
/* one or two byte type preceding it that MBZ */
struct smb2_sync_hdr sync_hdr; struct smb2_sync_hdr sync_hdr;
} __packed; } __packed;
...@@ -138,9 +135,6 @@ struct smb2_pdu { ...@@ -138,9 +135,6 @@ struct smb2_pdu {
#define SMB3_AES128GCM_NONCE 12 #define SMB3_AES128GCM_NONCE 12
struct smb2_transform_hdr { struct smb2_transform_hdr {
__be32 smb2_buf_length; /* big endian on wire */
/* length is only two or three bytes - with
one or two byte type preceding it that MBZ */
__le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */ __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
__u8 Signature[16]; __u8 Signature[16];
__u8 Nonce[16]; __u8 Nonce[16];
......
...@@ -480,7 +480,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) ...@@ -480,7 +480,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
unsigned int rc; unsigned int rc;
char server_response_sig[16]; char server_response_sig[16];
struct smb2_sync_hdr *shdr = struct smb2_sync_hdr *shdr =
(struct smb2_sync_hdr *)rqst->rq_iov[1].iov_base; (struct smb2_sync_hdr *)rqst->rq_iov[0].iov_base;
if ((shdr->Command == SMB2_NEGOTIATE) || if ((shdr->Command == SMB2_NEGOTIATE) ||
(shdr->Command == SMB2_SESSION_SETUP) || (shdr->Command == SMB2_SESSION_SETUP) ||
...@@ -605,14 +605,12 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, ...@@ -605,14 +605,12 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
bool log_error) bool log_error)
{ {
unsigned int len = mid->resp_buf_size; unsigned int len = mid->resp_buf_size;
struct kvec iov[2]; struct kvec iov[1];
struct smb_rqst rqst = { .rq_iov = iov, struct smb_rqst rqst = { .rq_iov = iov,
.rq_nvec = 2 }; .rq_nvec = 1 };
iov[0].iov_base = (char *)mid->resp_buf; iov[0].iov_base = (char *)mid->resp_buf;
iov[0].iov_len = 4; iov[0].iov_len = len;
iov[1].iov_base = (char *)mid->resp_buf + 4;
iov[1].iov_len = len;
dump_smb(mid->resp_buf, min_t(u32, 80, len)); dump_smb(mid->resp_buf, min_t(u32, 80, len));
/* convert the length into a more usable form */ /* convert the length into a more usable form */
......
...@@ -800,8 +800,8 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, ...@@ -800,8 +800,8 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses,
#ifdef CONFIG_CIFS_SMB311 #ifdef CONFIG_CIFS_SMB311
if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) { if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) {
struct kvec iov = { struct kvec iov = {
.iov_base = buf + 4, .iov_base = buf,
.iov_len = get_rfc1002_length(buf) .iov_len = midQ->resp_buf_size
}; };
smb311_update_preauth_hash(ses, &iov, 1); smb311_update_preauth_hash(ses, &iov, 1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment