Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be8e3b00 authored by Steve French's avatar Steve French
Browse files

consistently use smb_buf_length as be32 for cifs (try 3)



       There is one big endian field in the cifs protocol, the RFC1001
       length, which cifs code (unlike in the smb2 code) had been handling as
       u32 until the last possible moment, when it was converted to be32 (its
       native form) before sending on the wire.   To remove the last sparse
       endian warning, and to make this consistent with the smb2
       implementation  (which always treats the fields in their
       native size and endianness), convert all uses of smb_buf_length to
       be32.

       This version incorporates Christoph's comment about
       using be32_add_cpu, and fixes a typo in the second
       version of the patch.

Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
Signed-off-by: default avatarPavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent 9409ae58
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -60,7 +60,7 @@ static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
		server->session_key.response, server->session_key.len);
		server->session_key.response, server->session_key.len);


	crypto_shash_update(&server->secmech.sdescmd5->shash,
	crypto_shash_update(&server->secmech.sdescmd5->shash,
		cifs_pdu->Protocol, cifs_pdu->smb_buf_length);
		cifs_pdu->Protocol, be32_to_cpu(cifs_pdu->smb_buf_length));


	rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature);
	rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature);


+3 −3
Original line number Original line Diff line number Diff line
@@ -397,9 +397,9 @@
#define GETU32(var)  (*((__u32 *)var))	/* BB check for endian issues */
#define GETU32(var)  (*((__u32 *)var))	/* BB check for endian issues */


struct smb_hdr {
struct smb_hdr {
	__u32 smb_buf_length;	/* big endian on wire *//* BB length is only two
	__be32 smb_buf_length;	/* BB length is only two (rarely three) bytes,
		or three bytes - with one or two byte type preceding it that are
		with one or two byte "type" preceding it that will be
		zero - we could mask the type byte off just in case BB */
		zero - we could mask the type byte off */
	__u8 Protocol[4];
	__u8 Protocol[4];
	__u8 Command;
	__u8 Command;
	union {
	union {
+65 −58

File changed.

Preview size limit exceeded, changes collapsed.

+6 −6
Original line number Original line Diff line number Diff line
@@ -324,12 +324,12 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
		return -EPROTO;
		return -EPROTO;
	put_bcc_le(byte_count, pTargetSMB);
	put_bcc_le(byte_count, pTargetSMB);


	byte_count = pTargetSMB->smb_buf_length;
	byte_count = be32_to_cpu(pTargetSMB->smb_buf_length);
	byte_count += total_in_buf2;
	byte_count += total_in_buf2;
	/* don't allow buffer to overflow */
	/* don't allow buffer to overflow */
	if (byte_count > CIFSMaxBufSize)
	if (byte_count > CIFSMaxBufSize)
		return -ENOBUFS;
		return -ENOBUFS;
	pTargetSMB->smb_buf_length = byte_count;
	pTargetSMB->smb_buf_length = cpu_to_be32(byte_count);


	memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2);
	memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2);


@@ -496,8 +496,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
		/* Note that FC 1001 length is big endian on the wire,
		/* Note that FC 1001 length is big endian on the wire,
		but we convert it here so it is always manipulated
		but we convert it here so it is always manipulated
		as host byte order */
		as host byte order */
		pdu_length = be32_to_cpu((__force __be32)smb_buffer->smb_buf_length);
		pdu_length = be32_to_cpu(smb_buffer->smb_buf_length);
		smb_buffer->smb_buf_length = pdu_length;


		cFYI(1, "rfc1002 length 0x%x", pdu_length+4);
		cFYI(1, "rfc1002 length 0x%x", pdu_length+4);


@@ -2297,7 +2296,7 @@ ip_rfc1001_connect(struct TCP_Server_Info *server)
		smb_buf = (struct smb_hdr *)ses_init_buf;
		smb_buf = (struct smb_hdr *)ses_init_buf;


		/* sizeof RFC1002_SESSION_REQUEST with no scope */
		/* sizeof RFC1002_SESSION_REQUEST with no scope */
		smb_buf->smb_buf_length = 0x81000044;
		smb_buf->smb_buf_length = cpu_to_be32(0x81000044);
		rc = smb_send(server, smb_buf, 0x44);
		rc = smb_send(server, smb_buf, 0x44);
		kfree(ses_init_buf);
		kfree(ses_init_buf);
		/*
		/*
@@ -3100,7 +3099,8 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
	bcc_ptr += strlen("?????");
	bcc_ptr += strlen("?????");
	bcc_ptr += 1;
	bcc_ptr += 1;
	count = bcc_ptr - &pSMB->Password[0];
	count = bcc_ptr - &pSMB->Password[0];
	pSMB->hdr.smb_buf_length += count;
	pSMB->hdr.smb_buf_length = cpu_to_be32(be32_to_cpu(
					pSMB->hdr.smb_buf_length) + count);
	pSMB->ByteCount = cpu_to_le16(count);
	pSMB->ByteCount = cpu_to_le16(count);


	rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length,
	rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length,
+3 −5
Original line number Original line Diff line number Diff line
@@ -304,12 +304,10 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,


	memset(temp, 0, 256); /* bigger than MAX_CIFS_HDR_SIZE */
	memset(temp, 0, 256); /* bigger than MAX_CIFS_HDR_SIZE */


	buffer->smb_buf_length =
	buffer->smb_buf_length = cpu_to_be32(
	    (2 * word_count) + sizeof(struct smb_hdr) -
	    (2 * word_count) + sizeof(struct smb_hdr) -
	    4 /*  RFC 1001 length field does not count */  +
	    4 /*  RFC 1001 length field does not count */  +
	    2 /* for bcc field itself */ ;
	    2 /* for bcc field itself */) ;
	/* Note that this is the only network field that has to be converted
	   to big endian and it is done just before we send it */


	buffer->Protocol[0] = 0xFF;
	buffer->Protocol[0] = 0xFF;
	buffer->Protocol[1] = 'S';
	buffer->Protocol[1] = 'S';
@@ -424,7 +422,7 @@ check_smb_hdr(struct smb_hdr *smb, __u16 mid)
int
int
checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
{
{
	__u32 len = smb->smb_buf_length;
	__u32 len = be32_to_cpu(smb->smb_buf_length);
	__u32 clc_len;  /* calculated length */
	__u32 clc_len;  /* calculated length */
	cFYI(0, "checkSMB Length: 0x%x, smb_buf_length: 0x%x", length, len);
	cFYI(0, "checkSMB Length: 0x%x, smb_buf_length: 0x%x", length, len);


Loading