aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/cifssmb.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2011-05-04 08:05:26 -0400
committerSteve French <sfrench@us.ibm.com>2011-05-19 10:10:53 -0400
commit820a803ffac3ef591e597bc107f8e289a823a29c (patch)
tree246451259a7efc5027647de639a69cb121b889e0 /fs/cifs/cifssmb.c
parent0e6e37a7a81f370d9aafafdf88aca13977f6fb5f (diff)
cifs: keep BCC in little-endian format
This is the same patch as originally posted, just with some merge conflicts fixed up... Currently, the ByteCount is usually converted to host-endian on receive. This is confusing however, as we need to keep two sets of routines for accessing it, and keep track of when to use each routine. Munging received packets like this also limits when the signature can be calulated. Simplify the code by keeping the received ByteCount in little-endian format. This allows us to eliminate a set of routines for accessing it and we can now drop the *_le suffixes from the accessor functions since that's now implied. While we're at it, switch all of the places that read the ByteCount directly to use the get_bcc inline which should also clean up some unaligned accesses. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs/cifs/cifssmb.c')
-rw-r--r--fs/cifs/cifssmb.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 88004094ebd1..83df937b814e 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -582,7 +582,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
582 582
583 if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) && 583 if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) &&
584 (server->capabilities & CAP_EXTENDED_SECURITY)) { 584 (server->capabilities & CAP_EXTENDED_SECURITY)) {
585 count = pSMBr->ByteCount; 585 count = get_bcc(&pSMBr->hdr);
586 if (count < 16) { 586 if (count < 16) {
587 rc = -EIO; 587 rc = -EIO;
588 goto neg_err_exit; 588 goto neg_err_exit;
@@ -736,7 +736,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
736 smb->hdr.Tid = 0xffff; 736 smb->hdr.Tid = 0xffff;
737 smb->hdr.WordCount = 1; 737 smb->hdr.WordCount = 1;
738 put_unaligned_le16(1, &smb->EchoCount); 738 put_unaligned_le16(1, &smb->EchoCount);
739 put_bcc_le(1, &smb->hdr); 739 put_bcc(1, &smb->hdr);
740 smb->Data[0] = 'a'; 740 smb->Data[0] = 'a';
741 inc_rfc1001_len(smb, 3); 741 inc_rfc1001_len(smb, 3);
742 742
@@ -1079,7 +1079,7 @@ PsxCreat:
1079 cFYI(1, "copying inode info"); 1079 cFYI(1, "copying inode info");
1080 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 1080 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
1081 1081
1082 if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) { 1082 if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) {
1083 rc = -EIO; /* bad smb */ 1083 rc = -EIO; /* bad smb */
1084 goto psx_create_err; 1084 goto psx_create_err;
1085 } 1085 }
@@ -1100,7 +1100,7 @@ PsxCreat:
1100 pRetData->Type = cpu_to_le32(-1); /* unknown */ 1100 pRetData->Type = cpu_to_le32(-1); /* unknown */
1101 cFYI(DBG2, "unknown type"); 1101 cFYI(DBG2, "unknown type");
1102 } else { 1102 } else {
1103 if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) 1103 if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)
1104 + sizeof(FILE_UNIX_BASIC_INFO)) { 1104 + sizeof(FILE_UNIX_BASIC_INFO)) {
1105 cERROR(1, "Open response data too small"); 1105 cERROR(1, "Open response data too small");
1106 pRetData->Type = cpu_to_le32(-1); 1106 pRetData->Type = cpu_to_le32(-1);
@@ -1867,7 +1867,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
1867 __u16 data_count; 1867 __u16 data_count;
1868 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 1868 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
1869 1869
1870 if (rc || (pSMBr->ByteCount < sizeof(struct cifs_posix_lock))) { 1870 if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) {
1871 rc = -EIO; /* bad smb */ 1871 rc = -EIO; /* bad smb */
1872 goto plk_err_exit; 1872 goto plk_err_exit;
1873 } 1873 }
@@ -2494,7 +2494,7 @@ querySymLinkRetry:
2494 2494
2495 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 2495 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
2496 /* BB also check enough total bytes returned */ 2496 /* BB also check enough total bytes returned */
2497 if (rc || (pSMBr->ByteCount < 2)) 2497 if (rc || get_bcc(&pSMBr->hdr) < 2)
2498 rc = -EIO; 2498 rc = -EIO;
2499 else { 2499 else {
2500 bool is_unicode; 2500 bool is_unicode;
@@ -2576,14 +2576,14 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
2576 } else { /* decode response */ 2576 } else { /* decode response */
2577 __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); 2577 __u32 data_offset = le32_to_cpu(pSMBr->DataOffset);
2578 __u32 data_count = le32_to_cpu(pSMBr->DataCount); 2578 __u32 data_count = le32_to_cpu(pSMBr->DataCount);
2579 if ((pSMBr->ByteCount < 2) || (data_offset > 512)) { 2579 if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) {
2580 /* BB also check enough total bytes returned */ 2580 /* BB also check enough total bytes returned */
2581 rc = -EIO; /* bad smb */ 2581 rc = -EIO; /* bad smb */
2582 goto qreparse_out; 2582 goto qreparse_out;
2583 } 2583 }
2584 if (data_count && (data_count < 2048)) { 2584 if (data_count && (data_count < 2048)) {
2585 char *end_of_smb = 2 /* sizeof byte count */ + 2585 char *end_of_smb = 2 /* sizeof byte count */ +
2586 pSMBr->ByteCount + (char *)&pSMBr->ByteCount; 2586 get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount;
2587 2587
2588 struct reparse_data *reparse_buf = 2588 struct reparse_data *reparse_buf =
2589 (struct reparse_data *) 2589 (struct reparse_data *)
@@ -2841,8 +2841,8 @@ queryAclRetry:
2841 /* decode response */ 2841 /* decode response */
2842 2842
2843 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 2843 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
2844 if (rc || (pSMBr->ByteCount < 2))
2845 /* BB also check enough total bytes returned */ 2844 /* BB also check enough total bytes returned */
2845 if (rc || get_bcc(&pSMBr->hdr) < 2)
2846 rc = -EIO; /* bad smb */ 2846 rc = -EIO; /* bad smb */
2847 else { 2847 else {
2848 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 2848 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -2991,8 +2991,8 @@ GetExtAttrRetry:
2991 } else { 2991 } else {
2992 /* decode response */ 2992 /* decode response */
2993 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 2993 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
2994 if (rc || (pSMBr->ByteCount < 2))
2995 /* BB also check enough total bytes returned */ 2994 /* BB also check enough total bytes returned */
2995 if (rc || get_bcc(&pSMBr->hdr) < 2)
2996 /* If rc should we check for EOPNOSUPP and 2996 /* If rc should we check for EOPNOSUPP and
2997 disable the srvino flag? or in caller? */ 2997 disable the srvino flag? or in caller? */
2998 rc = -EIO; /* bad smb */ 2998 rc = -EIO; /* bad smb */
@@ -3067,6 +3067,7 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
3067 char *end_of_smb; 3067 char *end_of_smb;
3068 __u32 data_count, data_offset, parm_count, parm_offset; 3068 __u32 data_count, data_offset, parm_count, parm_offset;
3069 struct smb_com_ntransact_rsp *pSMBr; 3069 struct smb_com_ntransact_rsp *pSMBr;
3070 u16 bcc;
3070 3071
3071 *pdatalen = 0; 3072 *pdatalen = 0;
3072 *pparmlen = 0; 3073 *pparmlen = 0;
@@ -3076,8 +3077,8 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
3076 3077
3077 pSMBr = (struct smb_com_ntransact_rsp *)buf; 3078 pSMBr = (struct smb_com_ntransact_rsp *)buf;
3078 3079
3079 /* ByteCount was converted from little endian in SendReceive */ 3080 bcc = get_bcc(&pSMBr->hdr);
3080 end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount + 3081 end_of_smb = 2 /* sizeof byte count */ + bcc +
3081 (char *)&pSMBr->ByteCount; 3082 (char *)&pSMBr->ByteCount;
3082 3083
3083 data_offset = le32_to_cpu(pSMBr->DataOffset); 3084 data_offset = le32_to_cpu(pSMBr->DataOffset);
@@ -3103,7 +3104,7 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
3103 *ppdata, data_count, (data_count + *ppdata), 3104 *ppdata, data_count, (data_count + *ppdata),
3104 end_of_smb, pSMBr); 3105 end_of_smb, pSMBr);
3105 return -EINVAL; 3106 return -EINVAL;
3106 } else if (parm_count + data_count > pSMBr->ByteCount) { 3107 } else if (parm_count + data_count > bcc) {
3107 cFYI(1, "parm count and data count larger than SMB"); 3108 cFYI(1, "parm count and data count larger than SMB");
3108 return -EINVAL; 3109 return -EINVAL;
3109 } 3110 }
@@ -3389,7 +3390,7 @@ QFileInfoRetry:
3389 3390
3390 if (rc) /* BB add auto retry on EOPNOTSUPP? */ 3391 if (rc) /* BB add auto retry on EOPNOTSUPP? */
3391 rc = -EIO; 3392 rc = -EIO;
3392 else if (pSMBr->ByteCount < 40) 3393 else if (get_bcc(&pSMBr->hdr) < 40)
3393 rc = -EIO; /* bad smb */ 3394 rc = -EIO; /* bad smb */
3394 else if (pFindData) { 3395 else if (pFindData) {
3395 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 3396 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -3477,9 +3478,9 @@ QPathInfoRetry:
3477 3478
3478 if (rc) /* BB add auto retry on EOPNOTSUPP? */ 3479 if (rc) /* BB add auto retry on EOPNOTSUPP? */
3479 rc = -EIO; 3480 rc = -EIO;
3480 else if (!legacy && (pSMBr->ByteCount < 40)) 3481 else if (!legacy && get_bcc(&pSMBr->hdr) < 40)
3481 rc = -EIO; /* bad smb */ 3482 rc = -EIO; /* bad smb */
3482 else if (legacy && (pSMBr->ByteCount < 24)) 3483 else if (legacy && get_bcc(&pSMBr->hdr) < 24)
3483 rc = -EIO; /* 24 or 26 expected but we do not read 3484 rc = -EIO; /* 24 or 26 expected but we do not read
3484 last field */ 3485 last field */
3485 else if (pFindData) { 3486 else if (pFindData) {
@@ -3555,7 +3556,7 @@ UnixQFileInfoRetry:
3555 } else { /* decode response */ 3556 } else { /* decode response */
3556 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 3557 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
3557 3558
3558 if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { 3559 if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) {
3559 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" 3560 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
3560 "Unix Extensions can be disabled on mount " 3561 "Unix Extensions can be disabled on mount "
3561 "by specifying the nosfu mount option."); 3562 "by specifying the nosfu mount option.");
@@ -3641,7 +3642,7 @@ UnixQPathInfoRetry:
3641 } else { /* decode response */ 3642 } else { /* decode response */
3642 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 3643 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
3643 3644
3644 if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { 3645 if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) {
3645 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" 3646 cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
3646 "Unix Extensions can be disabled on mount " 3647 "Unix Extensions can be disabled on mount "
3647 "by specifying the nosfu mount option."); 3648 "by specifying the nosfu mount option.");
@@ -4046,8 +4047,8 @@ GetInodeNumberRetry:
4046 } else { 4047 } else {
4047 /* decode response */ 4048 /* decode response */
4048 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4049 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4049 if (rc || (pSMBr->ByteCount < 2))
4050 /* BB also check enough total bytes returned */ 4050 /* BB also check enough total bytes returned */
4051 if (rc || get_bcc(&pSMBr->hdr) < 2)
4051 /* If rc should we check for EOPNOSUPP and 4052 /* If rc should we check for EOPNOSUPP and
4052 disable the srvino flag? or in caller? */ 4053 disable the srvino flag? or in caller? */
4053 rc = -EIO; /* bad smb */ 4054 rc = -EIO; /* bad smb */
@@ -4272,13 +4273,13 @@ getDFSRetry:
4272 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4273 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4273 4274
4274 /* BB Also check if enough total bytes returned? */ 4275 /* BB Also check if enough total bytes returned? */
4275 if (rc || (pSMBr->ByteCount < 17)) { 4276 if (rc || get_bcc(&pSMBr->hdr) < 17) {
4276 rc = -EIO; /* bad smb */ 4277 rc = -EIO; /* bad smb */
4277 goto GetDFSRefExit; 4278 goto GetDFSRefExit;
4278 } 4279 }
4279 4280
4280 cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", 4281 cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d",
4281 pSMBr->ByteCount, 4282 get_bcc(&pSMBr->hdr),
4282 le16_to_cpu(pSMBr->t2.DataOffset)); 4283 le16_to_cpu(pSMBr->t2.DataOffset));
4283 4284
4284 /* parse returned result into more usable form */ 4285 /* parse returned result into more usable form */
@@ -4344,12 +4345,12 @@ oldQFSInfoRetry:
4344 } else { /* decode response */ 4345 } else { /* decode response */
4345 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4346 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4346 4347
4347 if (rc || (pSMBr->ByteCount < 18)) 4348 if (rc || get_bcc(&pSMBr->hdr) < 18)
4348 rc = -EIO; /* bad smb */ 4349 rc = -EIO; /* bad smb */
4349 else { 4350 else {
4350 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 4351 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
4351 cFYI(1, "qfsinf resp BCC: %d Offset %d", 4352 cFYI(1, "qfsinf resp BCC: %d Offset %d",
4352 pSMBr->ByteCount, data_offset); 4353 get_bcc(&pSMBr->hdr), data_offset);
4353 4354
4354 response_data = (FILE_SYSTEM_ALLOC_INFO *) 4355 response_data = (FILE_SYSTEM_ALLOC_INFO *)
4355 (((char *) &pSMBr->hdr.Protocol) + data_offset); 4356 (((char *) &pSMBr->hdr.Protocol) + data_offset);
@@ -4423,7 +4424,7 @@ QFSInfoRetry:
4423 } else { /* decode response */ 4424 } else { /* decode response */
4424 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4425 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4425 4426
4426 if (rc || (pSMBr->ByteCount < 24)) 4427 if (rc || get_bcc(&pSMBr->hdr) < 24)
4427 rc = -EIO; /* bad smb */ 4428 rc = -EIO; /* bad smb */
4428 else { 4429 else {
4429 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 4430 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -4503,7 +4504,7 @@ QFSAttributeRetry:
4503 } else { /* decode response */ 4504 } else { /* decode response */
4504 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4505 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4505 4506
4506 if (rc || (pSMBr->ByteCount < 13)) { 4507 if (rc || get_bcc(&pSMBr->hdr) < 13) {
4507 /* BB also check if enough bytes returned */ 4508 /* BB also check if enough bytes returned */
4508 rc = -EIO; /* bad smb */ 4509 rc = -EIO; /* bad smb */
4509 } else { 4510 } else {
@@ -4574,7 +4575,8 @@ QFSDeviceRetry:
4574 } else { /* decode response */ 4575 } else { /* decode response */
4575 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4576 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4576 4577
4577 if (rc || (pSMBr->ByteCount < sizeof(FILE_SYSTEM_DEVICE_INFO))) 4578 if (rc || get_bcc(&pSMBr->hdr) <
4579 sizeof(FILE_SYSTEM_DEVICE_INFO))
4578 rc = -EIO; /* bad smb */ 4580 rc = -EIO; /* bad smb */
4579 else { 4581 else {
4580 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 4582 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -4643,7 +4645,7 @@ QFSUnixRetry:
4643 } else { /* decode response */ 4645 } else { /* decode response */
4644 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4646 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4645 4647
4646 if (rc || (pSMBr->ByteCount < 13)) { 4648 if (rc || get_bcc(&pSMBr->hdr) < 13) {
4647 rc = -EIO; /* bad smb */ 4649 rc = -EIO; /* bad smb */
4648 } else { 4650 } else {
4649 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 4651 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -4788,7 +4790,7 @@ QFSPosixRetry:
4788 } else { /* decode response */ 4790 } else { /* decode response */
4789 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4791 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4790 4792
4791 if (rc || (pSMBr->ByteCount < 13)) { 4793 if (rc || get_bcc(&pSMBr->hdr) < 13) {
4792 rc = -EIO; /* bad smb */ 4794 rc = -EIO; /* bad smb */
4793 } else { 4795 } else {
4794 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 4796 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -5517,7 +5519,7 @@ QAllEAsRetry:
5517 of these trans2 responses */ 5519 of these trans2 responses */
5518 5520
5519 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 5521 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
5520 if (rc || (pSMBr->ByteCount < 4)) { 5522 if (rc || get_bcc(&pSMBr->hdr) < 4) {
5521 rc = -EIO; /* bad smb */ 5523 rc = -EIO; /* bad smb */
5522 goto QAllEAsOut; 5524 goto QAllEAsOut;
5523 } 5525 }