Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cifs: update calc_size to take a server argument

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>

authored by

Ronnie Sahlberg and committed by
Steve French
9ec672bd 14547f7d

+16 -14
+1 -1
fs/cifs/cifsglob.h
··· 372 372 int (*close_dir)(const unsigned int, struct cifs_tcon *, 373 373 struct cifs_fid *); 374 374 /* calculate a size of SMB message */ 375 - unsigned int (*calc_smb_size)(void *); 375 + unsigned int (*calc_smb_size)(void *buf, struct TCP_Server_Info *ptcpi); 376 376 /* check for STATUS_PENDING and process it in a positive case */ 377 377 bool (*is_status_pending)(char *, struct TCP_Server_Info *, int); 378 378 /* check for STATUS_NETWORK_SESSION_EXPIRED */
+1 -1
fs/cifs/cifsproto.h
··· 124 124 unsigned int bytes_written); 125 125 extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); 126 126 extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); 127 - extern unsigned int smbCalcSize(void *buf); 127 + extern unsigned int smbCalcSize(void *buf, struct TCP_Server_Info *server); 128 128 extern int decode_negTokenInit(unsigned char *security_blob, int length, 129 129 struct TCP_Server_Info *server); 130 130 extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
+1 -1
fs/cifs/misc.c
··· 342 342 /* otherwise, there is enough to get to the BCC */ 343 343 if (check_smb_hdr(smb)) 344 344 return -EIO; 345 - clc_len = smbCalcSize(smb); 345 + clc_len = smbCalcSize(smb, server); 346 346 347 347 if (4 + rfclen != total_read) { 348 348 cifs_dbg(VFS, "Length read does not match RFC1001 length %d\n",
+1 -1
fs/cifs/netmisc.c
··· 903 903 * portion, the number of word parameters and the data portion of the message 904 904 */ 905 905 unsigned int 906 - smbCalcSize(void *buf) 906 + smbCalcSize(void *buf, struct TCP_Server_Info *server) 907 907 { 908 908 struct smb_hdr *ptr = (struct smb_hdr *)buf; 909 909 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
+4 -2
fs/cifs/readdir.c
··· 650 650 char *cur_ent; 651 651 char *end_of_smb = cfile->srch_inf.ntwrk_buf_start + 652 652 server->ops->calc_smb_size( 653 - cfile->srch_inf.ntwrk_buf_start); 653 + cfile->srch_inf.ntwrk_buf_start, 654 + server); 654 655 655 656 cur_ent = cfile->srch_inf.srch_entries_start; 656 657 first_entry_in_buffer = cfile->srch_inf.index_of_last_entry ··· 832 831 cifs_dbg(FYI, "loop through %d times filling dir for net buf %p\n", 833 832 num_to_fill, cifsFile->srch_inf.ntwrk_buf_start); 834 833 max_len = tcon->ses->server->ops->calc_smb_size( 835 - cifsFile->srch_inf.ntwrk_buf_start); 834 + cifsFile->srch_inf.ntwrk_buf_start, 835 + tcon->ses->server); 836 836 end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len; 837 837 838 838 tmp_buf = kmalloc(UNICODE_NAME_MAX, GFP_KERNEL);
+7 -7
fs/cifs/smb2misc.c
··· 233 233 return 1; 234 234 } 235 235 236 - clc_len = smb2_calc_size(hdr); 236 + clc_len = smb2_calc_size(hdr, srvr); 237 237 238 238 #ifdef CONFIG_CIFS_SMB311 239 239 if (shdr->Command == SMB2_NEGOTIATE) ··· 403 403 * portion, the number of word parameters and the data portion of the message. 404 404 */ 405 405 unsigned int 406 - smb2_calc_size(void *buf) 406 + smb2_calc_size(void *buf, struct TCP_Server_Info *srvr) 407 407 { 408 408 struct smb2_pdu *pdu = (struct smb2_pdu *)buf; 409 409 struct smb2_hdr *hdr = &pdu->hdr; ··· 411 411 int offset; /* the offset from the beginning of SMB to data area */ 412 412 int data_length; /* the length of the variable length data area */ 413 413 /* Structure Size has already been checked to make sure it is 64 */ 414 - int len = 4 + le16_to_cpu(shdr->StructureSize); 414 + int len = srvr->vals->header_preamble_size + le16_to_cpu(shdr->StructureSize); 415 415 416 416 /* 417 417 * StructureSize2, ie length of fixed parameter area has already ··· 433 433 * so we must add one to the calculation (and 4 to account for 434 434 * the size of the RFC1001 hdr. 435 435 */ 436 - if (offset + 4 + 1 < len) { 437 - cifs_dbg(VFS, "data area offset %d overlaps SMB2 header %d\n", 438 - offset + 4 + 1, len); 436 + if (offset + srvr->vals->header_preamble_size + 1 < len) { 437 + cifs_dbg(VFS, "data area offset %zu overlaps SMB2 header %d\n", 438 + offset + srvr->vals->header_preamble_size + 1, len); 439 439 data_length = 0; 440 440 } else { 441 - len = 4 + offset + data_length; 441 + len = srvr->vals->header_preamble_size + offset + data_length; 442 442 } 443 443 } 444 444 calc_size_exit:
+1 -1
fs/cifs/smb2proto.h
··· 36 36 extern int map_smb2_to_linux_error(char *buf, bool log_err); 37 37 extern int smb2_check_message(char *buf, unsigned int length, 38 38 struct TCP_Server_Info *server); 39 - extern unsigned int smb2_calc_size(void *buf); 39 + extern unsigned int smb2_calc_size(void *buf, struct TCP_Server_Info *server); 40 40 extern char *smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr); 41 41 extern __le16 *cifs_convert_path_to_utf16(const char *from, 42 42 struct cifs_sb_info *cifs_sb);