Skip to content

Commit

Permalink
CIFS: Fix log messages in packet checking for SMB2
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
Signed-off-by: Steve French <smfrench@gmail.com>
  • Loading branch information
Pavel Shilovsky authored and Steve French committed Aug 20, 2012
1 parent b7ca692 commit 7411286
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 9 additions & 7 deletions fs/cifs/smb2misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ check_smb2_hdr(struct smb2_hdr *hdr, __u64 mid)
cERROR(1, "Bad protocol string signature header %x",
*(unsigned int *) hdr->ProtocolId);
if (mid != hdr->MessageId)
cERROR(1, "Mids do not match");
cERROR(1, "Mids do not match: %llu and %llu", mid,
hdr->MessageId);
}
cERROR(1, "Bad SMB detected. The Mid=%llu", hdr->MessageId);
return 1;
Expand Down Expand Up @@ -107,7 +108,7 @@ smb2_check_message(char *buf, unsigned int length)
* ie Validate the wct via smb2_struct_sizes table above
*/

if (length < 2 + sizeof(struct smb2_hdr)) {
if (length < sizeof(struct smb2_pdu)) {
if ((length >= sizeof(struct smb2_hdr)) && (hdr->Status != 0)) {
pdu->StructureSize2 = 0;
/*
Expand All @@ -121,15 +122,15 @@ smb2_check_message(char *buf, unsigned int length)
return 1;
}
if (len > CIFSMaxBufSize + MAX_SMB2_HDR_SIZE - 4) {
cERROR(1, "SMB length greater than maximum, mid=%lld", mid);
cERROR(1, "SMB length greater than maximum, mid=%llu", mid);
return 1;
}

if (check_smb2_hdr(hdr, mid))
return 1;

if (hdr->StructureSize != SMB2_HEADER_SIZE) {
cERROR(1, "Illegal structure size %d",
if (hdr->StructureSize != SMB2_HEADER_STRUCTURE_SIZE) {
cERROR(1, "Illegal structure size %u",
le16_to_cpu(hdr->StructureSize));
return 1;
}
Expand Down Expand Up @@ -161,8 +162,9 @@ smb2_check_message(char *buf, unsigned int length)
if (4 + len != clc_len) {
cFYI(1, "Calculated size %u length %u mismatch mid %llu",
clc_len, 4 + len, mid);
if (clc_len == 4 + len + 1) /* BB FIXME (fix samba) */
return 0; /* BB workaround Samba 3 bug SessSetup rsp */
/* server can return one byte more */
if (clc_len == 4 + len + 1)
return 0;
return 1;
}
return 0;
Expand Down
10 changes: 6 additions & 4 deletions fs/cifs/smb2pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@

#define SMB2_PROTO_NUMBER __constant_cpu_to_le32(0x424d53fe)

#define SMB2_HEADER_SIZE __constant_le16_to_cpu(64)

#define SMB2_ERROR_STRUCTURE_SIZE2 __constant_le16_to_cpu(9)

/*
* SMB2 Header Definition
*
Expand All @@ -99,6 +95,9 @@
* "PDU" : "Protocol Data Unit" (ie a network "frame")
*
*/

#define SMB2_HEADER_STRUCTURE_SIZE __constant_le16_to_cpu(64)

struct smb2_hdr {
__be32 smb2_buf_length; /* big endian on wire */
/* length is only two or three bytes - with
Expand Down Expand Up @@ -140,6 +139,9 @@ struct smb2_pdu {
* command code name for the struct. Note that structures must be packed.
*
*/

#define SMB2_ERROR_STRUCTURE_SIZE2 __constant_le16_to_cpu(9)

struct smb2_err_rsp {
struct smb2_hdr hdr;
__le16 StructureSize;
Expand Down

0 comments on commit 7411286

Please sign in to comment.