Skip to content

Commit 0d35e38

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
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 two files have diverged. This patch introduces the new smbfs_common/smb2pdu.h file and migrates the SMB2 header as well as TREE_CONNECT and TREE_DISCONNECT to the shared file. Signed-off-by: Ronnie Sahlberg <[email protected]> Reviewed-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 7ae5e58 commit 0d35e38

File tree

12 files changed

+493
-476
lines changed

12 files changed

+493
-476
lines changed

fs/cifs/cifsfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include <linux/key-type.h>
3939
#include "cifs_spnego.h"
4040
#include "fscache.h"
41-
#include "smb2pdu.h"
4241
#ifdef CONFIG_CIFS_DFS_UPCALL
4342
#include "dfs_cache.h"
4443
#endif

fs/cifs/cifsglob.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <crypto/internal/hash.h>
2121
#include <linux/scatterlist.h>
2222
#include <uapi/linux/cifs/cifs_mount.h>
23+
#include "../smbfs_common/smb2pdu.h"
2324
#include "smb2pdu.h"
2425

2526
#define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
@@ -776,7 +777,7 @@ revert_current_mid(struct TCP_Server_Info *server, const unsigned int val)
776777

777778
static inline void
778779
revert_current_mid_from_hdr(struct TCP_Server_Info *server,
779-
const struct smb2_sync_hdr *shdr)
780+
const struct smb2_hdr *shdr)
780781
{
781782
unsigned int num = le16_to_cpu(shdr->CreditCharge);
782783

fs/cifs/connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ dequeue_mid(struct mid_q_entry *mid, bool malformed)
677677
static unsigned int
678678
smb2_get_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
679679
{
680-
struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buffer;
680+
struct smb2_hdr *shdr = (struct smb2_hdr *)buffer;
681681

682682
/*
683683
* SMB1 does not use credits.
@@ -877,7 +877,7 @@ cifs_handle_standard(struct TCP_Server_Info *server, struct mid_q_entry *mid)
877877
static void
878878
smb2_add_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
879879
{
880-
struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buffer;
880+
struct smb2_hdr *shdr = (struct smb2_hdr *)buffer;
881881
int scredits, in_flight;
882882

883883
/*

fs/cifs/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ cifs_buf_get(void)
152152
* SMB2 header is bigger than CIFS one - no problems to clean some
153153
* more bytes for CIFS.
154154
*/
155-
size_t buf_size = sizeof(struct smb2_sync_hdr);
155+
size_t buf_size = sizeof(struct smb2_hdr);
156156

157157
/*
158158
* We could use negotiated size instead of max_msgsize -

fs/cifs/smb2maperror.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,14 +2439,16 @@ smb2_print_status(__le32 status)
24392439
int
24402440
map_smb2_to_linux_error(char *buf, bool log_err)
24412441
{
2442-
struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
2442+
struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
24432443
unsigned int i;
24442444
int rc = -EIO;
24452445
__le32 smb2err = shdr->Status;
24462446

24472447
if (smb2err == 0) {
2448-
trace_smb3_cmd_done(shdr->TreeId, shdr->SessionId,
2449-
le16_to_cpu(shdr->Command), le64_to_cpu(shdr->MessageId));
2448+
trace_smb3_cmd_done(le32_to_cpu(shdr->Id.SyncId.TreeId),
2449+
le64_to_cpu(shdr->SessionId),
2450+
le16_to_cpu(shdr->Command),
2451+
le64_to_cpu(shdr->MessageId));
24502452
return 0;
24512453
}
24522454

@@ -2470,8 +2472,10 @@ map_smb2_to_linux_error(char *buf, bool log_err)
24702472
cifs_dbg(FYI, "Mapping SMB2 status code 0x%08x to POSIX err %d\n",
24712473
__le32_to_cpu(smb2err), rc);
24722474

2473-
trace_smb3_cmd_err(shdr->TreeId, shdr->SessionId,
2474-
le16_to_cpu(shdr->Command),
2475-
le64_to_cpu(shdr->MessageId), le32_to_cpu(smb2err), rc);
2475+
trace_smb3_cmd_err(le32_to_cpu(shdr->Id.SyncId.TreeId),
2476+
le64_to_cpu(shdr->SessionId),
2477+
le16_to_cpu(shdr->Command),
2478+
le64_to_cpu(shdr->MessageId),
2479+
le32_to_cpu(smb2err), rc);
24762480
return rc;
24772481
}

fs/cifs/smb2misc.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*
99
*/
1010
#include <linux/ctype.h>
11-
#include "smb2pdu.h"
1211
#include "cifsglob.h"
1312
#include "cifsproto.h"
1413
#include "smb2proto.h"
@@ -19,7 +18,7 @@
1918
#include "nterr.h"
2019

2120
static int
22-
check_smb2_hdr(struct smb2_sync_hdr *shdr, __u64 mid)
21+
check_smb2_hdr(struct smb2_hdr *shdr, __u64 mid)
2322
{
2423
__u64 wire_mid = le64_to_cpu(shdr->MessageId);
2524

@@ -81,9 +80,9 @@ static const __le16 smb2_rsp_struct_sizes[NUMBER_OF_SMB2_COMMANDS] = {
8180
/* SMB2_OPLOCK_BREAK */ cpu_to_le16(24)
8281
};
8382

84-
#define SMB311_NEGPROT_BASE_SIZE (sizeof(struct smb2_sync_hdr) + sizeof(struct smb2_negotiate_rsp))
83+
#define SMB311_NEGPROT_BASE_SIZE (sizeof(struct smb2_hdr) + sizeof(struct smb2_negotiate_rsp))
8584

86-
static __u32 get_neg_ctxt_len(struct smb2_sync_hdr *hdr, __u32 len,
85+
static __u32 get_neg_ctxt_len(struct smb2_hdr *hdr, __u32 len,
8786
__u32 non_ctxlen)
8887
{
8988
__u16 neg_count;
@@ -135,13 +134,13 @@ static __u32 get_neg_ctxt_len(struct smb2_sync_hdr *hdr, __u32 len,
135134
int
136135
smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr)
137136
{
138-
struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
139-
struct smb2_sync_pdu *pdu = (struct smb2_sync_pdu *)shdr;
137+
struct smb2_hdr *shdr = (struct smb2_hdr *)buf;
138+
struct smb2_pdu *pdu = (struct smb2_pdu *)shdr;
140139
__u64 mid;
141140
__u32 clc_len; /* calculated length */
142141
int command;
143-
int pdu_size = sizeof(struct smb2_sync_pdu);
144-
int hdr_size = sizeof(struct smb2_sync_hdr);
142+
int pdu_size = sizeof(struct smb2_pdu);
143+
int hdr_size = sizeof(struct smb2_hdr);
145144

146145
/*
147146
* Add function to do table lookup of StructureSize by command
@@ -155,7 +154,7 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr)
155154
/* decrypt frame now that it is completely read in */
156155
spin_lock(&cifs_tcp_ses_lock);
157156
list_for_each_entry(ses, &srvr->smb_ses_list, smb_ses_list) {
158-
if (ses->Suid == thdr->SessionId)
157+
if (ses->Suid == le64_to_cpu(thdr->SessionId))
159158
break;
160159
}
161160
spin_unlock(&cifs_tcp_ses_lock);
@@ -296,7 +295,7 @@ static const bool has_smb2_data_area[NUMBER_OF_SMB2_COMMANDS] = {
296295
* area and the offset to it (from the beginning of the smb are also returned.
297296
*/
298297
char *
299-
smb2_get_data_area_len(int *off, int *len, struct smb2_sync_hdr *shdr)
298+
smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *shdr)
300299
{
301300
*off = 0;
302301
*len = 0;
@@ -401,8 +400,8 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_sync_hdr *shdr)
401400
unsigned int
402401
smb2_calc_size(void *buf, struct TCP_Server_Info *srvr)
403402
{
404-
struct smb2_sync_pdu *pdu = (struct smb2_sync_pdu *)buf;
405-
struct smb2_sync_hdr *shdr = &pdu->sync_hdr;
403+
struct smb2_pdu *pdu = (struct smb2_pdu *)buf;
404+
struct smb2_hdr *shdr = &pdu->hdr;
406405
int offset; /* the offset from the beginning of SMB to data area */
407406
int data_length; /* the length of the variable length data area */
408407
/* Structure Size has already been checked to make sure it is 64 */
@@ -669,7 +668,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
669668

670669
cifs_dbg(FYI, "Checking for oplock break\n");
671670

672-
if (rsp->sync_hdr.Command != SMB2_OPLOCK_BREAK)
671+
if (rsp->hdr.Command != SMB2_OPLOCK_BREAK)
673672
return false;
674673

675674
if (rsp->StructureSize !=
@@ -816,23 +815,23 @@ smb2_handle_cancelled_close(struct cifs_tcon *tcon, __u64 persistent_fid,
816815
int
817816
smb2_handle_cancelled_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server)
818817
{
819-
struct smb2_sync_hdr *sync_hdr = mid->resp_buf;
818+
struct smb2_hdr *hdr = mid->resp_buf;
820819
struct smb2_create_rsp *rsp = mid->resp_buf;
821820
struct cifs_tcon *tcon;
822821
int rc;
823822

824-
if ((mid->optype & CIFS_CP_CREATE_CLOSE_OP) || sync_hdr->Command != SMB2_CREATE ||
825-
sync_hdr->Status != STATUS_SUCCESS)
823+
if ((mid->optype & CIFS_CP_CREATE_CLOSE_OP) || hdr->Command != SMB2_CREATE ||
824+
hdr->Status != STATUS_SUCCESS)
826825
return 0;
827826

828-
tcon = smb2_find_smb_tcon(server, sync_hdr->SessionId,
829-
sync_hdr->TreeId);
827+
tcon = smb2_find_smb_tcon(server, le64_to_cpu(hdr->SessionId),
828+
le32_to_cpu(hdr->Id.SyncId.TreeId));
830829
if (!tcon)
831830
return -ENOENT;
832831

833832
rc = __smb2_handle_cancelled_cmd(tcon,
834-
le16_to_cpu(sync_hdr->Command),
835-
le64_to_cpu(sync_hdr->MessageId),
833+
le16_to_cpu(hdr->Command),
834+
le64_to_cpu(hdr->MessageId),
836835
rsp->PersistentFileId,
837836
rsp->VolatileFileId);
838837
if (rc)
@@ -856,10 +855,10 @@ smb311_update_preauth_hash(struct cifs_ses *ses, struct kvec *iov, int nvec)
856855
{
857856
int i, rc;
858857
struct sdesc *d;
859-
struct smb2_sync_hdr *hdr;
858+
struct smb2_hdr *hdr;
860859
struct TCP_Server_Info *server = cifs_ses_server(ses);
861860

862-
hdr = (struct smb2_sync_hdr *)iov[0].iov_base;
861+
hdr = (struct smb2_hdr *)iov[0].iov_base;
863862
/* neg prot are always taken */
864863
if (hdr->Command == SMB2_NEGOTIATE)
865864
goto ok;

0 commit comments

Comments
 (0)