]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
cifs: update calc_size to take a server argument
authorRonnie Sahlberg <lsahlber@redhat.com>
Sun, 22 Apr 2018 21:30:12 +0000 (15:30 -0600)
committerSteve French <stfrench@microsoft.com>
Sun, 27 May 2018 22:56:35 +0000 (17:56 -0500)
and change the smb2 version to take heder_preamble_size into account
instead of hardcoding it as 4 bytes.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <smfrench@gmail.com>
fs/cifs/cifsglob.h
fs/cifs/cifsproto.h
fs/cifs/misc.c
fs/cifs/netmisc.c
fs/cifs/readdir.c
fs/cifs/smb2misc.c
fs/cifs/smb2proto.h

index 0e2b145aba46274526755633d4830427eceec87d..d71585025ef63a336f56d2dbd3cd89ed33dd0be3 100644 (file)
@@ -372,7 +372,7 @@ struct smb_version_operations {
        int (*close_dir)(const unsigned int, struct cifs_tcon *,
                         struct cifs_fid *);
        /* calculate a size of SMB message */
-       unsigned int (*calc_smb_size)(void *);
+       unsigned int (*calc_smb_size)(void *buf, struct TCP_Server_Info *ptcpi);
        /* check for STATUS_PENDING and process it in a positive case */
        bool (*is_status_pending)(char *, struct TCP_Server_Info *, int);
        /* check for STATUS_NETWORK_SESSION_EXPIRED */
index 365a414a75e9d145da7786fee5f501b229501c31..6c4da5de1ab58d506cb8d83ffb0c0878113d181c 100644 (file)
@@ -124,7 +124,7 @@ extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
                            unsigned int bytes_written);
 extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool);
 extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool);
-extern unsigned int smbCalcSize(void *buf);
+extern unsigned int smbCalcSize(void *buf, struct TCP_Server_Info *server);
 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);
index 247a59774b7f27bbbe06e134100a9b4edf5586d8..96849b530e3289629d5e6d8f611bec50c87c40c6 100644 (file)
@@ -342,7 +342,7 @@ checkSMB(char *buf, unsigned int total_read, struct TCP_Server_Info *server)
        /* otherwise, there is enough to get to the BCC */
        if (check_smb_hdr(smb))
                return -EIO;
-       clc_len = smbCalcSize(smb);
+       clc_len = smbCalcSize(smb, server);
 
        if (4 + rfclen != total_read) {
                cifs_dbg(VFS, "Length read does not match RFC1001 length %d\n",
index cc88f4f0325ef4003bd248c36ca96865ff1b4ddd..d7ad0dfe4e6873c46b8d2d7ee234611e7e33844c 100644 (file)
@@ -903,7 +903,7 @@ map_smb_to_linux_error(char *buf, bool logErr)
  * portion, the number of word parameters and the data portion of the message
  */
 unsigned int
-smbCalcSize(void *buf)
+smbCalcSize(void *buf, struct TCP_Server_Info *server)
 {
        struct smb_hdr *ptr = (struct smb_hdr *)buf;
        return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
index a27fc8791551cc86ca14d2d65e7870990a393f1e..eeab81c9452f86e61948198b0d938ea8b6a9a5dd 100644 (file)
@@ -650,7 +650,8 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,
                char *cur_ent;
                char *end_of_smb = cfile->srch_inf.ntwrk_buf_start +
                        server->ops->calc_smb_size(
-                                       cfile->srch_inf.ntwrk_buf_start);
+                                       cfile->srch_inf.ntwrk_buf_start,
+                                       server);
 
                cur_ent = cfile->srch_inf.srch_entries_start;
                first_entry_in_buffer = cfile->srch_inf.index_of_last_entry
@@ -831,7 +832,8 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
        cifs_dbg(FYI, "loop through %d times filling dir for net buf %p\n",
                 num_to_fill, cifsFile->srch_inf.ntwrk_buf_start);
        max_len = tcon->ses->server->ops->calc_smb_size(
-                       cifsFile->srch_inf.ntwrk_buf_start);
+                       cifsFile->srch_inf.ntwrk_buf_start,
+                       tcon->ses->server);
        end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
 
        tmp_buf = kmalloc(UNICODE_NAME_MAX, GFP_KERNEL);
index 68ea8491c160fd0ef8be0bb9953ce494158e7d75..f7f3ad76040150c7f540bc2acca7a33a774b433b 100644 (file)
@@ -233,7 +233,7 @@ smb2_check_message(char *buf, unsigned int length, struct TCP_Server_Info *srvr)
                return 1;
        }
 
-       clc_len = smb2_calc_size(hdr);
+       clc_len = smb2_calc_size(hdr, srvr);
 
 #ifdef CONFIG_CIFS_SMB311
        if (shdr->Command == SMB2_NEGOTIATE)
@@ -403,7 +403,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
  * portion, the number of word parameters and the data portion of the message.
  */
 unsigned int
-smb2_calc_size(void *buf)
+smb2_calc_size(void *buf, struct TCP_Server_Info *srvr)
 {
        struct smb2_pdu *pdu = (struct smb2_pdu *)buf;
        struct smb2_hdr *hdr = &pdu->hdr;
@@ -411,7 +411,7 @@ smb2_calc_size(void *buf)
        int offset; /* the offset from the beginning of SMB to data area */
        int data_length; /* the length of the variable length data area */
        /* Structure Size has already been checked to make sure it is 64 */
-       int len = 4 + le16_to_cpu(shdr->StructureSize);
+       int len = srvr->vals->header_preamble_size + le16_to_cpu(shdr->StructureSize);
 
        /*
         * StructureSize2, ie length of fixed parameter area has already
@@ -433,12 +433,12 @@ smb2_calc_size(void *buf)
                 * so we must add one to the calculation (and 4 to account for
                 * the size of the RFC1001 hdr.
                 */
-               if (offset + 4 + 1 < len) {
-                       cifs_dbg(VFS, "data area offset %d overlaps SMB2 header %d\n",
-                                offset + 4 + 1, len);
+               if (offset + srvr->vals->header_preamble_size + 1 < len) {
+                       cifs_dbg(VFS, "data area offset %zu overlaps SMB2 header %d\n",
+                                offset + srvr->vals->header_preamble_size + 1, len);
                        data_length = 0;
                } else {
-                       len = 4 + offset + data_length;
+                       len = srvr->vals->header_preamble_size + offset + data_length;
                }
        }
 calc_size_exit:
index 800270b729e2dfed730d14ebc56821fcbe3c3661..8d7bb9a1dcb4c8447007d172c41b3bd8cd4459cf 100644 (file)
@@ -36,7 +36,7 @@ struct smb_rqst;
 extern int map_smb2_to_linux_error(char *buf, bool log_err);
 extern int smb2_check_message(char *buf, unsigned int length,
                              struct TCP_Server_Info *server);
-extern unsigned int smb2_calc_size(void *buf);
+extern unsigned int smb2_calc_size(void *buf, struct TCP_Server_Info *server);
 extern char *smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr);
 extern __le16 *cifs_convert_path_to_utf16(const char *from,
                                          struct cifs_sb_info *cifs_sb);