@@ -582,7 +582,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
582582
583583 if ((pSMBr -> hdr .Flags2 & SMBFLG2_EXT_SEC ) &&
584584 (server -> capabilities & CAP_EXTENDED_SECURITY )) {
585- count = pSMBr -> ByteCount ;
585+ count = get_bcc ( & pSMBr -> hdr ) ;
586586 if (count < 16 ) {
587587 rc = - EIO ;
588588 goto neg_err_exit ;
@@ -736,7 +736,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
736736 smb -> hdr .Tid = 0xffff ;
737737 smb -> hdr .WordCount = 1 ;
738738 put_unaligned_le16 (1 , & smb -> EchoCount );
739- put_bcc_le (1 , & smb -> hdr );
739+ put_bcc (1 , & smb -> hdr );
740740 smb -> Data [0 ] = 'a' ;
741741 inc_rfc1001_len (smb , 3 );
742742
@@ -1079,7 +1079,7 @@ CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags,
10791079 cFYI (1 , "copying inode info" );
10801080 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
10811081
1082- if (rc || ( pSMBr -> ByteCount < sizeof (OPEN_PSX_RSP ) )) {
1082+ if (rc || get_bcc ( & pSMBr -> hdr ) < sizeof (OPEN_PSX_RSP )) {
10831083 rc = - EIO ; /* bad smb */
10841084 goto psx_create_err ;
10851085 }
@@ -1100,7 +1100,7 @@ CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags,
11001100 pRetData -> Type = cpu_to_le32 (-1 ); /* unknown */
11011101 cFYI (DBG2 , "unknown type" );
11021102 } else {
1103- if (pSMBr -> ByteCount < sizeof (OPEN_PSX_RSP )
1103+ if (get_bcc ( & pSMBr -> hdr ) < sizeof (OPEN_PSX_RSP )
11041104 + sizeof (FILE_UNIX_BASIC_INFO )) {
11051105 cERROR (1 , "Open response data too small" );
11061106 pRetData -> Type = cpu_to_le32 (-1 );
@@ -1867,7 +1867,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
18671867 __u16 data_count ;
18681868 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
18691869
1870- if (rc || ( pSMBr -> ByteCount < sizeof (struct cifs_posix_lock ) )) {
1870+ if (rc || get_bcc ( & pSMBr -> hdr ) < sizeof (* parm_data )) {
18711871 rc = - EIO ; /* bad smb */
18721872 goto plk_err_exit ;
18731873 }
@@ -2494,7 +2494,7 @@ CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon,
24942494
24952495 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
24962496 /* BB also check enough total bytes returned */
2497- if (rc || ( pSMBr -> ByteCount < 2 ) )
2497+ if (rc || get_bcc ( & pSMBr -> hdr ) < 2 )
24982498 rc = - EIO ;
24992499 else {
25002500 bool is_unicode ;
@@ -2576,14 +2576,14 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
25762576 } else { /* decode response */
25772577 __u32 data_offset = le32_to_cpu (pSMBr -> DataOffset );
25782578 __u32 data_count = le32_to_cpu (pSMBr -> DataCount );
2579- if (( pSMBr -> ByteCount < 2 ) || ( data_offset > 512 ) ) {
2580- /* BB also check enough total bytes returned */
2579+ if (get_bcc ( & pSMBr -> hdr ) < 2 || data_offset > 512 ) {
2580+ /* BB also check enough total bytes returned */
25812581 rc = - EIO ; /* bad smb */
25822582 goto qreparse_out ;
25832583 }
25842584 if (data_count && (data_count < 2048 )) {
25852585 char * end_of_smb = 2 /* sizeof byte count */ +
2586- pSMBr -> ByteCount + (char * )& pSMBr -> ByteCount ;
2586+ get_bcc ( & pSMBr -> hdr ) + (char * )& pSMBr -> ByteCount ;
25872587
25882588 struct reparse_data * reparse_buf =
25892589 (struct reparse_data * )
@@ -2841,8 +2841,8 @@ CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon,
28412841 /* decode response */
28422842
28432843 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
2844- if (rc || (pSMBr -> ByteCount < 2 ))
28452844 /* BB also check enough total bytes returned */
2845+ if (rc || get_bcc (& pSMBr -> hdr ) < 2 )
28462846 rc = - EIO ; /* bad smb */
28472847 else {
28482848 __u16 data_offset = le16_to_cpu (pSMBr -> t2 .DataOffset );
@@ -2991,8 +2991,8 @@ CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon,
29912991 } else {
29922992 /* decode response */
29932993 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
2994- if (rc || (pSMBr -> ByteCount < 2 ))
29952994 /* BB also check enough total bytes returned */
2995+ if (rc || get_bcc (& pSMBr -> hdr ) < 2 )
29962996 /* If rc should we check for EOPNOSUPP and
29972997 disable the srvino flag? or in caller? */
29982998 rc = - EIO ; /* bad smb */
@@ -3067,6 +3067,7 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
30673067 char * end_of_smb ;
30683068 __u32 data_count , data_offset , parm_count , parm_offset ;
30693069 struct smb_com_ntransact_rsp * pSMBr ;
3070+ u16 bcc ;
30703071
30713072 * pdatalen = 0 ;
30723073 * pparmlen = 0 ;
@@ -3076,8 +3077,8 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
30763077
30773078 pSMBr = (struct smb_com_ntransact_rsp * )buf ;
30783079
3079- /* ByteCount was converted from little endian in SendReceive */
3080- end_of_smb = 2 /* sizeof byte count */ + pSMBr -> ByteCount +
3080+ bcc = get_bcc ( & pSMBr -> hdr );
3081+ end_of_smb = 2 /* sizeof byte count */ + bcc +
30813082 (char * )& pSMBr -> ByteCount ;
30823083
30833084 data_offset = le32_to_cpu (pSMBr -> DataOffset );
@@ -3103,7 +3104,7 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
31033104 * ppdata , data_count , (data_count + * ppdata ),
31043105 end_of_smb , pSMBr );
31053106 return - EINVAL ;
3106- } else if (parm_count + data_count > pSMBr -> ByteCount ) {
3107+ } else if (parm_count + data_count > bcc ) {
31073108 cFYI (1 , "parm count and data count larger than SMB" );
31083109 return - EINVAL ;
31093110 }
@@ -3389,7 +3390,7 @@ CIFSSMBQFileInfo(const int xid, struct cifsTconInfo *tcon,
33893390
33903391 if (rc ) /* BB add auto retry on EOPNOTSUPP? */
33913392 rc = - EIO ;
3392- else if (pSMBr -> ByteCount < 40 )
3393+ else if (get_bcc ( & pSMBr -> hdr ) < 40 )
33933394 rc = - EIO ; /* bad smb */
33943395 else if (pFindData ) {
33953396 __u16 data_offset = le16_to_cpu (pSMBr -> t2 .DataOffset );
@@ -3477,9 +3478,9 @@ CIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon,
34773478
34783479 if (rc ) /* BB add auto retry on EOPNOTSUPP? */
34793480 rc = - EIO ;
3480- else if (!legacy && ( pSMBr -> ByteCount < 40 ) )
3481+ else if (!legacy && get_bcc ( & pSMBr -> hdr ) < 40 )
34813482 rc = - EIO ; /* bad smb */
3482- else if (legacy && ( pSMBr -> ByteCount < 24 ) )
3483+ else if (legacy && get_bcc ( & pSMBr -> hdr ) < 24 )
34833484 rc = - EIO ; /* 24 or 26 expected but we do not read
34843485 last field */
34853486 else if (pFindData ) {
@@ -3555,7 +3556,7 @@ CIFSSMBUnixQFileInfo(const int xid, struct cifsTconInfo *tcon,
35553556 } else { /* decode response */
35563557 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
35573558
3558- if (rc || ( pSMBr -> ByteCount < sizeof (FILE_UNIX_BASIC_INFO ) )) {
3559+ if (rc || get_bcc ( & pSMBr -> hdr ) < sizeof (FILE_UNIX_BASIC_INFO )) {
35593560 cERROR (1 , "Malformed FILE_UNIX_BASIC_INFO response.\n"
35603561 "Unix Extensions can be disabled on mount "
35613562 "by specifying the nosfu mount option." );
@@ -3641,7 +3642,7 @@ CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon,
36413642 } else { /* decode response */
36423643 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
36433644
3644- if (rc || ( pSMBr -> ByteCount < sizeof (FILE_UNIX_BASIC_INFO ) )) {
3645+ if (rc || get_bcc ( & pSMBr -> hdr ) < sizeof (FILE_UNIX_BASIC_INFO )) {
36453646 cERROR (1 , "Malformed FILE_UNIX_BASIC_INFO response.\n"
36463647 "Unix Extensions can be disabled on mount "
36473648 "by specifying the nosfu mount option." );
@@ -4046,8 +4047,8 @@ CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon,
40464047 } else {
40474048 /* decode response */
40484049 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
4049- if (rc || (pSMBr -> ByteCount < 2 ))
40504050 /* BB also check enough total bytes returned */
4051+ if (rc || get_bcc (& pSMBr -> hdr ) < 2 )
40514052 /* If rc should we check for EOPNOSUPP and
40524053 disable the srvino flag? or in caller? */
40534054 rc = - EIO ; /* bad smb */
@@ -4272,13 +4273,13 @@ CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses,
42724273 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
42734274
42744275 /* BB Also check if enough total bytes returned? */
4275- if (rc || ( pSMBr -> ByteCount < 17 ) ) {
4276+ if (rc || get_bcc ( & pSMBr -> hdr ) < 17 ) {
42764277 rc = - EIO ; /* bad smb */
42774278 goto GetDFSRefExit ;
42784279 }
42794280
42804281 cFYI (1 , "Decoding GetDFSRefer response BCC: %d Offset %d" ,
4281- pSMBr -> ByteCount ,
4282+ get_bcc ( & pSMBr -> hdr ) ,
42824283 le16_to_cpu (pSMBr -> t2 .DataOffset ));
42834284
42844285 /* parse returned result into more usable form */
@@ -4344,12 +4345,12 @@ SMBOldQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData)
43444345 } else { /* decode response */
43454346 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
43464347
4347- if (rc || ( pSMBr -> ByteCount < 18 ) )
4348+ if (rc || get_bcc ( & pSMBr -> hdr ) < 18 )
43484349 rc = - EIO ; /* bad smb */
43494350 else {
43504351 __u16 data_offset = le16_to_cpu (pSMBr -> t2 .DataOffset );
43514352 cFYI (1 , "qfsinf resp BCC: %d Offset %d" ,
4352- pSMBr -> ByteCount , data_offset );
4353+ get_bcc ( & pSMBr -> hdr ) , data_offset );
43534354
43544355 response_data = (FILE_SYSTEM_ALLOC_INFO * )
43554356 (((char * ) & pSMBr -> hdr .Protocol ) + data_offset );
@@ -4423,7 +4424,7 @@ CIFSSMBQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData)
44234424 } else { /* decode response */
44244425 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
44254426
4426- if (rc || ( pSMBr -> ByteCount < 24 ) )
4427+ if (rc || get_bcc ( & pSMBr -> hdr ) < 24 )
44274428 rc = - EIO ; /* bad smb */
44284429 else {
44294430 __u16 data_offset = le16_to_cpu (pSMBr -> t2 .DataOffset );
@@ -4503,7 +4504,7 @@ CIFSSMBQFSAttributeInfo(const int xid, struct cifsTconInfo *tcon)
45034504 } else { /* decode response */
45044505 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
45054506
4506- if (rc || ( pSMBr -> ByteCount < 13 ) ) {
4507+ if (rc || get_bcc ( & pSMBr -> hdr ) < 13 ) {
45074508 /* BB also check if enough bytes returned */
45084509 rc = - EIO ; /* bad smb */
45094510 } else {
@@ -4574,7 +4575,8 @@ CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon)
45744575 } else { /* decode response */
45754576 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
45764577
4577- if (rc || (pSMBr -> ByteCount < sizeof (FILE_SYSTEM_DEVICE_INFO )))
4578+ if (rc || get_bcc (& pSMBr -> hdr ) <
4579+ sizeof (FILE_SYSTEM_DEVICE_INFO ))
45784580 rc = - EIO ; /* bad smb */
45794581 else {
45804582 __u16 data_offset = le16_to_cpu (pSMBr -> t2 .DataOffset );
@@ -4643,7 +4645,7 @@ CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon)
46434645 } else { /* decode response */
46444646 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
46454647
4646- if (rc || ( pSMBr -> ByteCount < 13 ) ) {
4648+ if (rc || get_bcc ( & pSMBr -> hdr ) < 13 ) {
46474649 rc = - EIO ; /* bad smb */
46484650 } else {
46494651 __u16 data_offset = le16_to_cpu (pSMBr -> t2 .DataOffset );
@@ -4788,7 +4790,7 @@ CIFSSMBQFSPosixInfo(const int xid, struct cifsTconInfo *tcon,
47884790 } else { /* decode response */
47894791 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
47904792
4791- if (rc || ( pSMBr -> ByteCount < 13 ) ) {
4793+ if (rc || get_bcc ( & pSMBr -> hdr ) < 13 ) {
47924794 rc = - EIO ; /* bad smb */
47934795 } else {
47944796 __u16 data_offset = le16_to_cpu (pSMBr -> t2 .DataOffset );
@@ -5517,7 +5519,7 @@ CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon,
55175519 of these trans2 responses */
55185520
55195521 rc = validate_t2 ((struct smb_t2_rsp * )pSMBr );
5520- if (rc || ( pSMBr -> ByteCount < 4 ) ) {
5522+ if (rc || get_bcc ( & pSMBr -> hdr ) < 4 ) {
55215523 rc = - EIO ; /* bad smb */
55225524 goto QAllEAsOut ;
55235525 }
0 commit comments