Re: [PATCH] cifs: keep BCC in little-endian format (try #2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 4 May 2011 09:11:15 +0400
Pavel Shilovsky <piastryyy@xxxxxxxxx> wrote:

> 2011/4/29 Jeff Layton <jlayton@xxxxxxxxxx>:
> > This is the same patch as originally posted, just with some merge
> > conflicts fixed up for some patches that went late into 2.6.39.
> >
> > 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@xxxxxxxxxx>
> > Signed-off-by: Steve French <sfrench@xxxxxxxxxx>
> > ---
> > Âfs/cifs/cifs_debug.c | Â Â2 +-
> > Âfs/cifs/cifspdu.h  Â|  22 +----------------
> > Âfs/cifs/cifsproto.h Â| Â Â1 -
> > Âfs/cifs/cifssmb.c  Â|  61 +++++++++++++++++++++++++------------------------
> > Âfs/cifs/connect.c  Â|  Â4 +-
> > Âfs/cifs/misc.c    |  Â4 +-
> > Âfs/cifs/netmisc.c  Â|  Â7 -----
> > Âfs/cifs/sess.c    |  Â2 +-
> > Âfs/cifs/transport.c Â| Â 19 +--------------
> > Â9 files changed, 40 insertions(+), 82 deletions(-)
> >
> > diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
> > index 30d01bc..18f4272 100644
> > --- a/fs/cifs/cifs_debug.c
> > +++ b/fs/cifs/cifs_debug.c
> > @@ -63,7 +63,7 @@ void cifs_dump_detail(struct smb_hdr *smb)
> > Â Â Â ÂcERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
> > Â Â Â Â Â Â Â Â Âsmb->Command, smb->Status.CifsError,
> > Â Â Â Â Â Â Â Â Âsmb->Flags, smb->Flags2, smb->Mid, smb->Pid);
> > - Â Â Â cERROR(1, "smb buf %p len %d", smb, smbCalcSize_LE(smb));
> > + Â Â Â cERROR(1, "smb buf %p len %d", smb, smbCalcSize(smb));
> > Â}
> >
> >
> > diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
> > index b5c8cc5..e53c6b3 100644
> > --- a/fs/cifs/cifspdu.h
> > +++ b/fs/cifs/cifspdu.h
> > @@ -435,36 +435,18 @@ struct smb_hdr {
> > Â/* given a pointer to an smb_hdr retrieve the pointer to the byte area */
> > Â#define pByteArea(smb_var) (BCC(smb_var) + 2)
> >
> > -/* get the converted ByteCount for a SMB packet and return it */
> > -static inline __u16
> > -get_bcc(struct smb_hdr *hdr)
> > -{
> > - Â Â Â __u16 *bc_ptr = (__u16 *)BCC(hdr);
> > -
> > - Â Â Â return get_unaligned(bc_ptr);
> > -}
> > -
> > Â/* get the unconverted ByteCount for a SMB packet and return it */
> > Âstatic inline __u16
> > -get_bcc_le(struct smb_hdr *hdr)
> > +get_bcc(struct smb_hdr *hdr)
> > Â{
> > Â Â Â Â__le16 *bc_ptr = (__le16 *)BCC(hdr);
> >
> > Â Â Â Âreturn get_unaligned_le16(bc_ptr);
> > Â}
> >
> > -/* set the ByteCount for a SMB packet in host-byte order */
> > -static inline void
> > -put_bcc(__u16 count, struct smb_hdr *hdr)
> > -{
> > - Â Â Â __u16 *bc_ptr = (__u16 *)BCC(hdr);
> > -
> > - Â Â Â put_unaligned(count, bc_ptr);
> > -}
> > -
> > Â/* set the ByteCount for a SMB packet in little-endian */
> > Âstatic inline void
> > -put_bcc_le(__u16 count, struct smb_hdr *hdr)
> > +put_bcc(__u16 count, struct smb_hdr *hdr)
> > Â{
> > Â Â Â Â__le16 *bc_ptr = (__le16 *)BCC(hdr);
> >
> > diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
> > index 0e4e057..0cdf375 100644
> > --- a/fs/cifs/cifsproto.h
> > +++ b/fs/cifs/cifsproto.h
> > @@ -90,7 +90,6 @@ extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
> > Âextern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool);
> > Âextern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool);
> > Âextern unsigned int smbCalcSize(struct smb_hdr *ptr);
> > -extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
> > Âextern int decode_negTokenInit(unsigned char *security_blob, int length,
> > Â Â Â Â Â Â Â Â Â Â Â Âstruct TCP_Server_Info *server);
> > Âextern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
> > diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
> > index 2710f00..5ae00d5 100644
> > --- a/fs/cifs/cifssmb.c
> > +++ b/fs/cifs/cifssmb.c
> > @@ -575,7 +575,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
> >
> > Â Â Â Âif ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) &&
> > Â Â Â Â Â Â Â Â(server->capabilities & CAP_EXTENDED_SECURITY)) {
> > - Â Â Â Â Â Â Â count = pSMBr->ByteCount;
> > + Â Â Â Â Â Â Â count = get_bcc(&pSMBr->hdr);
> > Â Â Â Â Â Â Â Âif (count < 16) {
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO;
> > Â Â Â Â Â Â Â Â Â Â Â Âgoto neg_err_exit;
> > @@ -729,7 +729,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server)
> > Â Â Â Âsmb->hdr.Tid = 0xffff;
> > Â Â Â Âsmb->hdr.WordCount = 1;
> > Â Â Â Âput_unaligned_le16(1, &smb->EchoCount);
> > - Â Â Â put_bcc_le(1, &smb->hdr);
> > + Â Â Â put_bcc(1, &smb->hdr);
> > Â Â Â Âsmb->Data[0] = 'a';
> > Â Â Â Âsmb->hdr.smb_buf_length += 3;
> >
> > @@ -1072,7 +1072,7 @@ PsxCreat:
> > Â Â Â ÂcFYI(1, "copying inode info");
> > Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) {
> > + Â Â Â if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) {
> > Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Âgoto psx_create_err;
> > Â Â Â Â}
> > @@ -1093,7 +1093,7 @@ PsxCreat:
> > Â Â Â Â Â Â Â ÂpRetData->Type = cpu_to_le32(-1); /* unknown */
> > Â Â Â Â Â Â Â ÂcFYI(DBG2, "unknown type");
> > Â Â Â Â} else {
> > - Â Â Â Â Â Â Â if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP)
> > + Â Â Â Â Â Â Â if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â+ sizeof(FILE_UNIX_BASIC_INFO)) {
> > Â Â Â Â Â Â Â Â Â Â Â ÂcERROR(1, "Open response data too small");
> > Â Â Â Â Â Â Â Â Â Â Â ÂpRetData->Type = cpu_to_le32(-1);
> > @@ -1859,7 +1859,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
> > Â Â Â Â Â Â Â Â__u16 data_count;
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < sizeof(struct cifs_posix_lock))) {
> > + Â Â Â Â Â Â Â if (rc || (get_bcc(&pSMBr->hdr) < sizeof(struct cifs_posix_lock))) {
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Â Â Â Â Âgoto plk_err_exit;
> > Â Â Â Â Â Â Â Â}
> > @@ -2486,7 +2486,7 @@ querySymLinkRetry:
> >
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> > Â Â Â Â Â Â Â Â/* BB also check enough total bytes returned */
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 2))
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 2)
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO;
> > Â Â Â Â Â Â Â Âelse {
> > Â Â Â Â Â Â Â Â Â Â Â Âbool is_unicode;
> > @@ -2568,14 +2568,14 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Â__u32 data_offset = le32_to_cpu(pSMBr->DataOffset);
> > Â Â Â Â Â Â Â Â__u32 data_count = le32_to_cpu(pSMBr->DataCount);
> > - Â Â Â Â Â Â Â if ((pSMBr->ByteCount < 2) || (data_offset > 512)) {
> > - Â Â Â Â Â Â Â /* BB also check enough total bytes returned */
> > + Â Â Â Â Â Â Â if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) {
> > + Â Â Â Â Â Â Â Â Â Â Â /* BB also check enough total bytes returned */
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Â Â Â Â Âgoto qreparse_out;
> > Â Â Â Â Â Â Â Â}
> > Â Â Â Â Â Â Â Âif (data_count && (data_count < 2048)) {
> > Â Â Â Â Â Â Â Â Â Â Â Âchar *end_of_smb = 2 /* sizeof byte count */ +
> > - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pSMBr->ByteCount + (char *)&pSMBr->ByteCount;
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount;
> >
> > Â Â Â Â Â Â Â Â Â Â Â Âstruct reparse_data *reparse_buf =
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(struct reparse_data *)
> > @@ -2833,7 +2833,7 @@ queryAclRetry:
> > Â Â Â Â Â Â Â Â/* decode response */
> >
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 2))
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 2)
> > Â Â Â Â Â Â Â Â/* BB also check enough total bytes returned */
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Âelse {
> > @@ -2983,7 +2983,7 @@ GetExtAttrRetry:
> > Â Â Â Â} else {
> > Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 2))
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 2)
> > Â Â Â Â Â Â Â Â/* BB also check enough total bytes returned */
> > Â Â Â Â Â Â Â Â Â Â Â Â/* If rc should we check for EOPNOSUPP and
> > Â Â Â Â Â Â Â Â Â Â Â Â Â disable the srvino flag? or in caller? */
> > @@ -3059,6 +3059,7 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
> > Â Â Â Âchar *end_of_smb;
> > Â Â Â Â__u32 data_count, data_offset, parm_count, parm_offset;
> > Â Â Â Âstruct smb_com_ntransact_rsp *pSMBr;
> > + Â Â Â u16 bcc;
> >
> > Â Â Â Â*pdatalen = 0;
> > Â Â Â Â*pparmlen = 0;
> > @@ -3068,8 +3069,8 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
> >
> > Â Â Â ÂpSMBr = (struct smb_com_ntransact_rsp *)buf;
> >
> > - Â Â Â /* ByteCount was converted from little endian in SendReceive */
> > - Â Â Â end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount +
> > + Â Â Â bcc = get_bcc(&pSMBr->hdr);
> > + Â Â Â end_of_smb = 2 /* sizeof byte count */ + bcc +
> > Â Â Â Â Â Â Â Â Â Â Â Â(char *)&pSMBr->ByteCount;
> >
> > Â Â Â Âdata_offset = le32_to_cpu(pSMBr->DataOffset);
> > @@ -3095,7 +3096,7 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
> > Â Â Â Â Â Â Â Â Â Â Â Â*ppdata, data_count, (data_count + *ppdata),
> > Â Â Â Â Â Â Â Â Â Â Â Âend_of_smb, pSMBr);
> > Â Â Â Â Â Â Â Âreturn -EINVAL;
> > - Â Â Â } else if (parm_count + data_count > pSMBr->ByteCount) {
> > + Â Â Â } else if (parm_count + data_count > bcc) {
> > Â Â Â Â Â Â Â ÂcFYI(1, "parm count and data count larger than SMB");
> > Â Â Â Â Â Â Â Âreturn -EINVAL;
> > Â Â Â Â}
> > @@ -3382,7 +3383,7 @@ QFileInfoRetry:
> >
> > Â Â Â Â Â Â Â Âif (rc) /* BB add auto retry on EOPNOTSUPP? */
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO;
> > - Â Â Â Â Â Â Â else if (pSMBr->ByteCount < 40)
> > + Â Â Â Â Â Â Â else if (get_bcc(&pSMBr->hdr) < 40)
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Âelse if (pFindData) {
> > Â Â Â Â Â Â Â Â Â Â Â Â__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
> > @@ -3470,9 +3471,9 @@ QPathInfoRetry:
> >
> > Â Â Â Â Â Â Â Âif (rc) /* BB add auto retry on EOPNOTSUPP? */
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO;
> > - Â Â Â Â Â Â Â else if (!legacy && (pSMBr->ByteCount < 40))
> > + Â Â Â Â Â Â Â else if (!legacy && get_bcc(&pSMBr->hdr) < 40)
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > - Â Â Â Â Â Â Â else if (legacy && (pSMBr->ByteCount < 24))
> > + Â Â Â Â Â Â Â else if (legacy && get_bcc(&pSMBr->hdr) < 24)
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â/* 24 or 26 expected but we do not read
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âlast field */
> > Â Â Â Â Â Â Â Âelse if (pFindData) {
> > @@ -3548,7 +3549,7 @@ UnixQFileInfoRetry:
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) {
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) {
> > Â Â Â Â Â Â Â Â Â Â Â ÂcERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Unix Extensions can be disabled on mount "
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "by specifying the nosfu mount option.");
> > @@ -3634,7 +3635,7 @@ UnixQPathInfoRetry:
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) {
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) {
> > Â Â Â Â Â Â Â Â Â Â Â ÂcERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Unix Extensions can be disabled on mount "
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "by specifying the nosfu mount option.");
> > @@ -4039,7 +4040,7 @@ GetInodeNumberRetry:
> > Â Â Â Â} else {
> > Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 2))
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 2)
> > Â Â Â Â Â Â Â Â/* BB also check enough total bytes returned */
> > Â Â Â Â Â Â Â Â Â Â Â Â/* If rc should we check for EOPNOSUPP and
> > Â Â Â Â Â Â Â Â Â Â Â Âdisable the srvino flag? or in caller? */
> > @@ -4265,13 +4266,13 @@ getDFSRetry:
> > Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > Â Â Â Â/* BB Also check if enough total bytes returned? */
> > - Â Â Â if (rc || (pSMBr->ByteCount < 17)) {
> > + Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 17) {
> > Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Âgoto GetDFSRefExit;
> > Â Â Â Â}
> >
> > Â Â Â ÂcFYI(1, "Decoding GetDFSRefer response BCC: %d ÂOffset %d",
> > - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pSMBr->ByteCount,
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â get_bcc(&pSMBr->hdr),
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âle16_to_cpu(pSMBr->t2.DataOffset));
> >
> > Â Â Â Â/* parse returned result into more usable form */
> > @@ -4337,12 +4338,12 @@ oldQFSInfoRetry:
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 18))
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 18)
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Âelse {
> > Â Â Â Â Â Â Â Â Â Â Â Â__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
> > Â Â Â Â Â Â Â Â Â Â Â ÂcFYI(1, "qfsinf resp BCC: %d ÂOffset %d",
> > - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂpSMBr->ByteCount, data_offset);
> > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âget_bcc(&pSMBr->hdr), data_offset);
> >
> > Â Â Â Â Â Â Â Â Â Â Â Âresponse_data = (FILE_SYSTEM_ALLOC_INFO *)
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â(((char *) &pSMBr->hdr.Protocol) + data_offset);
> > @@ -4416,7 +4417,7 @@ QFSInfoRetry:
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 24))
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 24)
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Âelse {
> > Â Â Â Â Â Â Â Â Â Â Â Â__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
> > @@ -4496,7 +4497,7 @@ QFSAttributeRetry:
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 13)) {
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 13) {
> > Â Â Â Â Â Â Â Â Â Â Â Â/* BB also check if enough bytes returned */
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Â} else {
> > @@ -4567,7 +4568,7 @@ QFSDeviceRetry:
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < sizeof(FILE_SYSTEM_DEVICE_INFO)))
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_SYSTEM_DEVICE_INFO))
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Âelse {
> > Â Â Â Â Â Â Â Â Â Â Â Â__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
> > @@ -4636,7 +4637,7 @@ QFSUnixRetry:
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 13)) {
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 13) {
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Â} else {
> > Â Â Â Â Â Â Â Â Â Â Â Â__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
> > @@ -4781,7 +4782,7 @@ QFSPosixRetry:
> > Â Â Â Â} else { Â Â Â Â Â Â Â Â/* decode response */
> > Â Â Â Â Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> >
> > - Â Â Â Â Â Â Â if (rc || (pSMBr->ByteCount < 13)) {
> > + Â Â Â Â Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 13) {
> > Â Â Â Â Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Â} else {
> > Â Â Â Â Â Â Â Â Â Â Â Â__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
> > @@ -5510,7 +5511,7 @@ QAllEAsRetry:
> > Â Â Â Âof these trans2 responses */
> >
> > Â Â Â Ârc = validate_t2((struct smb_t2_rsp *)pSMBr);
> > - Â Â Â if (rc || (pSMBr->ByteCount < 4)) {
> > + Â Â Â if (rc || get_bcc(&pSMBr->hdr) < 4) {
> > Â Â Â Â Â Â Â Ârc = -EIO; Â Â Â/* bad smb */
> > Â Â Â Â Â Â Â Âgoto QAllEAsOut;
> > Â Â Â Â}
> > diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> > index 9d05d8f..68bd894 100644
> > --- a/fs/cifs/connect.c
> > +++ b/fs/cifs/connect.c
> > @@ -316,12 +316,12 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
> > Â Â Â Âput_unaligned_le16(total_in_buf, &pSMBt->t2_rsp.DataCount);
> >
> > Â Â Â Â/* fix up the BCC */
> > - Â Â Â byte_count = get_bcc_le(pTargetSMB);
> > + Â Â Â byte_count = get_bcc(pTargetSMB);
> > Â Â Â Âbyte_count += total_in_buf2;
> > Â Â Â Â/* is the result too big for the field? */
> > Â Â Â Âif (byte_count > USHRT_MAX)
> > Â Â Â Â Â Â Â Âreturn -EPROTO;
> > - Â Â Â put_bcc_le(byte_count, pTargetSMB);
> > + Â Â Â put_bcc(byte_count, pTargetSMB);
> >
> > Â Â Â Âbyte_count = pTargetSMB->smb_buf_length;
> > Â Â Â Âbyte_count += total_in_buf2;
> > diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
> > index 0c684ae..a0765e6 100644
> > --- a/fs/cifs/misc.c
> > +++ b/fs/cifs/misc.c
> > @@ -464,7 +464,7 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
> >
> > Â Â Â Âif (check_smb_hdr(smb, mid))
> > Â Â Â Â Â Â Â Âreturn 1;
> > - Â Â Â clc_len = smbCalcSize_LE(smb);
> > + Â Â Â clc_len = smbCalcSize(smb);
> >
> > Â Â Â Âif (4 + len != length) {
> > Â Â Â Â Â Â Â ÂcERROR(1, "Length read does not match RFC1001 length %d",
> > @@ -521,7 +521,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
> > Â Â Â Â Â Â Â Â Â Â Â Â(struct smb_com_transaction_change_notify_rsp *)buf;
> > Â Â Â Â Â Â Â Âstruct file_notify_information *pnotify;
> > Â Â Â Â Â Â Â Â__u32 data_offset = 0;
> > - Â Â Â Â Â Â Â if (get_bcc_le(buf) > sizeof(struct file_notify_information)) {
> > + Â Â Â Â Â Â Â if (get_bcc(buf) > sizeof(struct file_notify_information)) {
> > Â Â Â Â Â Â Â Â Â Â Â Âdata_offset = le32_to_cpu(pSMBr->DataOffset);
> >
> > Â Â Â Â Â Â Â Â Â Â Â Âpnotify = (struct file_notify_information *)
> > diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
> > index 79f641e..79b71c2 100644
> > --- a/fs/cifs/netmisc.c
> > +++ b/fs/cifs/netmisc.c
> > @@ -919,13 +919,6 @@ smbCalcSize(struct smb_hdr *ptr)
> > Â Â Â Â Â Â Â Â2 /* size of the bcc field */ + get_bcc(ptr));
> > Â}
> >
> > -unsigned int
> > -smbCalcSize_LE(struct smb_hdr *ptr)
> > -{
> > - Â Â Â return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
> > - Â Â Â Â Â Â Â 2 /* size of the bcc field */ + get_bcc_le(ptr));
> > -}
> > -
> > Â/* The following are taken from fs/ntfs/util.c */
> >
> > Â#define NTFS_TIME_OFFSET ((u64)(369*365 + 89) * 24 * 3600 * 10000000)
> > diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
> > index b6ff84a..74344ef 100644
> > --- a/fs/cifs/sess.c
> > +++ b/fs/cifs/sess.c
> > @@ -861,7 +861,7 @@ ssetup_ntlmssp_authenticate:
> > Â Â Â Âcount = iov[1].iov_len + iov[2].iov_len;
> > Â Â Â Âsmb_buf->smb_buf_length += count;
> >
> > - Â Â Â put_bcc_le(count, smb_buf);
> > + Â Â Â put_bcc(count, smb_buf);
> >
> > Â Â Â Ârc = SendReceive2(xid, ses, iov, 3 /* num_iovecs */, &resp_buf_type,
> > Â Â Â Â Â Â Â Â Â Â Â Â ÂCIFS_LOG_ERROR);
> > diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
> > index 46d8756..44f4f49 100644
> > --- a/fs/cifs/transport.c
> > +++ b/fs/cifs/transport.c
> > @@ -491,7 +491,7 @@ send_nt_cancel(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
> > Â Â Â Âin_buf->smb_buf_length = sizeof(struct smb_hdr) - 4 Â+ 2;
> > Â Â Â Âin_buf->Command = SMB_COM_NT_CANCEL;
> > Â Â Â Âin_buf->WordCount = 0;
> > - Â Â Â put_bcc_le(0, in_buf);
> > + Â Â Â put_bcc(0, in_buf);
> >
> > Â Â Â Âmutex_lock(&server->srv_mutex);
> > Â Â Â Ârc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
> > @@ -651,11 +651,6 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
> > Â Â Â Â Â Â Â Ârc = map_smb_to_linux_error(midQ->resp_buf,
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âflags & CIFS_LOG_ERROR);
> >
> > - Â Â Â Â Â Â Â /* convert ByteCount if necessary */
> > - Â Â Â Â Â Â Â if (receive_len >= sizeof(struct smb_hdr) - 4
> > - Â Â Â Â Â Â Â Â Â /* do not count RFC1001 header */ Â+
> > - Â Â Â Â Â Â Â Â Â (2 * midQ->resp_buf->WordCount) + 2 /* bcc */ )
> > - Â Â Â Â Â Â Â Â Â Â Â put_bcc(get_bcc_le(midQ->resp_buf), midQ->resp_buf);
> > Â Â Â Â Â Â Â Âif ((flags & CIFS_NO_RESP) == 0)
> > Â Â Â Â Â Â Â Â Â Â Â ÂmidQ->resp_buf = NULL; Â/* mark it so buf will
> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â not be freed by
> > @@ -804,12 +799,6 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
> >
> > Â Â Â Â Â Â Â Â/* BB special case reconnect tid and uid here? */
> > Â Â Â Â Â Â Â Ârc = map_smb_to_linux_error(out_buf, 0 /* no log */ );
> > -
> > - Â Â Â Â Â Â Â /* convert ByteCount if necessary */
> > - Â Â Â Â Â Â Â if (receive_len >= sizeof(struct smb_hdr) - 4
> > - Â Â Â Â Â Â Â Â Â /* do not count RFC1001 header */ Â+
> > - Â Â Â Â Â Â Â Â Â (2 * out_buf->WordCount) + 2 /* bcc */ )
> > - Â Â Â Â Â Â Â Â Â Â Â put_bcc(get_bcc_le(midQ->resp_buf), midQ->resp_buf);
> > Â Â Â Â} else {
> > Â Â Â Â Â Â Â Ârc = -EIO;
> > Â Â Â Â Â Â Â ÂcERROR(1, "Bad MID state?");
> > @@ -1017,12 +1006,6 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
> > Â Â Â Â/* BB special case reconnect tid and uid here? */
> > Â Â Â Ârc = map_smb_to_linux_error(out_buf, 0 /* no log */ );
> >
> > - Â Â Â /* convert ByteCount if necessary */
> > - Â Â Â if (receive_len >= sizeof(struct smb_hdr) - 4
> > - Â Â Â Â Â /* do not count RFC1001 header */ Â+
> > - Â Â Â Â Â (2 * out_buf->WordCount) + 2 /* bcc */ )
> > - Â Â Â Â Â Â Â put_bcc(get_bcc_le(out_buf), out_buf);
> > -
> > Âout:
> > Â Â Â Âdelete_mid(midQ);
> > Â Â Â Âif (rstart && rc == -EACCES)
> > --
> > 1.7.4.4
> 
> This patch has checkpatch warnings:
> WARNING: line over 80 characters
> #152: FILE: fs/cifs/cifssmb.c:1870:
> +		if (rc || (get_bcc(&pSMBr->hdr) < sizeof(struct cifs_posix_lock))) {
> 
> WARNING: line over 80 characters
> #179: FILE: fs/cifs/cifssmb.c:2586:
> +				get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount;
> 
> WARNING: suspect code indent for conditional statements (16, 16)
> #188: FILE: fs/cifs/cifssmb.c:2844:
> +		if (rc || get_bcc(&pSMBr->hdr) < 2)
>  		/* BB also check enough total bytes returned */
> 
> WARNING: suspect code indent for conditional statements (16, 16)
> #197: FILE: fs/cifs/cifssmb.c:2994:
> +		if (rc || get_bcc(&pSMBr->hdr) < 2)
>  		/* BB also check enough total bytes returned */
> 
> WARNING: suspect code indent for conditional statements (16, 16)
> #273: FILE: fs/cifs/cifssmb.c:4050:
> +		if (rc || get_bcc(&pSMBr->hdr) < 2)
>  		/* BB also check enough total bytes returned */
> 
> WARNING: line over 80 characters
> #331: FILE: fs/cifs/cifssmb.c:4578:
> +		if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_SYSTEM_DEVICE_INFO))
> 
> total: 0 errors, 6 warnings, 373 lines checked
> 

Bleh -- ok. Many of those problems preexist these changes but it's
probably worth fixing them. I'll respin the patch.

-- 
Jeff Layton <jlayton@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux