SMB3 encryption support
Subsystems (2)
v2 cover SMB3 encryption support
This patchset adds encryption support when SMB3 version of the protocol and higher is negotiated. The encryption is done through the kernel crypto API (CCM(AES)).
The patchset has been successfully tested by xfstests and cthon test suites with encrypted file shares on Samba.
Patches are split into several groups:
1) #1-#4: prepare transport infractructure to be able to send SMB3 transform header; this is done primarily by separating RFC1001 length and SMB2 header into different iovs.
2) #5-#6: simplify SMB2 header processing and cleaning up a read codepath.
3) #7-#9: encrypt outcoming packets by transforming them before sending.
4) #10-#14: decrypt incoming packets and pass ordinary SMB2 messages for further usual processing.
5) #15: allow to use "seal" mount option to request the encryption on a share.
Changes since v1:
- module dependencies are fixed;
- error path handling during message decryption is fixed;
- other minor fixes.
Pavel Shilovsky (15):
CIFS: Separate SMB2 header structure
CIFS: Make SendReceive2() takes resp iov
CIFS: Make send_cancel take rqst as argument
CIFS: Send RFC1001 length in a separate iov
CIFS: Separate SMB2 sync header processing
CIFS: Separate RFC1001 length processing for SMB2 read
CIFS: Add capability to transform requests before sending
CIFS: Enable encryption during session setup phase
CIFS: Encrypt SMB3 requests before sending
CIFS: Add transform header handling callbacks
CIFS: Add mid handle callback
CIFS: Add copy into pages callback for a read operation
CIFS: Decrypt and process small encrypted packets
CIFS: Add capability to decrypt big read responses
CIFS: Allow to switch on encryption with seal mount option
fs/cifs/Kconfig | 2 + fs/cifs/cifsencrypt.c | 51 ++-- fs/cifs/cifsfs.c | 2 + fs/cifs/cifsglob.h | 28 +- fs/cifs/cifsproto.h | 13 +- fs/cifs/cifssmb.c | 135 +++++----- fs/cifs/connect.c | 71 ++++-- fs/cifs/file.c | 52 +++- fs/cifs/sess.c | 27 +- fs/cifs/smb1ops.c | 4 +- fs/cifs/smb2glob.h | 5 + fs/cifs/smb2maperror.c | 5 +- fs/cifs/smb2misc.c | 61 +++-- fs/cifs/smb2ops.c | 663 +++++++++++++++++++++++++++++++++++++++++++++++- fs/cifs/smb2pdu.c | 575 +++++++++++++++++++++++++++-------------- fs/cifs/smb2pdu.h | 27 +- fs/cifs/smb2proto.h | 5 + fs/cifs/smb2transport.c | 132 ++++++---- fs/cifs/transport.c | 171 ++++++++----- 19 files changed, 1556 insertions(+), 473 deletions(-)
Signature · 1 line
2.7.4
A message that is not in the archive (sent off-list or not yet received): 1485812384-28870-1-git-send-email-pshilov-0li6OtcxBFHby3iVrkZq2A@public.gmane.org
PATCH v2 1/15 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.
--- fs/cifs/smb2glob.h | 5 ++ fs/cifs/smb2maperror.c | 5 +- fs/cifs/smb2misc.c | 61 ++++++++++++---------- fs/cifs/smb2ops.c | 26 +++++----- fs/cifs/smb2pdu.c | 132 ++++++++++++++++++++++++++---------------------- fs/cifs/smb2pdu.h | 12 +++-- fs/cifs/smb2transport.c | 81 +++++++++++++++-------------- 7 files changed, 174 insertions(+), 148 deletions(-)
fs/cifs/smb2glob.h +5 -0
@@ -61,4 +61,9 @@/* Maximum buffer size value we can send with 1 credit */ #define SMB2_MAX_BUFFER_SIZE 65536 +static inline struct smb2_sync_hdr *get_sync_hdr (void *buf) +{ +return &(((struct smb2_hdr *)buf)->sync_hdr); +} +#endif /* _SMB2_GLOB_H */
fs/cifs/smb2maperror.c +3 -2
@@ -26,6 +26,7 @@#include "smb2pdu.h" #include "smb2proto.h" #include "smb2status.h" +#include "smb2glob.h" struct status_to_posix_error {__le32 smb2_status;
@@ -2449,10 +2450,10 @@ smb2_print_status(__le32 status)int map_smb2_to_linux_error (char *buf,bool log_err) { -struct smb2_hdr *hdr = (struct smb2_hdr *)buf; +struct smb2_sync_hdr *shdr =get_sync_hdr (buf);unsigned int i;int rc = -EIO ; -__le32 smb2err = hdr->Status; +__le32 smb2err = shdr->Status;if (smb2err ==0 )return 0 ;
fs/cifs/smb2misc.c +33 -28
176 lines not on this page · raw message
fs/cifs/smb2ops.c +14 -12
@@ -119,7 +119,9 @@ smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)static unsigned int smb2_get_credits (struct mid_q_entry *mid) { -return le16_to_cpu (((struct smb2_hdr *)mid->resp_buf)->CreditRequest); +struct smb2_sync_hdr *shdr =get_sync_hdr (mid->resp_buf); + +return le16_to_cpu (shdr->CreditRequest); } static int
@@ -184,10 +186,10 @@ static struct mid_q_entry * smb2_find_mid(struct TCP_Server_Info *server, char *buf) { struct mid_q_entry *mid; -struct smb2_hdr *hdr = (struct smb2_hdr *)buf; -__u64 wire_mid =le64_to_cpu (hdr->MessageId); +struct smb2_sync_hdr *shdr =get_sync_hdr (buf); +__u64 wire_mid =le64_to_cpu (shdr->MessageId); -if (hdr->ProtocolId ==SMB2_TRANSFORM_PROTO_NUM ) { +if (shdr->ProtocolId ==SMB2_TRANSFORM_PROTO_NUM ) {cifs_dbg (VFS ,"encrypted frame parsing not supported yet" );return NULL ; }
@@ -196,7 +198,7 @@ smb2_find_mid(struct TCP_Server_Info *server, char *buf)list_for_each_entry (mid, &server->pending_mid_q, qhead) {if ((mid->mid == wire_mid) && (mid->mid_state ==MID_REQUEST_SUBMITTED ) && - (mid->command == hdr->Command)) { + (mid->command == shdr->Command)) {spin_unlock (&GlobalMid_Lock);return mid; }
@@ -209,12 +211,12 @@ static void smb2_dump_detail(void *buf) {#ifdef CONFIG_CIFS_DEBUG2 -struct smb2_hdr *smb = (struct smb2_hdr *)buf; +struct smb2_sync_hdr *shdr =get_sync_hdr (buf);cifs_dbg (VFS ,"Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n" , - smb->Command, smb->Status, smb->Flags, smb->MessageId, - smb->ProcessId); -cifs_dbg (VFS ,"smb buf %p len %u\n" , smb,smb2_calc_size (smb)); + shdr->Command, shdr->Status, shdr->Flags, shdr->MessageId, + shdr->ProcessId); +cifs_dbg (VFS ,"smb buf %p len %u\n" , buf,smb2_calc_size (buf));#endif }
@@ -1002,14 +1004,14 @@ smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,static bool smb2_is_status_pending (char *buf,struct TCP_Server_Info *server,int length) { -struct smb2_hdr *hdr = (struct smb2_hdr *)buf; +struct smb2_sync_hdr *shdr =get_sync_hdr (buf); -if (hdr->Status !=STATUS_PENDING ) +if (shdr->Status !=STATUS_PENDING )return false;if (!length) {spin_lock (&server->req_lock); - server->credits +=le16_to_cpu (hdr->CreditRequest); + server->credits +=le16_to_cpu (shdr->CreditRequest);spin_unlock (&server->req_lock);wake_up (&server->request_q); }
fs/cifs/smb2pdu.c +71 -61
419 lines not on this page · raw message
fs/cifs/smb2pdu.h +8 -4
@@ -101,10 +101,7 @@#define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64) -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 {__le32 ProtocolId;/* 0xFE 'S' 'M' 'B' */ __le16 StructureSize;/* 64 */ __le16 CreditCharge;/* MBZ */
@@ -120,6 +117,13 @@ struct smb2_hdr {__u8 Signature[16 ]; } __packed; +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; +} __packed; +struct smb2_pdu {struct smb2_hdr hdr;__le16 StructureSize2;/* size of wct area (varies, request specific) */
fs/cifs/smb2transport.c +40 -41
235 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 2/15 CIFS: Make SendReceive2() takes resp iov
In reply to a message not in the archiveNow SendReceive2 frees the first iov and returns a response buffer in it that increases a code complexity. Simplify this by making a caller responsible for freeing request buffer itself and returning a response buffer in a separate iov.
--- fs/cifs/cifsproto.h | 3 +- fs/cifs/cifssmb.c | 70 ++++++++++++++++------------ fs/cifs/sess.c | 5 +- fs/cifs/smb2pdu.c | 128 +++++++++++++++++++++++++++++++++------------------- fs/cifs/transport.c | 30 ++++-------- 5 files changed, 136 insertions(+), 100 deletions(-)
fs/cifs/cifsproto.h +2 -1
@@ -95,7 +95,8 @@ extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int *credits);extern int SendReceive2 (const unsigned int /* xid */ ,struct cifs_ses *,struct kvec *,int /* nvec to send */ , -int */* type of buf returned */ ,const int flags); +int */* type of buf returned */ ,const int flags, +struct kvec */* resp vec */ ); extern int SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *ptcon, struct smb_hdr *in_buf ,
fs/cifs/cifssmb.c +40 -30
237 lines not on this page · raw message
fs/cifs/sess.c +4 -1
@@ -652,6 +652,7 @@ sess_sendreceive(struct sess_data *sess_data)int rc;struct smb_hdr *smb_buf = (struct smb_hdr *) sess_data->iov[0 ].iov_base;__u16 count; +struct kvec rsp_iov = {NULL ,0 }; count = sess_data->iov[1 ].iov_len + sess_data->iov[2 ].iov_len; smb_buf->smb_buf_length =
@@ -661,7 +662,9 @@ sess_sendreceive(struct sess_data *sess_data) rc =SendReceive2 (sess_data->xid, sess_data->ses, sess_data->iov,3 /* num_iovecs */ , &sess_data->buf0_type, -CIFS_LOG_ERROR ); +CIFS_LOG_ERROR , &rsp_iov); +cifs_small_buf_release (sess_data->iov[0 ].iov_base); +memcpy (&sess_data->iov[0 ], &rsp_iov,sizeof (struct kvec ));return rc; }
fs/cifs/smb2pdu.c +81 -47
403 lines not on this page · raw message
fs/cifs/transport.c +9 -21
@@ -546,12 +546,13 @@ SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses, {int rc;struct kvec iov[1 ]; +struct kvec rsp_iov;int resp_buf_type; iov[0 ].iov_base = in_buf; iov[0 ].iov_len =get_rfc1002_length (in_buf) +4 ; flags |=CIFS_NO_RESP ; - rc =SendReceive2 (xid, ses, iov,1 , &resp_buf_type, flags); + rc =SendReceive2 (xid, ses, iov,1 , &resp_buf_type, flags, &rsp_iov);cifs_dbg (NOISY ,"SendRcvNoRsp flags %d rc %d\n" , flags, rc);return rc;
@@ -650,7 +651,7 @@ cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)int SendReceive2 (const unsigned int xid,struct cifs_ses *ses,struct kvec *iov,int n_vec,int *resp_buf_type/* ret */ , -const int flags) +const int flags,struct kvec *resp_iov) {int rc =0 ;int timeout, optype;
@@ -666,15 +667,12 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, *resp_buf_type =CIFS_NO_BUFFER ;/* no response buf yet */ if ((ses ==NULL ) || (ses->server ==NULL )) { -cifs_small_buf_release (buf);cifs_dbg (VFS ,"Null session\n" );return -EIO ; } -if (ses->server->tcpStatus == CifsExiting) { -cifs_small_buf_release (buf); +if (ses->server->tcpStatus == CifsExiting)return -ENOENT ; - }/* * Ensure that we do not send more than 50 overlapping requests
@@ -683,10 +681,8 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,*/ rc =wait_for_free_request (ses->server, timeout, optype); -if (rc) { -cifs_small_buf_release (buf); +if (rc)return rc; - }/* * Make sure that we sign in the same order that we send on this socket
@@ -699,7 +695,6 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, midQ = ses->server->ops->setup_request (ses, &rqst);if (IS_ERR (midQ)) {mutex_unlock (&ses->server->srv_mutex); -cifs_small_buf_release (buf);/* Update # of requests on wire to server */ add_credits (ses->server,1 , optype);return PTR_ERR (midQ);
@@ -715,15 +710,11 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, ses->server->sequence_number -=2 ;mutex_unlock (&ses->server->srv_mutex); -if (rc <0 ) { -cifs_small_buf_release (buf); +if (rc <0 ) goto out; - } -if (timeout ==CIFS_ASYNC_OP ) { -cifs_small_buf_release (buf); +if (timeout ==CIFS_ASYNC_OP ) goto out; - } rc =wait_for_response (ses->server, midQ);if (rc !=0 ) {
@@ -732,15 +723,12 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses,if (midQ->mid_state ==MID_REQUEST_SUBMITTED ) { midQ->callback = DeleteMidQEntry;spin_unlock (&GlobalMid_Lock); -cifs_small_buf_release (buf);add_credits (ses->server,1 , optype);return rc; }spin_unlock (&GlobalMid_Lock); } -cifs_small_buf_release (buf); - rc =cifs_sync_mid_result (midQ, ses->server);if (rc !=0 ) {add_credits (ses->server,1 , optype);
@@ -754,8 +742,8 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, } buf = (char *)midQ->resp_buf; - iov[0 ].iov_base = buf; - iov[0 ].iov_len =get_rfc1002_length (buf) +4 ; + resp_iov->iov_base = buf; + resp_iov->iov_len =get_rfc1002_length (buf) +4 ;if (midQ->large_buf) *resp_buf_type =CIFS_LARGE_BUFFER ;else
Signature · 1 line
2.7.4
PATCH v2 3/15 CIFS: Make send_cancel take rqst as argument
In reply to a message not in the archive--- fs/cifs/cifsglob.h | 2 +- fs/cifs/smb1ops.c | 4 ++-- fs/cifs/transport.c | 33 +++++++++++++++++++-------------- 3 files changed, 22 insertions(+), 17 deletions(-)
fs/cifs/cifsglob.h +1 -1
@@ -208,7 +208,7 @@ struct cifsInodeInfo;struct cifs_open_parms ;struct smb_version_operations { -int (*send_cancel)(struct TCP_Server_Info *,void *, +int (*send_cancel)(struct TCP_Server_Info *,struct smb_rqst *,struct mid_q_entry *);bool (*compare_fids)(struct cifsFileInfo *,struct cifsFileInfo *);/* setup request: allocate mid, sign message */
fs/cifs/smb1ops.c +2 -2
@@ -36,11 +36,11 @@* SMB_COM_NT_CANCEL request and then sends it. */ static int -send_nt_cancel (struct TCP_Server_Info *server,void *buf, +send_nt_cancel (struct TCP_Server_Info *server,struct smb_rqst *rqst,struct mid_q_entry *mid) {int rc =0 ; -struct smb_hdr *in_buf = (struct smb_hdr *)buf; +struct smb_hdr *in_buf = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base;/* -4 for RFC1001 length and +2 for BCC field */ in_buf->smb_buf_length =cpu_to_be32 (sizeof (struct smb_hdr ) -4 +2 );
fs/cifs/transport.c +19 -14
@@ -595,10 +595,11 @@ cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server) }static inline int -send_cancel (struct TCP_Server_Info *server,void *buf,struct mid_q_entry *mid) +send_cancel (struct TCP_Server_Info *server,struct smb_rqst *rqst, +struct mid_q_entry *mid) {return server->ops->send_cancel ? - server->ops->send_cancel (server, buf, mid) :0 ; + server->ops->send_cancel (server, rqst, mid) :0 ; }int
@@ -718,7 +719,7 @@ SendReceive2(const unsigned int xid, struct cifs_ses *ses, rc =wait_for_response (ses->server, midQ);if (rc !=0 ) { -send_cancel (ses->server, buf, midQ); +send_cancel (ses->server, &rqst, midQ);spin_lock (&GlobalMid_Lock);if (midQ->mid_state ==MID_REQUEST_SUBMITTED ) { midQ->callback = DeleteMidQEntry;
@@ -771,6 +772,9 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, {int rc =0 ;struct mid_q_entry *midQ; +unsigned int len =be32_to_cpu (in_buf->smb_buf_length); +struct kvec iov = { .iov_base = in_buf, .iov_len = len }; +struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec =1 };if (ses ==NULL ) {cifs_dbg (VFS ,"Null smb session\n" );
@@ -788,10 +792,9 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses,to the same server. We may make this configurable later or use ses->maxReq */ -if (be32_to_cpu (in_buf->smb_buf_length) > CIFSMaxBufSize + -MAX_CIFS_HDR_SIZE -4 ) { +if (len > CIFSMaxBufSize +MAX_CIFS_HDR_SIZE -4 ) {cifs_dbg (VFS ,"Illegal length, greater than maximum frame, %d\n" , -be32_to_cpu (in_buf->smb_buf_length)); + len);return -EIO ; }
@@ -822,7 +825,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, midQ->mid_state =MID_REQUEST_SUBMITTED ;cifs_in_send_inc (ses->server); - rc =smb_send (ses->server, in_buf,be32_to_cpu (in_buf->smb_buf_length)); + rc =smb_send (ses->server, in_buf, len);cifs_in_send_dec (ses->server);cifs_save_when_sent (midQ);
@@ -839,7 +842,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, rc =wait_for_response (ses->server, midQ);if (rc !=0 ) { -send_cancel (ses->server, in_buf, midQ); +send_cancel (ses->server, &rqst, midQ);spin_lock (&GlobalMid_Lock);if (midQ->mid_state ==MID_REQUEST_SUBMITTED ) {/* no longer considered to be "in-flight" */
@@ -908,6 +911,9 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,int rstart =0 ;struct mid_q_entry *midQ;struct cifs_ses *ses; +unsigned int len =be32_to_cpu (in_buf->smb_buf_length); +struct kvec iov = { .iov_base = in_buf, .iov_len = len }; +struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec =1 };if (tcon ==NULL || tcon->ses ==NULL ) {cifs_dbg (VFS ,"Null smb session\n" );
@@ -927,10 +933,9 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,to the same server. We may make this configurable later or use ses->maxReq */ -if (be32_to_cpu (in_buf->smb_buf_length) > CIFSMaxBufSize + -MAX_CIFS_HDR_SIZE -4 ) { +if (len > CIFSMaxBufSize +MAX_CIFS_HDR_SIZE -4 ) {cifs_dbg (VFS ,"Illegal length, greater than maximum frame, %d\n" , -be32_to_cpu (in_buf->smb_buf_length)); + len);return -EIO ; }
@@ -959,7 +964,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, midQ->mid_state =MID_REQUEST_SUBMITTED ;cifs_in_send_inc (ses->server); - rc =smb_send (ses->server, in_buf,be32_to_cpu (in_buf->smb_buf_length)); + rc =smb_send (ses->server, in_buf, len);cifs_in_send_dec (ses->server);cifs_save_when_sent (midQ);
@@ -988,7 +993,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon,if (in_buf->Command ==SMB_COM_TRANSACTION2 ) {/* POSIX lock. We send a NT_CANCEL SMB to cause the blocking lock to return. */ - rc =send_cancel (ses->server, in_buf, midQ); + rc =send_cancel (ses->server, &rqst, midQ);if (rc) {cifs_delete_mid (midQ);return rc;
@@ -1009,7 +1014,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, rc =wait_for_response (ses->server, midQ);if (rc) { -send_cancel (ses->server, in_buf, midQ); +send_cancel (ses->server, &rqst, midQ);spin_lock (&GlobalMid_Lock);if (midQ->mid_state ==MID_REQUEST_SUBMITTED ) {/* no longer considered to be "in-flight" */
Signature · 1 line
2.7.4
PATCH v2 4/15 CIFS: Send RFC1001 length in a separate iov
In reply to a message not in the archiveIn order to simplify further encryption support we need to separate RFC1001 length and SMB2 header when sending a request. Put the length field in iov[0] and the rest of the packet into following iovs.
--- fs/cifs/cifsencrypt.c | 38 +++++++++++++--------- fs/cifs/cifsglob.h | 2 +- fs/cifs/cifssmb.c | 51 +++++++++++++++++------------ fs/cifs/smb2pdu.c | 64 ++++++++++++++++++++++-------------- fs/cifs/smb2transport.c | 28 +++++++++------- fs/cifs/transport.c | 86 +++++++++++++++++++++++++++++++++++++------------ 6 files changed, 174 insertions(+), 95 deletions(-)
fs/cifs/cifsencrypt.c +22 -16
@@ -75,24 +75,20 @@ int __cifs_calc_signature(struct smb_rqst *rqst,struct kvec *iov = rqst->rq_iov;int n_vec = rqst->rq_nvec; -for (i =0 ; i < n_vec; i++) { +if (n_vec <2 || iov[0 ].iov_len !=4 ) +return -EIO ; + +for (i =1 ; i < n_vec; i++) {if (iov[i].iov_len ==0 )continue ;if (iov[i].iov_base ==NULL ) {cifs_dbg (VFS ,"null iovec entry\n" );return -EIO ; } -/* The first entry includes a length field (which does not get -signed that occupies the first 4 bytes before the header */ -if (i ==0 ) { -if (iov[0 ].iov_len <=8 )/* cmd field at offset 9 */ -break ;/* nothing to sign or corrupt header */ - rc =crypto_shash_update (shash, - iov[i].iov_base +4 , iov[i].iov_len -4 ); - }else { - rc =crypto_shash_update (shash, - iov[i].iov_base, iov[i].iov_len); - } +if (i ==1 && iov[1 ].iov_len <=4 ) +break ;/* nothing to sign or corrupt header */ + rc =crypto_shash_update (shash, + iov[i].iov_base, iov[i].iov_len);if (rc) {cifs_dbg (VFS ,"%s: Could not update with payload\n" , __func__);
@@ -168,6 +164,10 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,char smb_signature[20 ];struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; +if (rqst->rq_iov[0 ].iov_len !=4 || + rqst->rq_iov[0 ].iov_base +4 != rqst->rq_iov[1 ].iov_base) +return -EIO ; +if ((cifs_pdu ==NULL ) || (server ==NULL ))return -EINVAL ;
@@ -209,12 +209,14 @@ int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,int cifs_sign_smb (struct smb_hdr *cifs_pdu,struct TCP_Server_Info *server,__u32 *pexpected_response_sequence_number) { -struct kvec iov; +struct kvec iov[2 ]; - iov.iov_base = cifs_pdu; - iov.iov_len =be32_to_cpu (cifs_pdu->smb_buf_length) +4 ; + iov[0 ].iov_base = cifs_pdu; + iov[0 ].iov_len =4 ; + iov[1 ].iov_base = (char *)cifs_pdu +4 ; + iov[1 ].iov_len =be32_to_cpu (cifs_pdu->smb_buf_length); -return cifs_sign_smbv (&iov,1 , server, +return cifs_sign_smbv (iov,2 , server, pexpected_response_sequence_number); }
@@ -227,6 +229,10 @@ int cifs_verify_signature(struct smb_rqst *rqst,char what_we_think_sig_should_be[20 ];struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0 ].iov_base; +if (rqst->rq_iov[0 ].iov_len !=4 || + rqst->rq_iov[0 ].iov_base +4 != rqst->rq_iov[1 ].iov_base) +return -EIO ; +if (cifs_pdu ==NULL || server ==NULL )return -EINVAL ;
fs/cifs/cifsglob.h +1 -1
@@ -1117,7 +1117,7 @@ struct cifs_readdata {int (*read_into_pages)(struct TCP_Server_Info *server,struct cifs_readdata *rdata,unsigned int len); -struct kvec iov; +struct kvec iov[2 ];unsigned int pagesz;unsigned int tailsz;unsigned int credits;
fs/cifs/cifssmb.c +30 -21
106 lines not on this page · raw message
fs/cifs/smb2pdu.c +39 -25
148 lines not on this page · raw message
fs/cifs/smb2transport.c +17 -11
@@ -138,7 +138,7 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)unsigned char smb2_signature[SMB2_HMACSHA256_SIZE ];unsigned char *sigptr = smb2_signature;struct kvec *iov = rqst->rq_iov; -struct smb2_sync_hdr *shdr =get_sync_hdr (iov[0 ].iov_base); +struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)iov[1 ].iov_base;struct cifs_ses *ses; ses =smb2_find_smb_ses (shdr, server);
@@ -355,7 +355,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)unsigned char smb3_signature[SMB2_CMACAES_SIZE ];unsigned char *sigptr = smb3_signature;struct kvec *iov = rqst->rq_iov; -struct smb2_sync_hdr *shdr =get_sync_hdr (iov[0 ].iov_base); +struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)iov[1 ].iov_base;struct cifs_ses *ses; ses =smb2_find_smb_ses (shdr, server);
@@ -400,7 +400,8 @@ static int smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) { int rc = 0; -struct smb2_sync_hdr *shdr =get_sync_hdr (rqst->rq_iov[0 ].iov_base); +struct smb2_sync_hdr *shdr = + (struct smb2_sync_hdr *)rqst->rq_iov[1 ].iov_base;if (!(shdr->Flags &SMB2_FLAGS_SIGNED ) || server->tcpStatus == CifsNeedNegotiate)
@@ -421,7 +422,8 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) {unsigned int rc;char server_response_sig[16 ]; -struct smb2_sync_hdr *shdr =get_sync_hdr (rqst->rq_iov[0 ].iov_base); +struct smb2_sync_hdr *shdr = + (struct smb2_sync_hdr *)rqst->rq_iov[1 ].iov_base; if ((shdr->Command == SMB2_NEGOTIATE) || (shdr->Command == SMB2_SESSION_SETUP) ||
@@ -550,12 +552,14 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, bool log_error) {unsigned int len =get_rfc1002_length (mid->resp_buf); -struct kvec iov; -struct smb_rqst rqst = { .rq_iov = &iov, - .rq_nvec =1 }; +struct kvec iov[2 ]; +struct smb_rqst rqst = { .rq_iov = iov, + .rq_nvec =2 }; - iov.iov_base = (char *)mid->resp_buf; - iov.iov_len =get_rfc1002_length (mid->resp_buf) +4 ; + iov[0 ].iov_base = (char *)mid->resp_buf; + iov[0 ].iov_len =4 ; + iov[1 ].iov_base = (char *)mid->resp_buf +4 ; + iov[1 ].iov_len = len;dump_smb (mid->resp_buf,min_t (u32,80 , len));/* convert the length into a more usable form */
@@ -575,7 +579,8 @@ struct mid_q_entry * smb2_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst) { int rc; -struct smb2_sync_hdr *shdr =get_sync_hdr (rqst->rq_iov[0 ].iov_base); +struct smb2_sync_hdr *shdr = + (struct smb2_sync_hdr *)rqst->rq_iov[1 ].iov_base;struct mid_q_entry *mid;smb2_seq_num_into_buf (ses->server, shdr);
@@ -595,7 +600,8 @@ struct mid_q_entry * smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst) { int rc; -struct smb2_sync_hdr *shdr =get_sync_hdr (rqst->rq_iov[0 ].iov_base); +struct smb2_sync_hdr *shdr = + (struct smb2_sync_hdr *)rqst->rq_iov[1 ].iov_base;struct mid_q_entry *mid;smb2_seq_num_into_buf (server, shdr);
fs/cifs/transport.c +65 -21
163 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 5/15 CIFS: Separate SMB2 sync header processing
In reply to a message not in the archiveDo not process RFC1001 length in smb2_hdr_assemble() because it is not a part of SMB2 header. This allows to cleanup the code and adds a possibility combine several SMB2 packets into one for compounding.
--- fs/cifs/smb2pdu.c | 50 ++++++++++++++++++++++++++++++-------------------- fs/cifs/smb2pdu.h | 5 +++++ 2 files changed, 35 insertions(+), 20 deletions(-)
fs/cifs/smb2pdu.c +30 -20
@@ -79,25 +79,9 @@ static const int smb2_req_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = {static void -smb2_hdr_assemble (struct smb2_hdr *hdr,__le16 smb2_cmd/* command */ , +smb2_hdr_assemble (struct smb2_sync_hdr *shdr,__le16 smb2_cmd,const struct cifs_tcon *tcon) { -struct smb2_pdu *pdu = (struct smb2_pdu *)hdr; -struct smb2_sync_hdr *shdr =get_sync_hdr (hdr); -char *temp = (char *)hdr; -/* lookup word count ie StructureSize from table */ -__u16 parmsize = smb2_req_struct_sizes[le16_to_cpu (smb2_cmd)]; - -/* -* smaller than SMALL_BUFFER_SIZE but bigger than fixed area of -* largest operations (Create) -*/ -memset (temp,0 ,256 ); - -/* Note this is only network field converted to big endian */ - hdr->smb2_buf_length = -cpu_to_be32 (parmsize +sizeof (struct smb2_sync_hdr )); - shdr->ProtocolId =SMB2_PROTO_NUMBER ; shdr->StructureSize =cpu_to_le16 (64 ); shdr->Command = smb2_cmd;
@@ -149,7 +133,6 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,if (tcon->ses && tcon->ses->server && tcon->ses->server->sign) shdr->Flags |=SMB2_FLAGS_SIGNED ; out: - pdu->StructureSize2 =cpu_to_le16 (parmsize);return ; }
@@ -290,6 +273,26 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon)return rc; } +static void +fill_small_buf (__le16 smb2_command,struct cifs_tcon *tcon,void *buf, +unsigned int *total_len) +{ +struct smb2_sync_pdu *spdu = (struct smb2_sync_pdu *)buf; +/* lookup word count ie StructureSize from table */ +__u16 parmsize = smb2_req_struct_sizes[le16_to_cpu (smb2_command)]; + +/* +* smaller than SMALL_BUFFER_SIZE but bigger than fixed area of +* largest operations (Create) +*/ +memset (buf,0 ,256 ); + +smb2_hdr_assemble (&spdu->sync_hdr, smb2_command, tcon); + spdu->StructureSize2 =cpu_to_le16 (parmsize); + + *total_len = parmsize +sizeof (struct smb2_sync_hdr ); +} +/* * Allocate and return pointer to an SMB request hdr, and set basic * SMB information in the SMB header. If the return code is zero, this
@@ -299,7 +302,9 @@ static int small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon, void **request_buf) { - int rc = 0; + int rc; +unsigned int total_len; +struct smb2_pdu *pdu; rc =smb2_reconnect (smb2_command, tcon);if (rc)
@@ -312,7 +317,12 @@ small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon,return -ENOMEM ; } -smb2_hdr_assemble ((struct smb2_hdr *) *request_buf, smb2_command, tcon); + pdu = (struct smb2_pdu *)(*request_buf); + +fill_small_buf (smb2_command, tcon,get_sync_hdr (pdu), &total_len); + +/* Note this is only network field converted to big endian */ + pdu->hdr.smb2_buf_length =cpu_to_be32 (total_len);if (tcon !=NULL ) {#ifdef CONFIG_CIFS_STATS2
fs/cifs/smb2pdu.h +5 -0
@@ -117,6 +117,11 @@ struct smb2_sync_hdr {__u8 Signature[16 ]; } __packed; +struct smb2_sync_pdu { +struct smb2_sync_hdr sync_hdr; +__le16 StructureSize2;/* size of wct area (varies, request specific) */ +} __packed; +struct smb2_hdr {__be32 smb2_buf_length;/* big endian on wire */ /* length is only two or three bytes - with */
Signature · 1 line
2.7.4
PATCH v2 6/15 CIFS: Separate RFC1001 length processing for SMB2 read
In reply to a message not in the archiveAllocate and initialize SMB2 read request without RFC1001 length field to directly call cifs_send_recv() rather than SendReceive2() in a read codepath.
--- fs/cifs/cifsproto.h | 3 ++ fs/cifs/smb2pdu.c | 89 ++++++++++++++++++++++++++++++++++++++++------------- fs/cifs/smb2pdu.h | 5 +-- fs/cifs/transport.c | 2 +- 4 files changed, 74 insertions(+), 25 deletions(-)
fs/cifs/cifsproto.h +3 -0
@@ -78,6 +78,9 @@ extern int cifs_call_async(struct TCP_Server_Info *server,struct smb_rqst *rqst, mid_receive_t *receive, mid_callback_t *callback, void *cbdata, const int flags); +extern int cifs_send_recv (const unsigned int xid,struct cifs_ses *ses, +struct smb_rqst *rqst,int *resp_buf_type, +const int flags,struct kvec *resp_iov); extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *, struct smb_hdr * /* input */ , struct smb_hdr * /* out */ ,
fs/cifs/smb2pdu.c +67 -22
152 lines not on this page · raw message
fs/cifs/smb2pdu.h +3 -2
@@ -823,8 +823,9 @@ struct smb2_flush_rsp {#define SMB2_CHANNEL_RDMA_V1 0x00000001/* SMB3 or later */ #define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000001/* SMB3.02 or later */ -struct smb2_read_req { -struct smb2_hdr hdr; +/* SMB2 read request without RFC1001 length at the beginning */ +struct smb2_read_plain_req { +struct smb2_sync_hdr sync_hdr;__le16 StructureSize;/* Must be 49 */ __u8 Padding;/* offset from start of SMB2 header to place read */ __u8 Flags;/* MBZ unless SMB3.02 or later */
fs/cifs/transport.c +1 -1
@@ -665,7 +665,7 @@ cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)return mid; } -static int +int cifs_send_recv (const unsigned int xid,struct cifs_ses *ses,struct smb_rqst *rqst,int *resp_buf_type,const int flags,struct kvec *resp_iov)
Signature · 1 line
2.7.4
PATCH v2 7/15 CIFS: Add capability to transform requests before sending
In reply to a message not in the archiveThis will allow us to do protocol specific tranformations of packets before sending to the server. For SMB3 it can be used to support encryption.
--- fs/cifs/cifsglob.h | 7 +++ fs/cifs/smb2pdu.c | 129 ++++++++++++++++++++++++++++++++++++++++++---------- fs/cifs/transport.c | 33 ++++++++++---- 3 files changed, 136 insertions(+), 33 deletions(-)
fs/cifs/cifsglob.h +7 -0
@@ -433,6 +433,11 @@ struct smb_version_operations {bool (*dir_needs_close)(struct cifsFileInfo *);long (*fallocate)(struct file *,struct cifs_tcon *,int ,loff_t ,loff_t ); +/* init transform request - used for encryption for now */ +int (*init_transform_rq)(struct TCP_Server_Info *,struct smb_rqst *, +struct smb_rqst *); +/* free transform request */ +void (*free_transform_rq)(struct smb_rqst *); };struct smb_version_values {
@@ -1473,7 +1478,9 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,#define CIFS_OBREAK_OP 0x0100/* oplock break request */ #define CIFS_NEG_OP 0x0200/* negotiate request */ #define CIFS_OP_MASK 0x0380/* mask request type */ +#define CIFS_HAS_CREDITS 0x0400/* already has credits */ +#define CIFS_TRANSFORM_REQ 0x0800/* transform request before sending */ /* Security Flags: indicate type of session setup needed */ #define CIFSSEC_MAY_SIGN 0x00001
fs/cifs/smb2pdu.c +104 -25
454 lines not on this page · raw message
fs/cifs/transport.c +25 -8
@@ -220,7 +220,7 @@ rqst_len(struct smb_rqst *rqst) }static int -smb_send_rqst (struct TCP_Server_Info *server,struct smb_rqst *rqst) +__smb_send_rqst (struct TCP_Server_Info *server,struct smb_rqst *rqst) {int rc;struct kvec *iov = rqst->rq_iov;
@@ -312,12 +312,27 @@ smb_send_rqst(struct TCP_Server_Info *server, struct smb_rqst *rqst) }static int -smb_sendv (struct TCP_Server_Info *server,struct kvec *iov,int n_vec) +smb_send_rqst (struct TCP_Server_Info *server,struct smb_rqst *rqst,int flags) { -struct smb_rqst rqst = { .rq_iov = iov, - .rq_nvec = n_vec }; +struct smb_rqst cur_rqst; +int rc; + +if (!(flags &CIFS_TRANSFORM_REQ )) +return __smb_send_rqst (server, rqst); + +if (!server->ops->init_transform_rq || + !server->ops->free_transform_rq) { +cifs_dbg (VFS ,"Encryption requested but transform callbacks are missed\n" ); +return -EIO ; + } -return smb_send_rqst (server, &rqst); + rc = server->ops->init_transform_rq (server, &cur_rqst, rqst); +if (rc) +return rc; + + rc =__smb_send_rqst (server, &cur_rqst); + server->ops->free_transform_rq (&cur_rqst); +return rc; }int
@@ -325,13 +340,15 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, unsigned int smb_buf_length) {struct kvec iov[2 ]; +struct smb_rqst rqst = { .rq_iov = iov, + .rq_nvec =2 }; iov[0 ].iov_base = smb_buffer; iov[0 ].iov_len =4 ; iov[1 ].iov_base = (char *)smb_buffer +4 ; iov[1 ].iov_len = smb_buf_length; -return smb_sendv (server, iov,2 ); +return __smb_send_rqst (server, &rqst); } static int
@@ -523,7 +540,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,cifs_in_send_inc (server); - rc =smb_send_rqst (server, rqst); + rc =smb_send_rqst (server, rqst, flags);cifs_in_send_dec (server);cifs_save_when_sent (mid);
@@ -717,7 +734,7 @@ cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, midQ->mid_state =MID_REQUEST_SUBMITTED ;cifs_in_send_inc (ses->server); - rc =smb_send_rqst (ses->server, rqst); + rc =smb_send_rqst (ses->server, rqst, flags);cifs_in_send_dec (ses->server);cifs_save_when_sent (midQ);
Signature · 1 line
2.7.4
PATCH v2 8/15 CIFS: Enable encryption during session setup phase
In reply to a message not in the archiveIn order to allow encryption on SMB connection we need to exchange a session key and generate encryption and decryption keys.
--- fs/cifs/sess.c | 22 ++++++++++------------ fs/cifs/smb2pdu.c | 12 ++---------- 2 files changed, 12 insertions(+), 22 deletions(-)
fs/cifs/sess.c +10 -12
@@ -344,13 +344,12 @@ void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,/* BB is NTLMV2 session security format easier to use here? */ flags =NTLMSSP_NEGOTIATE_56 |NTLMSSP_REQUEST_TARGET |NTLMSSP_NEGOTIATE_128 |NTLMSSP_NEGOTIATE_UNICODE | -NTLMSSP_NEGOTIATE_NTLM |NTLMSSP_NEGOTIATE_EXTENDED_SEC ; -if (ses->server->sign) { +NTLMSSP_NEGOTIATE_NTLM |NTLMSSP_NEGOTIATE_EXTENDED_SEC | +NTLMSSP_NEGOTIATE_SEAL ; +if (ses->server->sign) flags |=NTLMSSP_NEGOTIATE_SIGN ; -if (!ses->server->session_estab || - ses->ntlmssp->sesskey_per_smbsess) - flags |=NTLMSSP_NEGOTIATE_KEY_XCH ; - } +if (!ses->server->session_estab || ses->ntlmssp->sesskey_per_smbsess) + flags |=NTLMSSP_NEGOTIATE_KEY_XCH ; sec_blob->NegotiateFlags =cpu_to_le32 (flags);
@@ -407,13 +406,12 @@ int build_ntlmssp_auth_blob(unsigned char **pbuffer, flags =NTLMSSP_NEGOTIATE_56 |NTLMSSP_REQUEST_TARGET |NTLMSSP_NEGOTIATE_TARGET_INFO |NTLMSSP_NEGOTIATE_128 |NTLMSSP_NEGOTIATE_UNICODE | -NTLMSSP_NEGOTIATE_NTLM |NTLMSSP_NEGOTIATE_EXTENDED_SEC ; -if (ses->server->sign) { +NTLMSSP_NEGOTIATE_NTLM |NTLMSSP_NEGOTIATE_EXTENDED_SEC | +NTLMSSP_NEGOTIATE_SEAL ; +if (ses->server->sign) flags |=NTLMSSP_NEGOTIATE_SIGN ; -if (!ses->server->session_estab || - ses->ntlmssp->sesskey_per_smbsess) - flags |=NTLMSSP_NEGOTIATE_KEY_XCH ; - } +if (!ses->server->session_estab || ses->ntlmssp->sesskey_per_smbsess) + flags |=NTLMSSP_NEGOTIATE_KEY_XCH ; tmp = *pbuffer +sizeof (AUTHENTICATE_MESSAGE ); sec_blob->NegotiateFlags =cpu_to_le32 (flags);
fs/cifs/smb2pdu.c +2 -10
@@ -756,15 +756,13 @@ SMB2_sess_establish_session(struct SMB2_sess_data *sess_data)struct cifs_ses *ses = sess_data->ses;mutex_lock (&ses->server->srv_mutex); -if (ses->server->sign && ses->server->ops->generate_signingkey) { +if (ses->server->ops->generate_signingkey) { rc = ses->server->ops->generate_signingkey (ses); -kfree (ses->auth_key.response); - ses->auth_key.response =NULL ;if (rc) {cifs_dbg (FYI ,"SMB3 session key generation failed\n" );mutex_unlock (&ses->server->srv_mutex); - goto keygen_exit; +return rc; } }if (!ses->server->session_estab) {
@@ -778,12 +776,6 @@ SMB2_sess_establish_session(struct SMB2_sess_data *sess_data) ses->status = CifsGood; ses->need_reconnect = false;spin_unlock (&GlobalMid_Lock); - -keygen_exit: -if (!ses->server->sign) { -kfree (ses->auth_key.response); - ses->auth_key.response =NULL ; - }return rc; }
Signature · 1 line
2.7.4
PATCH v2 9/15 CIFS: Encrypt SMB3 requests before sending
In reply to a message not in the archiveThis change allows to encrypt packets if it is required by a server for SMB sessions or tree connections.
--- fs/cifs/Kconfig | 2 + fs/cifs/cifsencrypt.c | 13 ++- fs/cifs/cifsfs.c | 2 + fs/cifs/cifsglob.h | 2 + fs/cifs/cifsproto.h | 2 +- fs/cifs/connect.c | 4 +- fs/cifs/smb2ops.c | 257 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/smb2pdu.h | 5 +- fs/cifs/smb2proto.h | 3 + fs/cifs/smb2transport.c | 41 +++++++- 10 files changed, 321 insertions(+), 10 deletions(-)
fs/cifs/Kconfig +2 -0
@@ -174,6 +174,8 @@ config CIFS_SMB2 select CRYPTO_AES select CRYPTO_SHA256 select CRYPTO_CMAC + select CRYPTO_AEAD2 + select CRYPTO_CCM help This enables support for the Server Message Block version 2
fs/cifs/cifsencrypt.c +12 -1
@@ -34,6 +34,7 @@#include <linux/random.h> #include <linux/highmem.h> #include <crypto/skcipher.h> +#include <crypto/aead.h> static int cifs_crypto_shash_md5_allocate (struct TCP_Server_Info *server)
@@ -870,7 +871,7 @@ calc_seckey(struct cifs_ses *ses) }void -cifs_crypto_shash_release (struct TCP_Server_Info *server) +cifs_crypto_secmech_release (struct TCP_Server_Info *server) {if (server->secmech.cmacaes) {crypto_free_shash (server->secmech.cmacaes);
@@ -892,6 +893,16 @@ cifs_crypto_shash_release(struct TCP_Server_Info *server) server->secmech.hmacmd5 =NULL ; } +if (server->secmech.ccmaesencrypt) { +crypto_free_aead (server->secmech.ccmaesencrypt); + server->secmech.ccmaesencrypt =NULL ; + } + +if (server->secmech.ccmaesdecrypt) { +crypto_free_aead (server->secmech.ccmaesdecrypt); + server->secmech.ccmaesdecrypt =NULL ; + } +kfree (server->secmech.sdesccmacaes); server->secmech.sdesccmacaes =NULL ;kfree (server->secmech.sdeschmacsha256);
fs/cifs/cifsfs.c +2 -0
@@ -1377,6 +1377,8 @@ MODULE_SOFTDEP("pre: nls");MODULE_SOFTDEP ("pre: aes" );MODULE_SOFTDEP ("pre: cmac" );MODULE_SOFTDEP ("pre: sha256" ); +MODULE_SOFTDEP ("pre: aead2" ); +MODULE_SOFTDEP ("pre: ccm" );#endif /* CONFIG_CIFS_SMB2 */ module_init (init_cifs)module_exit (exit_cifs)
fs/cifs/cifsglob.h +2 -0
@@ -136,6 +136,8 @@ struct cifs_secmech {struct sdesc *sdescmd5;/* ctxt to generate cifs/smb signature */ struct sdesc *sdeschmacsha256;/* ctxt to generate smb2 signature */ struct sdesc *sdesccmacaes;/* ctxt to generate smb3 signature */ +struct crypto_aead *ccmaesencrypt;/* smb3 encryption aead */ +struct crypto_aead *ccmaesdecrypt;/* smb3 decryption aead */ };/* per smb session structure/fields */
fs/cifs/cifsproto.h +1 -1
@@ -444,7 +444,7 @@ extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *, const struct nls_table *);extern int setup_ntlm_response (struct cifs_ses *,const struct nls_table *);extern int setup_ntlmv2_rsp (struct cifs_ses *,const struct nls_table *); -extern void cifs_crypto_shash_release (struct TCP_Server_Info *); +extern void cifs_crypto_secmech_release (struct TCP_Server_Info *server);extern int calc_seckey (struct cifs_ses *);extern int generate_smb30signingkey (struct cifs_ses *);extern int generate_smb311signingkey (struct cifs_ses *);
fs/cifs/connect.c +2 -2
@@ -2148,7 +2148,7 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect) server->tcpStatus = CifsExiting;spin_unlock (&GlobalMid_Lock); -cifs_crypto_shash_release (server); +cifs_crypto_secmech_release (server);cifs_fscache_release_client_cookie (server);kfree (server->session_key.response);
@@ -2267,7 +2267,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)return tcp_ses; out_err_crypto_release: -cifs_crypto_shash_release (tcp_ses); +cifs_crypto_secmech_release (tcp_ses);put_net (cifs_net_ns (tcp_ses));
fs/cifs/smb2ops.c +257 -0
281 lines not on this page · raw message
fs/cifs/smb2pdu.h +4 -1
@@ -134,11 +134,14 @@ struct smb2_pdu {__le16 StructureSize2;/* size of wct area (varies, request specific) */ } __packed; +#define SMB3_AES128CMM_NONCE 11 +#define SMB3_AES128GCM_NONCE 12 +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 */ -__u8 ProtocolId[4 ];/* 0xFD 'S' 'M' 'B' */ +__le32 ProtocolId;/* 0xFD 'S' 'M' 'B' */ __u8 Signature[16 ];__u8 Nonce[16 ];__le32 OriginalMessageSize;
fs/cifs/smb2proto.h +3 -0
@@ -56,6 +56,8 @@ extern void smb2_echo_request(struct work_struct *work);extern __le32 smb2_get_lease_state (struct cifsInodeInfo *cinode);extern bool smb2_is_valid_oplock_break (char *buffer,struct TCP_Server_Info *srv); +extern struct cifs_ses *smb2_find_smb_ses (struct TCP_Server_Info *server, +__u64 ses_id);extern void move_smb2_info_to_cifs (FILE_ALL_INFO *dst,struct smb2_file_all_info *src);
@@ -97,6 +99,7 @@ extern int smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, const unsigned int xid);extern int smb2_push_mandatory_locks (struct cifsFileInfo *cfile);extern void smb2_reconnect_server (struct work_struct *work); +extern int smb3_crypto_aead_allocate (struct TCP_Server_Info *server);/* * SMB2 Worker functions - most of protocol specific implementation details
fs/cifs/smb2transport.c +36 -5
73 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 10/15 CIFS: Add transform header handling callbacks
In reply to a message not in the archiveWe need to recognize and parse transformed packets in demultiplex thread to find a corresponsing mid and process it further.
--- fs/cifs/cifsglob.h | 3 +++ fs/cifs/connect.c | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-)
fs/cifs/cifsglob.h +3 -0
@@ -440,6 +440,9 @@ struct smb_version_operations { struct smb_rqst *);/* free transform request */ void (*free_transform_rq)(struct smb_rqst *); +int (*is_transform_hdr)(void *buf); +int (*receive_transform)(struct TCP_Server_Info *, +struct mid_q_entry **); };struct smb_version_values {
fs/cifs/connect.c +12 -5
@@ -869,12 +869,19 @@ cifs_demultiplex_thread(void *p)continue ; server->total_read += length; - mid_entry = server->ops->find_mid (server, buf); +if (server->ops->is_transform_hdr && + server->ops->receive_transform && + server->ops->is_transform_hdr (buf)) { + length = server->ops->receive_transform (server, + &mid_entry); + }else { + mid_entry = server->ops->find_mid (server, buf); -if (!mid_entry || !mid_entry->receive) - length =standard_receive3 (server, mid_entry); -else - length = mid_entry->receive (server, mid_entry); +if (!mid_entry || !mid_entry->receive) + length =standard_receive3 (server, mid_entry); +else + length = mid_entry->receive (server, mid_entry); + }if (length <0 )continue ;
Signature · 1 line
2.7.4
PATCH v2 11/15 CIFS: Add mid handle callback
In reply to a message not in the archiveWe need to process read responses differently because the data should go directly into preallocated pages. This can be done by specifying a mid handle callback.
--- fs/cifs/cifsglob.h | 8 ++++++++ fs/cifs/cifsproto.h | 2 +- fs/cifs/cifssmb.c | 6 +++--- fs/cifs/smb2pdu.c | 10 +++++----- fs/cifs/transport.c | 5 +++-- 5 files changed, 20 insertions(+), 11 deletions(-)
fs/cifs/cifsglob.h +8 -0
@@ -1310,6 +1310,13 @@ typedef int (mid_receive_t)(struct TCP_Server_Info *server,*/ typedef void (mid_callback_t )(struct mid_q_entry *mid); +/* +* This is the protopyte for mid handle function. This is called once the mid +* has been recognized after decryption of the message. +*/ +typedef int (mid_handle_t )(struct TCP_Server_Info *server, +struct mid_q_entry *mid); +/* one of these for every pending CIFS request to the server */ struct mid_q_entry {struct list_head qhead;/* mids waiting on reply from this server */
@@ -1324,6 +1331,7 @@ struct mid_q_entry {#endif mid_receive_t *receive;/* call receive callback */ mid_callback_t *callback;/* call completion callback */ +mid_handle_t *handle;/* call handle mid callback */ void *callback_data;/* general purpose pointer for callback */ void *resp_buf;/* pointer to received SMB header */ int mid_state;/* wish this were enum but can not pass to wait_event */
fs/cifs/cifsproto.h +1 -1
@@ -77,7 +77,7 @@ extern void cifs_wake_up_task(struct mid_q_entry *mid);extern int cifs_call_async (struct TCP_Server_Info *server,struct smb_rqst *rqst,mid_receive_t *receive,mid_callback_t *callback, -void *cbdata,const int flags); +mid_handle_t *handle,void *cbdata,const int flags);extern int cifs_send_recv (const unsigned int xid,struct cifs_ses *ses,struct smb_rqst *rqst,int *resp_buf_type,const int flags,struct kvec *resp_iov);
fs/cifs/cifssmb.c +3 -3
@@ -731,7 +731,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server) iov[1 ].iov_len =get_rfc1002_length (smb); iov[1 ].iov_base = (char *)smb +4 ; - rc =cifs_call_async (server, &rqst,NULL , cifs_echo_callback, + rc =cifs_call_async (server, &rqst,NULL , cifs_echo_callback,NULL , server,CIFS_ASYNC_OP |CIFS_ECHO_OP );if (rc)cifs_dbg (FYI ,"Echo request failed: %d\n" , rc);
@@ -1654,7 +1654,7 @@ cifs_async_readv(struct cifs_readdata *rdata)kref_get (&rdata->refcount); rc =cifs_call_async (tcon->ses->server, &rqst, cifs_readv_receive, - cifs_readv_callback, rdata,0 ); + cifs_readv_callback,NULL , rdata,0 );if (rc ==0 )cifs_stats_inc (&tcon->stats.cifs_stats.num_reads);
@@ -2168,7 +2168,7 @@ cifs_async_writev(struct cifs_writedata *wdata,kref_get (&wdata->refcount); rc =cifs_call_async (tcon->ses->server, &rqst,NULL , - cifs_writev_callback, wdata,0 ); + cifs_writev_callback,NULL , wdata,0 );if (rc ==0 )cifs_stats_inc (&tcon->stats.cifs_stats.num_writes);
fs/cifs/smb2pdu.c +5 -5
@@ -2144,8 +2144,8 @@ SMB2_echo(struct TCP_Server_Info *server) iov[1 ].iov_len =get_rfc1002_length (req); iov[1 ].iov_base = (char *)req +4 ; - rc =cifs_call_async (server, &rqst,NULL , smb2_echo_callback, server, -CIFS_ECHO_OP ); + rc =cifs_call_async (server, &rqst,NULL , smb2_echo_callback,NULL , + server,CIFS_ECHO_OP );if (rc)cifs_dbg (FYI ,"Echo request failed: %d\n" , rc);
@@ -2384,7 +2384,7 @@ smb2_async_readv(struct cifs_readdata *rdata)kref_get (&rdata->refcount); rc =cifs_call_async (io_parms.tcon->ses->server, &rqst, cifs_readv_receive, smb2_readv_callback, - rdata, flags); +NULL , rdata, flags);if (rc) {kref_put (&rdata->refcount, cifs_readdata_release);cifs_stats_fail_inc (io_parms.tcon,SMB2_READ_HE );
@@ -2595,8 +2595,8 @@ smb2_async_writev(struct cifs_writedata *wdata, }kref_get (&wdata->refcount); - rc =cifs_call_async (server, &rqst,NULL , smb2_writev_callback, wdata, - flags); + rc =cifs_call_async (server, &rqst,NULL , smb2_writev_callback,NULL , + wdata, flags);if (rc) {kref_put (&wdata->refcount, release);
fs/cifs/transport.c +3 -2
@@ -503,8 +503,8 @@ cifs_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)*/ int cifs_call_async (struct TCP_Server_Info *server,struct smb_rqst *rqst, -mid_receive_t *receive,mid_callback_t *callback,void *cbdata, -const int flags) +mid_receive_t *receive,mid_callback_t *callback, +mid_handle_t *handle,void *cbdata,const int flags) {int rc, timeout, optype;struct mid_q_entry *mid;
@@ -531,6 +531,7 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, mid->receive = receive; mid->callback = callback; mid->callback_data = cbdata; + mid->handle = handle; mid->mid_state =MID_REQUEST_SUBMITTED ;/* put it on the pending_mid_q */
Signature · 1 line
2.7.4
PATCH v2 12/15 CIFS: Add copy into pages callback for a read operation
In reply to a message not in the archiveSince we have two different types of reads (pagecache and direct) we need to process such responses differently after decryption of a packet. The change allows to specify a callback that copies a read payload data into preallocated pages.
--- fs/cifs/cifsglob.h | 3 +++ fs/cifs/file.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 6 deletions(-)
fs/cifs/cifsglob.h +3 -0
@@ -1127,6 +1127,9 @@ struct cifs_readdata {int (*read_into_pages)(struct TCP_Server_Info *server,struct cifs_readdata *rdata,unsigned int len); +int (*copy_into_pages)(struct TCP_Server_Info *server, +struct cifs_readdata *rdata, +struct iov_iter *iter);struct kvec iov[2 ];unsigned int pagesz;unsigned int tailsz;
fs/cifs/file.c +46 -6
100 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 13/15 CIFS: Decrypt and process small encrypted packets
In reply to a message not in the archiveAllow to decrypt transformed packets, find a corresponding mid and process as usual further.
--- fs/cifs/cifsglob.h | 1 + fs/cifs/cifsproto.h | 2 + fs/cifs/connect.c | 9 ++ fs/cifs/smb2ops.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++- fs/cifs/smb2pdu.c | 4 +- fs/cifs/smb2proto.h | 2 + fs/cifs/smb2transport.c | 2 +- 7 files changed, 243 insertions(+), 4 deletions(-)
fs/cifs/cifsglob.h +1 -0
@@ -1342,6 +1342,7 @@ struct mid_q_entry { bool large_buf:1; /* if valid response, is pointer to large buf */ bool multiRsp:1; /* multiple trans2 responses for one request */ bool multiEnd:1; /* both received */ + bool decrypted:1; /* decrypted entry */ };/* Make code in transport.c a little cleaner by moving
fs/cifs/cifsproto.h +2 -0
@@ -74,6 +74,8 @@ extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer,extern void DeleteMidQEntry (struct mid_q_entry *midEntry);extern void cifs_delete_mid (struct mid_q_entry *mid);extern void cifs_wake_up_task (struct mid_q_entry *mid); +extern int cifs_handle_standard (struct TCP_Server_Info *server, +struct mid_q_entry *mid); extern int cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, mid_receive_t *receive, mid_callback_t *callback,
fs/cifs/connect.c +9 -0
@@ -784,6 +784,15 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)dump_smb (buf, server->total_read); +return cifs_handle_standard (server, mid); +} + +int +cifs_handle_standard (struct TCP_Server_Info *server,struct mid_q_entry *mid) +{ +char *buf = server->large_buf ? server->bigbuf : server->smallbuf; +int length; +/* * We know that we received enough to get to the MID as we * checked the pdu_length earlier. Now check to see
fs/cifs/smb2ops.c +226 -1
245 lines not on this page · raw message
fs/cifs/smb2pdu.c +2 -2
@@ -2281,7 +2281,7 @@ smb2_readv_callback(struct mid_q_entry *mid)case MID_RESPONSE_RECEIVED : credits_received =le16_to_cpu (shdr->CreditRequest);/* result already set, check signature */ -if (server->sign) { +if (server->sign && !mid->decrypted) {int rc; rc =smb2_verify_signature (&rqst, server);
@@ -2384,7 +2384,7 @@ smb2_async_readv(struct cifs_readdata *rdata)kref_get (&rdata->refcount); rc =cifs_call_async (io_parms.tcon->ses->server, &rqst, cifs_readv_receive, smb2_readv_callback, -NULL , rdata, flags); + smb3_handle_read_data, rdata, flags);if (rc) {kref_put (&rdata->refcount, cifs_readdata_release);cifs_stats_fail_inc (io_parms.tcon,SMB2_READ_HE );
fs/cifs/smb2proto.h +2 -0
@@ -58,6 +58,8 @@ extern bool smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv);extern struct cifs_ses *smb2_find_smb_ses (struct TCP_Server_Info *server,__u64 ses_id); +extern int smb3_handle_read_data (struct TCP_Server_Info *server, +struct mid_q_entry *mid);extern void move_smb2_info_to_cifs (FILE_ALL_INFO *dst,struct smb2_file_all_info *src);
fs/cifs/smb2transport.c +1 -1
@@ -564,7 +564,7 @@ smb2_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,dump_smb (mid->resp_buf,min_t (u32,80 , len));/* convert the length into a more usable form */ -if (len >24 && server->sign) { +if (len >24 && server->sign && !mid->decrypted) {int rc; rc =smb2_verify_signature (&rqst, server);
Signature · 1 line
2.7.4
PATCH v2 14/15 CIFS: Add capability to decrypt big read responses
In reply to a message not in the archiveAllow to decrypt transformed packets that are bigger than the big buffer size. In particular it is used for read responses that can only exceed the big buffer size.
--- fs/cifs/cifsproto.h | 1 + fs/cifs/cifssmb.c | 8 +-- fs/cifs/smb2ops.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 169 insertions(+), 13 deletions(-)
fs/cifs/cifsproto.h +1 -0
@@ -76,6 +76,7 @@ extern void cifs_delete_mid(struct mid_q_entry *mid);extern void cifs_wake_up_task (struct mid_q_entry *mid);extern int cifs_handle_standard (struct TCP_Server_Info *server,struct mid_q_entry *mid); +extern int cifs_discard_remaining_data (struct TCP_Server_Info *server); extern int cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst, mid_receive_t *receive, mid_callback_t *callback,
fs/cifs/cifssmb.c +4 -4
@@ -1399,8 +1399,8 @@ CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock,* Discard any remaining data in the current SMB. To do this, we borrow the * current bigbuf. */ -static int -discard_remaining_data (struct TCP_Server_Info *server) +int +cifs_discard_remaining_data (struct TCP_Server_Info *server) {unsigned int rfclen =get_rfc1002_length (server->smallbuf);int remaining = rfclen +4 - server->total_read;
@@ -1426,7 +1426,7 @@ cifs_readv_discard(struct TCP_Server_Info *server, struct mid_q_entry *mid)int length;struct cifs_readdata *rdata = mid->callback_data; - length =discard_remaining_data (server); + length =cifs_discard_remaining_data (server);dequeue_mid (mid, rdata->result);return length; }
@@ -1459,7 +1459,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)if (server->ops->is_status_pending && server->ops->is_status_pending (buf, server,0 )) { -discard_remaining_data (server); +cifs_discard_remaining_data (server);return -1 ; }
fs/cifs/smb2ops.c +164 -9
205 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 15/15 CIFS: Allow to switch on encryption with seal mount option
In reply to a message not in the archiveThis allows users to inforce encryption for SMB3 shares if a server supports it.
--- fs/cifs/connect.c | 41 ++++++++++++++++++++++++++++------------- fs/cifs/smb2pdu.c | 33 +++++++++++++++------------------ 2 files changed, 43 insertions(+), 31 deletions(-)
fs/cifs/connect.c +28 -13
@@ -2622,12 +2622,18 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)return ERR_PTR (rc); } -static int match_tcon (struct cifs_tcon *tcon,const char *unc) +static int match_tcon (struct cifs_tcon *tcon,struct smb_vol *volume_info) {if (tcon->tidStatus == CifsExiting)return 0 ; -if (strncmp (tcon->treeName, unc,MAX_TREE_SIZE )) +if (strncmp (tcon->treeName, volume_info->UNC,MAX_TREE_SIZE ))return 0 ; +if (tcon->seal != volume_info->seal) +return 0 ; +#ifdef CONFIG_CIFS_SMB2 +if (tcon->snapshot_time != volume_info->snapshot_time) +return 0 ; +#endif /* CONFIG_CIFS_SMB2 */ return 1 ; }
@@ -2640,14 +2646,8 @@ cifs_find_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)spin_lock (&cifs_tcp_ses_lock);list_for_each (tmp, &ses->tcon_list) { tcon = list_entry(tmp, struct cifs_tcon, tcon_list); -if (!match_tcon (tcon, volume_info->UNC)) -continue ; - -#ifdef CONFIG_CIFS_SMB2 -if (tcon->snapshot_time != volume_info->snapshot_time) +if (!match_tcon (tcon, volume_info))continue ; -#endif /* CONFIG_CIFS_SMB2 */ - ++tcon->tc_count;spin_unlock (&cifs_tcp_ses_lock);return tcon;
@@ -2693,8 +2693,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)cifs_dbg (FYI ,"Found match on UNC path\n" );/* existing tcon already has a reference */ cifs_put_smb_ses (ses); -if (tcon->seal != volume_info->seal) -cifs_dbg (VFS ,"transport encryption setting conflicts with existing tid\n" );return tcon; }
@@ -2750,7 +2748,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) tcon->Flags &= ~SMB_SHARE_IS_IN_DFS ;cifs_dbg (FYI ,"DFS disabled (%d)\n" , tcon->Flags); } - tcon->seal = volume_info->seal; tcon->use_persistent = false;/* check if SMB2 or later, CIFS does not support persistent handles */ if (volume_info->persistent) {
@@ -2787,6 +2784,24 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info) tcon->use_resilient = true; } +if (volume_info->seal) { +if (ses->server->vals->protocol_id ==0 ) { +cifs_dbg (VFS , +"SMB3 or later required for encryption\n" ); + rc = -EOPNOTSUPP ; + goto out_fail; +#ifdef CONFIG_CIFS_SMB2 + }else if (tcon->ses->server->capabilities & +SMB2_GLOBAL_CAP_ENCRYPTION ) + tcon->seal = true; +else { +cifs_dbg (VFS ,"Encryption is not supported on share\n" ); + rc = -EOPNOTSUPP ; + goto out_fail; +#endif /* CONFIG_CIFS_SMB2 */ + } + } +/* * We can have only one retry value for a connection to a share so for * resources mounted more than once to the same server share the last
@@ -2918,7 +2933,7 @@ cifs_match_super(struct super_block *sb, void *data)if (!match_server (tcp_srv, volume_info) || !match_session (ses, volume_info) || - !match_tcon (tcon, volume_info->UNC) || + !match_tcon (tcon, volume_info) || !match_prepath (sb, mnt_data)) { rc =0 ; goto out;
fs/cifs/smb2pdu.c +15 -18
@@ -79,9 +79,14 @@ static const int smb2_req_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = {static int encryption_required (const struct cifs_tcon *tcon) { +if (!tcon) +return 0 ;if ((tcon->ses->session_flags &SMB2_SESSION_FLAG_ENCRYPT_DATA ) || (tcon->share_flags &SHI1005_FLAGS_ENCRYPT_DATA ))return 1 ; +if (tcon->seal && + (tcon->ses->server->capabilities &SMB2_GLOBAL_CAP_ENCRYPTION )) +return 1 ;return 0 ; }
@@ -835,8 +840,6 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data) ses->Suid = rsp->hdr.sync_hdr.SessionId; ses->session_flags =le16_to_cpu (rsp->SessionFlags); -if (ses->session_flags &SMB2_SESSION_FLAG_ENCRYPT_DATA ) -cifs_dbg (VFS ,"SMB3 encryption not supported yet\n" ); rc =SMB2_sess_establish_session (sess_data); out_put_spnego_key:
@@ -933,8 +936,6 @@ SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data) ses->Suid = rsp->hdr.sync_hdr.SessionId; ses->session_flags =le16_to_cpu (rsp->SessionFlags); -if (ses->session_flags &SMB2_SESSION_FLAG_ENCRYPT_DATA ) -cifs_dbg (VFS ,"SMB3 encryption not supported yet\n" ); out:kfree (ntlmssp_blob);
@@ -993,8 +994,6 @@ SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data) ses->Suid = rsp->hdr.sync_hdr.SessionId; ses->session_flags =le16_to_cpu (rsp->SessionFlags); -if (ses->session_flags &SMB2_SESSION_FLAG_ENCRYPT_DATA ) -cifs_dbg (VFS ,"SMB3 encryption not supported yet\n" ); rc =SMB2_sess_establish_session (sess_data); out:
@@ -1145,12 +1144,6 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,if (tcon && tcon->bad_network_name)return -ENOENT ; -if ((tcon && tcon->seal) && - ((ses->server->capabilities &SMB2_GLOBAL_CAP_ENCRYPTION ) ==0 )) { -cifs_dbg (VFS ,"encryption requested but no server support" ); -return -EOPNOTSUPP ; - } - unc_path =kmalloc (MAX_SHARENAME_LENGTH *2 ,GFP_KERNEL );if (unc_path ==NULL )return -ENOMEM ;
@@ -1168,15 +1161,16 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,return rc; } -if (ses->session_flags &SMB2_SESSION_FLAG_ENCRYPT_DATA ) - flags |=CIFS_TRANSFORM_REQ ; -if (tcon ==NULL ) { +if ((ses->session_flags &SMB2_SESSION_FLAG_ENCRYPT_DATA )) + flags |=CIFS_TRANSFORM_REQ ; +/* since no tcon, smb2_init can not do this, so do here */ req->hdr.sync_hdr.SessionId = ses->Suid;/* if (ses->server->sec_mode & SECMODE_SIGN_REQUIRED) req->hdr.Flags |= SMB2_FLAGS_SIGNED; */ - } + }else if (encryption_required (tcon)) + flags |=CIFS_TRANSFORM_REQ ; iov[0 ].iov_base = (char *)req;/* 4 for rfc1002 length field and 1 for pad */
@@ -1233,9 +1227,12 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,if ((rsp->Capabilities &SMB2_SHARE_CAP_DFS ) && ((tcon->share_flags &SHI1005_FLAGS_DFS ) ==0 ))cifs_dbg (VFS ,"DFS capability contradicts DFS flag\n" ); + +if (tcon->seal && + !(tcon->ses->server->capabilities &SMB2_GLOBAL_CAP_ENCRYPTION )) +cifs_dbg (VFS ,"Encryption is requested but not supported\n" ); +init_copy_chunk_defaults (tcon); -if (tcon->share_flags &SHI1005_FLAGS_ENCRYPT_DATA ) -cifs_dbg (VFS ,"Encrypted shares not supported" );if (tcon->ses->server->ops->validate_negotiate) rc = tcon->ses->server->ops->validate_negotiate (xid, tcon); tcon_exit:
Signature · 1 line
2.7.4