cifs: Create a new shared file holding smb2 pdu definitions
Subsystems (2)
PATCH 1/4 cifs: Create a new shared file holding smb2 pdu definitions
This file will contain all the definitions we need for SMB2 packets and will follow the naming convention of MS-SMB2.PDF as closely as possible to make it easier to cross-reference beween the definitions and the standard.
The content of this file will mostly consist of migration of existing definitions in the cifs/smb2.pdu.h and ksmbd/smb2pdu.h files with some additional tweaks as the the two files have diverged.
This patch introduces the new cifs_common/smb2pdu.h file
and migrates the SMB2 header as well as TREE_CONNECT and TREE_DISCONNECT to the shared file.
--- fs/cifs/cifsfs.c | 1 - fs/cifs/cifsglob.h | 3 +- fs/cifs/connect.c | 4 +- fs/cifs/misc.c | 2 +- fs/cifs/smb2maperror.c | 16 +- fs/cifs/smb2misc.c | 43 +++-- fs/cifs/smb2ops.c | 65 +++---- fs/cifs/smb2pdu.c | 105 ++++++----- fs/cifs/smb2pdu.h | 373 ++++----------------------------------- fs/cifs/smb2proto.h | 2 +- fs/cifs/smb2transport.c | 36 ++-- fs/cifs_common/smb2pdu.h | 318 +++++++++++++++++++++++++++++++++ 12 files changed, 493 insertions(+), 475 deletions(-) create mode 100644 fs/cifs_common/smb2pdu.h
fs/cifs/cifsfs.c +0 -1
@@ -39,7 +39,6 @@#include <linux/key-type.h> #include "cifs_spnego.h" #include "fscache.h" -#include "smb2pdu.h" #ifdef CONFIG_CIFS_DFS_UPCALL #include "dfs_cache.h" #endif
fs/cifs/cifsglob.h +2 -1
@@ -21,6 +21,7 @@#include <crypto/internal/hash.h> #include <linux/scatterlist.h> #include <uapi/linux/cifs/cifs_mount.h> +#include "../cifs_common/smb2pdu.h" #include "smb2pdu.h" #define CIFS_MAGIC_NUMBER 0xFF534D42/* the first four bytes of SMB PDUs */
@@ -777,7 +778,7 @@ revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)static inline void revert_current_mid_from_hdr (struct TCP_Server_Info *server, -const struct smb2_sync_hdr *shdr) +const struct smb2_hdr *shdr) {unsigned int num =le16_to_cpu (shdr->CreditCharge);
fs/cifs/connect.c +2 -2
@@ -678,7 +678,7 @@ dequeue_mid(struct mid_q_entry *mid, bool malformed)static unsigned int smb2_get_credits_from_hdr (char *buffer,struct TCP_Server_Info *server) { -struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buffer; +struct smb2_hdr *shdr = (struct smb2_hdr *)buffer;/* * SMB1 does not use credits.
@@ -879,7 +879,7 @@ cifs_handle_standard(struct TCP_Server_Info *server, struct mid_q_entry *mid)static void smb2_add_credits_from_hdr (char *buffer,struct TCP_Server_Info *server) { -struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buffer; +struct smb2_hdr *shdr = (struct smb2_hdr *)buffer;int scredits, in_flight;/*
fs/cifs/misc.c +1 -1
@@ -153,7 +153,7 @@ cifs_buf_get(void)* SMB2 header is bigger than CIFS one - no problems to clean some * more bytes for CIFS. */ -size_t buf_size =sizeof (struct smb2_sync_hdr ); +size_t buf_size =sizeof (struct smb2_hdr );/* * We could use negotiated size instead of max_msgsize -
fs/cifs/smb2maperror.c +10 -6
@@ -2439,14 +2439,16 @@ smb2_print_status(__le32 status)int map_smb2_to_linux_error (char *buf,bool log_err) { -struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf; +struct smb2_hdr *shdr = (struct smb2_hdr *)buf;unsigned int i;int rc = -EIO ;__le32 smb2err = shdr->Status;if (smb2err ==0 ) { -trace_smb3_cmd_done (shdr->TreeId, shdr->SessionId, -le16_to_cpu (shdr->Command),le64_to_cpu (shdr->MessageId)); +trace_smb3_cmd_done (le32_to_cpu (shdr->Id.SyncId.TreeId), +le64_to_cpu (shdr->SessionId), +le16_to_cpu (shdr->Command), +le64_to_cpu (shdr->MessageId));return 0 ; }
@@ -2470,8 +2472,10 @@ map_smb2_to_linux_error(char *buf, bool log_err)cifs_dbg (FYI ,"Mapping SMB2 status code 0x%08x to POSIX err %d\n" ,__le32_to_cpu (smb2err), rc); -trace_smb3_cmd_err (shdr->TreeId, shdr->SessionId, -le16_to_cpu (shdr->Command), -le64_to_cpu (shdr->MessageId),le32_to_cpu (smb2err), rc); +trace_smb3_cmd_err (le32_to_cpu (shdr->Id.SyncId.TreeId), +le64_to_cpu (shdr->SessionId), +le16_to_cpu (shdr->Command), +le64_to_cpu (shdr->MessageId), +le32_to_cpu (smb2err), rc);return rc; }
fs/cifs/smb2misc.c +21 -22
119 lines not on this page · raw message
fs/cifs/smb2ops.c +33 -32
241 lines not on this page · raw message
fs/cifs/smb2pdu.c +52 -53
381 lines not on this page · raw message
fs/cifs/smb2pdu.h +35 -338
589 lines not on this page · raw message
fs/cifs/smb2proto.h +1 -1
@@ -26,7 +26,7 @@ extern int smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *server);extern unsigned int smb2_calc_size (void *buf,struct TCP_Server_Info *server);extern char *smb2_get_data_area_len (int *off,int *len, -struct smb2_sync_hdr *shdr); +struct smb2_hdr *shdr);extern __le16 *cifs_convert_path_to_utf16 (const char *from,struct cifs_sb_info *cifs_sb);
fs/cifs/smb2transport.c +18 -18
@@ -20,7 +20,6 @@#include <linux/mempool.h> #include <linux/highmem.h> #include <crypto/aead.h> -#include "smb2pdu.h" #include "cifsglob.h" #include "cifsproto.h" #include "smb2proto.h"
@@ -214,14 +213,14 @@ 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 = (struct smb2_sync_hdr *)iov[0 ].iov_base; +struct smb2_hdr *shdr = (struct smb2_hdr *)iov[0 ].iov_base;struct cifs_ses *ses;struct shash_desc *shash;struct crypto_shash *hash;struct sdesc *sdesc =NULL ;struct smb_rqst drqst; - ses =smb2_find_smb_ses (server, shdr->SessionId); + ses =smb2_find_smb_ses (server,le64_to_cpu (shdr->SessionId));if (!ses) {cifs_server_dbg (VFS ,"%s: Could not find session\n" , __func__);return 0 ;
@@ -535,14 +534,14 @@ 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 = (struct smb2_sync_hdr *)iov[0 ].iov_base; +struct smb2_hdr *shdr = (struct smb2_hdr *)iov[0 ].iov_base;struct shash_desc *shash;struct crypto_shash *hash;struct sdesc *sdesc =NULL ;struct smb_rqst drqst;u8 key[SMB3_SIGN_KEY_SIZE ]; - rc =smb2_get_sign_key (shdr->SessionId, server, key); + rc =smb2_get_sign_key (le64_to_cpu (shdr->SessionId), server, key);if (rc)return 0 ;
@@ -612,12 +611,12 @@ static int smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server) { int rc = 0; -struct smb2_sync_hdr *shdr; +struct smb2_hdr *shdr;struct smb2_sess_setup_req *ssr;bool is_binding;bool is_signed; - shdr = (struct smb2_sync_hdr *)rqst->rq_iov[0 ].iov_base; + shdr = (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base; ssr = (struct smb2_sess_setup_req *)shdr; is_binding = shdr->Command == SMB2_SESSION_SETUP &&
@@ -643,8 +642,8 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) {unsigned int rc;char server_response_sig[SMB2_SIGNATURE_SIZE ]; -struct smb2_sync_hdr *shdr = - (struct smb2_sync_hdr *)rqst->rq_iov[0 ].iov_base; +struct smb2_hdr *shdr = + (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base; if ((shdr->Command == SMB2_NEGOTIATE) || (shdr->Command == SMB2_SESSION_SETUP) ||
@@ -690,7 +689,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)*/ static inline void smb2_seq_num_into_buf (struct TCP_Server_Info *server, -struct smb2_sync_hdr *shdr) +struct smb2_hdr *shdr) {unsigned int i, num =le16_to_cpu (shdr->CreditCharge);
@@ -701,7 +700,7 @@ smb2_seq_num_into_buf(struct TCP_Server_Info *server, }static struct mid_q_entry * -smb2_mid_entry_alloc (const struct smb2_sync_hdr *shdr, +smb2_mid_entry_alloc (const struct smb2_hdr *shdr,struct TCP_Server_Info *server) {struct mid_q_entry *temp;
@@ -733,14 +732,15 @@ smb2_mid_entry_alloc(const struct smb2_sync_hdr *shdr,atomic_inc (&midCount); temp->mid_state =MID_REQUEST_ALLOCATED ; -trace_smb3_cmd_enter (shdr->TreeId, shdr->SessionId, -le16_to_cpu (shdr->Command), temp->mid); +trace_smb3_cmd_enter (le32_to_cpu (shdr->Id.SyncId.TreeId), +le64_to_cpu (shdr->SessionId), +le16_to_cpu (shdr->Command), temp->mid);return temp; }static int smb2_get_mid_entry (struct cifs_ses *ses,struct TCP_Server_Info *server, -struct smb2_sync_hdr *shdr,struct mid_q_entry **mid) +struct smb2_hdr *shdr,struct mid_q_entry **mid) {if (server->tcpStatus == CifsExiting)return -ENOENT ;
@@ -808,8 +808,8 @@ smb2_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *server, struct smb_rqst *rqst) {int rc; -struct smb2_sync_hdr *shdr = - (struct smb2_sync_hdr *)rqst->rq_iov[0 ].iov_base; +struct smb2_hdr *shdr = + (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base;struct mid_q_entry *mid;smb2_seq_num_into_buf (server, shdr);
@@ -834,8 +834,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 = - (struct smb2_sync_hdr *)rqst->rq_iov[0 ].iov_base; +struct smb2_hdr *shdr = + (struct smb2_hdr *)rqst->rq_iov[0 ].iov_base;struct mid_q_entry *mid; if (server->tcpStatus == CifsNeedNegotiate &&
fs/cifs_common/smb2pdu.h new file +318 -0
318 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH 2/4 ksmbd: switch to use shared definitions where available
--- fs/ksmbd/smb2misc.c | 1 - fs/ksmbd/smb2ops.c | 1 - fs/ksmbd/smb2pdu.c | 3 +- fs/ksmbd/smb2pdu.h | 176 ------------------------------------------ fs/ksmbd/smb_common.h | 1 + 5 files changed, 2 insertions(+), 180 deletions(-)
fs/ksmbd/smb2misc.c +0 -1
@@ -6,7 +6,6 @@#include "glob.h" #include "nterr.h" -#include "smb2pdu.h" #include "smb_common.h" #include "smbstatus.h" #include "mgmt/user_session.h"
fs/ksmbd/smb2ops.c +0 -1
@@ -6,7 +6,6 @@#include <linux/slab.h> #include "glob.h" -#include "smb2pdu.h" #include "auth.h" #include "connection.h"
fs/ksmbd/smb2pdu.c +1 -2
@@ -13,7 +13,6 @@#include <linux/falloc.h> #include "glob.h" -#include "smb2pdu.h" #include "smbfsctl.h" #include "oplock.h" #include "smbacl.h"
@@ -8249,7 +8248,7 @@ static void fill_transform_hdr(void *tr_buf, char *old_buf, __le16 cipher_type)memset (tr_buf,0 ,sizeof (struct smb2_transform_hdr ) +4 ); tr_hdr->ProtocolId =SMB2_TRANSFORM_PROTO_NUM ; tr_hdr->OriginalMessageSize =cpu_to_le32 (orig_len); - tr_hdr->Flags =cpu_to_le16 (0x01 ); + tr_hdr->Flags =cpu_to_le16 (TRANSFORM_FLAG_ENCRYPTED );if (cipher_type ==SMB2_ENCRYPTION_AES128_GCM || cipher_type ==SMB2_ENCRYPTION_AES256_GCM )get_random_bytes (&tr_hdr->Nonce,SMB3_AES_GCM_NONCE );
fs/ksmbd/smb2pdu.h +0 -176
198 lines not on this page · raw message
fs/ksmbd/smb_common.h +1 -0
@@ -10,6 +10,7 @@#include "glob.h" #include "nterr.h" +#include "../cifs_common/smb2pdu.h" #include "smb2pdu.h" /* ksmbd's Specific ERRNO */
Signature · 1 line
2.30.2
PATCH 3/4 cifs: move NEGOTIATE_PROTOCOL definitions out into the common area
In reply to Ronnie Sahlberg--- fs/cifs/smb2pdu.c | 4 +- fs/cifs/smb2pdu.h | 220 ------------------------------------- fs/cifs_common/smb2pdu.h | 229 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 231 insertions(+), 222 deletions(-)
fs/cifs/smb2pdu.c +2 -2
@@ -414,8 +414,8 @@ build_preauth_ctxt(struct smb2_preauth_neg_context *pneg_ctxt) pneg_ctxt->ContextType =SMB2_PREAUTH_INTEGRITY_CAPABILITIES ; pneg_ctxt->DataLength =cpu_to_le16 (38 ); pneg_ctxt->HashAlgorithmCount =cpu_to_le16 (1 ); - pneg_ctxt->SaltLength =cpu_to_le16 (SMB311_LINUX_CLIENT_SALT_SIZE ); -get_random_bytes (pneg_ctxt->Salt,SMB311_LINUX_CLIENT_SALT_SIZE ); + pneg_ctxt->SaltLength =cpu_to_le16 (SMB311_SALT_SIZE ); +get_random_bytes (pneg_ctxt->Salt,SMB311_SALT_SIZE ); pneg_ctxt->HashAlgorithms =SMB2_PREAUTH_INTEGRITY_SHA512 ; }
fs/cifs/smb2pdu.h +0 -220
226 lines not on this page · raw message
fs/cifs_common/smb2pdu.h +229 -0
233 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH 4/4 ksmbd: use the common definitions for NEGOTIATE_PROTOCOL
In reply to Ronnie Sahlberg--- fs/ksmbd/smb2ops.c | 8 +-- fs/ksmbd/smb2pdu.c | 20 +++--- fs/ksmbd/smb2pdu.h | 143 +----------------------------------------- fs/ksmbd/smb_common.h | 11 ---- 4 files changed, 15 insertions(+), 167 deletions(-)
fs/ksmbd/smb2ops.c +4 -4
@@ -203,7 +203,7 @@ void init_smb2_1_server(struct ksmbd_conn *conn) conn->cmds = smb2_0_server_cmds; conn->max_cmds =ARRAY_SIZE (smb2_0_server_cmds); conn->max_credits =SMB2_MAX_CREDITS ; - conn->signing_algorithm =SIGNING_ALG_HMAC_SHA256 ; + conn->signing_algorithm =SIGNING_ALG_HMAC_SHA256_LE ;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_LEASES ) conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING ;
@@ -221,7 +221,7 @@ void init_smb3_0_server(struct ksmbd_conn *conn) conn->cmds = smb2_0_server_cmds; conn->max_cmds =ARRAY_SIZE (smb2_0_server_cmds); conn->max_credits =SMB2_MAX_CREDITS ; - conn->signing_algorithm =SIGNING_ALG_AES_CMAC ; + conn->signing_algorithm =SIGNING_ALG_AES_CMAC_LE ;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_LEASES ) conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING ;
@@ -246,7 +246,7 @@ void init_smb3_02_server(struct ksmbd_conn *conn) conn->cmds = smb2_0_server_cmds; conn->max_cmds =ARRAY_SIZE (smb2_0_server_cmds); conn->max_credits =SMB2_MAX_CREDITS ; - conn->signing_algorithm =SIGNING_ALG_AES_CMAC ; + conn->signing_algorithm =SIGNING_ALG_AES_CMAC_LE ;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_LEASES ) conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING ;
@@ -271,7 +271,7 @@ int init_smb3_11_server(struct ksmbd_conn *conn) conn->cmds = smb2_0_server_cmds; conn->max_cmds =ARRAY_SIZE (smb2_0_server_cmds); conn->max_credits =SMB2_MAX_CREDITS ; - conn->signing_algorithm =SIGNING_ALG_AES_CMAC ; + conn->signing_algorithm =SIGNING_ALG_AES_CMAC_LE ;if (server_conf.flags &KSMBD_GLOBAL_FLAG_SMB2_LEASES ) conn->vals->capabilities |=SMB2_GLOBAL_CAP_LEASING ;
fs/ksmbd/smb2pdu.c +10 -10
@@ -771,16 +771,16 @@ static void build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt, pneg_ctxt->Ciphers[0 ] = cipher_type; } -static void build_compression_ctxt (struct smb2_compression_ctx *pneg_ctxt, +static void build_compression_ctxt (struct smb2_compression_capabilities_context *pneg_ctxt,__le16 comp_algo) { pneg_ctxt->ContextType =SMB2_COMPRESSION_CAPABILITIES ; pneg_ctxt->DataLength = -cpu_to_le16 (sizeof (struct smb2_compression_ctx ) +cpu_to_le16 (sizeof (struct smb2_compression_capabilities_context ) -sizeof (struct smb2_neg_context )); pneg_ctxt->Reserved =cpu_to_le32 (0 ); pneg_ctxt->CompressionAlgorithmCount =cpu_to_le16 (1 ); - pneg_ctxt->Reserved1 =cpu_to_le32 (0 ); + pneg_ctxt->Flags =cpu_to_le32 (0 ); pneg_ctxt->CompressionAlgorithms[0 ] = comp_algo; }
@@ -857,12 +857,12 @@ static void assemble_neg_contexts(struct ksmbd_conn *conn,ksmbd_debug (SMB ,"assemble SMB2_COMPRESSION_CAPABILITIES context\n" );/* Temporarily set to SMB3_COMPRESS_NONE */ -build_compression_ctxt ((struct smb2_compression_ctx *)pneg_ctxt, +build_compression_ctxt ((struct smb2_compression_capabilities_context *)pneg_ctxt, conn->compress_algorithm); rsp->NegotiateContextCount =cpu_to_le16 (++neg_ctxt_cnt); - ctxt_size +=sizeof (struct smb2_compression_ctx ) +2 ; + ctxt_size +=sizeof (struct smb2_compression_capabilities_context ) +2 ;/* Round to 8 byte boundary */ - pneg_ctxt +=round_up (sizeof (struct smb2_compression_ctx ) +2 , + pneg_ctxt +=round_up (sizeof (struct smb2_compression_capabilities_context ) +2 ,8 ); }
@@ -936,7 +936,7 @@ static void decode_encrypt_ctxt(struct ksmbd_conn *conn, }static void decode_compress_ctxt (struct ksmbd_conn *conn, -struct smb2_compression_ctx *pneg_ctxt) +struct smb2_compression_capabilities_context *pneg_ctxt) { conn->compress_algorithm =SMB3_COMPRESS_NONE ; }
@@ -957,8 +957,8 @@ static void decode_sign_cap_ctxt(struct ksmbd_conn *conn, }for (i =0 ; i < sign_algo_cnt; i++) { -if (pneg_ctxt->SigningAlgorithms[i] ==SIGNING_ALG_HMAC_SHA256 || - pneg_ctxt->SigningAlgorithms[i] ==SIGNING_ALG_AES_CMAC ) { +if (pneg_ctxt->SigningAlgorithms[i] ==SIGNING_ALG_HMAC_SHA256_LE || + pneg_ctxt->SigningAlgorithms[i] ==SIGNING_ALG_AES_CMAC_LE ) {ksmbd_debug (SMB ,"Signing Algorithm ID = 0x%x\n" , pneg_ctxt->SigningAlgorithms[i]); conn->signing_negotiated = true;
@@ -1029,7 +1029,7 @@ static __le32 deassemble_neg_contexts(struct ksmbd_conn *conn,break ;decode_compress_ctxt (conn, - (struct smb2_compression_ctx *)pctx); + (struct smb2_compression_capabilities_context *)pctx); }else if (pctx->ContextType ==SMB2_NETNAME_NEGOTIATE_CONTEXT_ID ) {ksmbd_debug (SMB ,"deassemble SMB2_NETNAME_NEGOTIATE_CONTEXT_ID context\n" );
fs/ksmbd/smb2pdu.h +1 -142
165 lines not on this page · raw message
fs/ksmbd/smb_common.h +0 -11
@@ -33,17 +33,6 @@#define SMB302_VERSION_STRING "3.02"#define SMB311_VERSION_STRING "3.1.1" -/* Dialects */ -#define SMB10_PROT_ID 0x00 -#define SMB20_PROT_ID 0x0202 -#define SMB21_PROT_ID 0x0210 -/* multi-protocol negotiate request */ -#define SMB2X_PROT_ID 0x02FF -#define SMB30_PROT_ID 0x0300 -#define SMB302_PROT_ID 0x0302 -#define SMB311_PROT_ID 0x0311 -#define BAD_PROT_ID 0xFFFF -#define SMB_ECHO_INTERVAL (60 * HZ)#define CIFS_DEFAULT_IOSIZE (64 * 1024)
Signature · 1 line
2.30.2