@@ -581,7 +581,7 @@ SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
581581	rc  =  SMB2_ioctl (xid , tcon , NO_FILE_ID , NO_FILE_ID ,
582582			FSCTL_QUERY_NETWORK_INTERFACE_INFO , true /* is_fsctl */ ,
583583			NULL  /* no data input */ , 0  /* no data input */ ,
584- 			(char  * * )& out_buf , & ret_data_len );
584+ 			CIFSMaxBufSize ,  (char  * * )& out_buf , & ret_data_len );
585585	if  (rc  ==  - EOPNOTSUPP ) {
586586		cifs_dbg (FYI ,
587587			 "server does not support query network interfaces\n" );
@@ -1297,7 +1297,7 @@ SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
12971297
12981298	rc  =  SMB2_ioctl (xid , tcon , persistent_fid , volatile_fid ,
12991299			FSCTL_SRV_REQUEST_RESUME_KEY , true /* is_fsctl */ ,
1300- 			NULL , 0  /* no input */ ,
1300+ 			NULL , 0  /* no input */ ,  CIFSMaxBufSize , 
13011301			(char  * * )& res_key , & ret_data_len );
13021302
13031303	if  (rc ) {
@@ -1402,7 +1402,7 @@ smb2_ioctl_query_info(const unsigned int xid,
14021402			rc  =  SMB2_ioctl_init (tcon , & rqst [1 ],
14031403					     COMPOUND_FID , COMPOUND_FID ,
14041404					     qi .info_type , true, NULL ,
1405- 					     0 );
1405+ 					     0 ,  CIFSMaxBufSize );
14061406		}
14071407	} else  if  (qi .flags  ==  PASSTHRU_QUERY_INFO ) {
14081408		memset (& qi_iov , 0 , sizeof (qi_iov ));
@@ -1530,8 +1530,8 @@ smb2_copychunk_range(const unsigned int xid,
15301530		rc  =  SMB2_ioctl (xid , tcon , trgtfile -> fid .persistent_fid ,
15311531			trgtfile -> fid .volatile_fid , FSCTL_SRV_COPYCHUNK_WRITE ,
15321532			true /* is_fsctl */ , (char  * )pcchunk ,
1533- 			sizeof (struct  copychunk_ioctl ),	( char   * * ) & retbuf ,
1534- 			& ret_data_len );
1533+ 			sizeof (struct  copychunk_ioctl ),	CIFSMaxBufSize ,
1534+ 			( char   * * ) & retbuf ,  & ret_data_len );
15351535		if  (rc  ==  0 ) {
15361536			if  (ret_data_len  != 
15371537					sizeof (struct  copychunk_ioctl_rsp )) {
@@ -1691,7 +1691,7 @@ static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
16911691	rc  =  SMB2_ioctl (xid , tcon , cfile -> fid .persistent_fid ,
16921692			cfile -> fid .volatile_fid , FSCTL_SET_SPARSE ,
16931693			true /* is_fctl */ ,
1694- 			& setsparse , 1 , NULL , NULL );
1694+ 			& setsparse , 1 , CIFSMaxBufSize ,  NULL , NULL );
16951695	if  (rc ) {
16961696		tcon -> broken_sparse_sup  =  true;
16971697		cifs_dbg (FYI , "set sparse rc = %d\n" , rc );
@@ -1764,7 +1764,7 @@ smb2_duplicate_extents(const unsigned int xid,
17641764			true /* is_fsctl */ ,
17651765			(char  * )& dup_ext_buf ,
17661766			sizeof (struct  duplicate_extents_to_file ),
1767- 			NULL ,
1767+ 			CIFSMaxBufSize ,  NULL ,
17681768			& ret_data_len );
17691769
17701770	if  (ret_data_len  >  0 )
@@ -1799,14 +1799,16 @@ smb3_set_integrity(const unsigned int xid, struct cifs_tcon *tcon,
17991799			true /* is_fsctl */ ,
18001800			(char  * )& integr_info ,
18011801			sizeof (struct  fsctl_set_integrity_information_req ),
1802- 			NULL ,
1802+ 			CIFSMaxBufSize ,  NULL ,
18031803			& ret_data_len );
18041804
18051805}
18061806
18071807/* GMT Token is @GMT-YYYY.MM.DD-HH.MM.SS Unicode which is 48 bytes + null */ 
18081808#define  GMT_TOKEN_SIZE  50
18091809
1810+ #define  MIN_SNAPSHOT_ARRAY_SIZE  16 /* See MS-SMB2 section 3.3.5.15.1 */ 
1811+ 
18101812/* 
18111813 * Input buffer contains (empty) struct smb_snapshot array with size filled in 
18121814 * For output see struct SRV_SNAPSHOT_ARRAY in MS-SMB2 section 2.2.32.2 
@@ -1818,13 +1820,29 @@ smb3_enum_snapshots(const unsigned int xid, struct cifs_tcon *tcon,
18181820	char  * retbuf  =  NULL ;
18191821	unsigned int   ret_data_len  =  0 ;
18201822	int  rc ;
1823+ 	u32  max_response_size ;
18211824	struct  smb_snapshot_array  snapshot_in ;
18221825
1826+ 	if  (get_user (ret_data_len , (unsigned int   __user  * )ioc_buf ))
1827+ 		return  - EFAULT ;
1828+ 
1829+ 	/* 
1830+ 	 * Note that for snapshot queries that servers like Azure expect that 
1831+ 	 * the first query be minimal size (and just used to get the number/size 
1832+ 	 * of previous versions) so response size must be specified as EXACTLY 
1833+ 	 * sizeof(struct snapshot_array) which is 16 when rounded up to multiple 
1834+ 	 * of eight bytes. 
1835+ 	 */ 
1836+ 	if  (ret_data_len  ==  0 )
1837+ 		max_response_size  =  MIN_SNAPSHOT_ARRAY_SIZE ;
1838+ 	else 
1839+ 		max_response_size  =  CIFSMaxBufSize ;
1840+ 
18231841	rc  =  SMB2_ioctl (xid , tcon , cfile -> fid .persistent_fid ,
18241842			cfile -> fid .volatile_fid ,
18251843			FSCTL_SRV_ENUMERATE_SNAPSHOTS ,
18261844			true /* is_fsctl */ ,
1827- 			NULL , 0  /* no input data */ ,
1845+ 			NULL , 0  /* no input data */ ,  max_response_size , 
18281846			(char  * * )& retbuf ,
18291847			& ret_data_len );
18301848	cifs_dbg (FYI , "enum snaphots ioctl returned %d and ret buflen is %d\n" ,
@@ -2302,7 +2320,7 @@ smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
23022320		rc  =  SMB2_ioctl (xid , tcon , NO_FILE_ID , NO_FILE_ID ,
23032321				FSCTL_DFS_GET_REFERRALS ,
23042322				true /* is_fsctl */ ,
2305- 				(char  * )dfs_req , dfs_req_size ,
2323+ 				(char  * )dfs_req , dfs_req_size ,  CIFSMaxBufSize , 
23062324				(char  * * )& dfs_rsp , & dfs_rsp_size );
23072325	} while  (rc  ==  - EAGAIN );
23082326
@@ -2656,7 +2674,8 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
26562674	rc  =  SMB2_ioctl_init (tcon , & rqst [num ++ ], cfile -> fid .persistent_fid ,
26572675			     cfile -> fid .volatile_fid , FSCTL_SET_ZERO_DATA ,
26582676			     true /* is_fctl */ , (char  * )& fsctl_buf ,
2659- 			     sizeof (struct  file_zero_data_information ));
2677+ 			     sizeof (struct  file_zero_data_information ),
2678+ 			     CIFSMaxBufSize );
26602679	if  (rc )
26612680		goto zero_range_exit ;
26622681
@@ -2733,7 +2752,8 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
27332752	rc  =  SMB2_ioctl (xid , tcon , cfile -> fid .persistent_fid ,
27342753			cfile -> fid .volatile_fid , FSCTL_SET_ZERO_DATA ,
27352754			true /* is_fctl */ , (char  * )& fsctl_buf ,
2736- 			sizeof (struct  file_zero_data_information ), NULL , NULL );
2755+ 			sizeof (struct  file_zero_data_information ),
2756+ 			CIFSMaxBufSize , NULL , NULL );
27372757	free_xid (xid );
27382758	return  rc ;
27392759}
0 commit comments