@@ -471,10 +471,15 @@ static int __smb2_plain_req_init(__le16 smb2_command, struct cifs_tcon *tcon,
471471 void * * request_buf , unsigned int * total_len )
472472{
473473 /* BB eventually switch this to SMB2 specific small buf size */
474- if (smb2_command == SMB2_SET_INFO )
474+ switch (smb2_command ) {
475+ case SMB2_SET_INFO :
476+ case SMB2_QUERY_INFO :
475477 * request_buf = cifs_buf_get ();
476- else
478+ break ;
479+ default :
477480 * request_buf = cifs_small_buf_get ();
481+ break ;
482+ }
478483 if (* request_buf == NULL ) {
479484 /* BB should we add a retry in here if not a writepage? */
480485 return - ENOMEM ;
@@ -3587,8 +3592,13 @@ SMB2_query_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
35873592 struct smb2_query_info_req * req ;
35883593 struct kvec * iov = rqst -> rq_iov ;
35893594 unsigned int total_len ;
3595+ size_t len ;
35903596 int rc ;
35913597
3598+ if (unlikely (check_add_overflow (input_len , sizeof (* req ), & len ) ||
3599+ len > CIFSMaxBufSize ))
3600+ return - EINVAL ;
3601+
35923602 rc = smb2_plain_req_init (SMB2_QUERY_INFO , tcon , server ,
35933603 (void * * ) & req , & total_len );
35943604 if (rc )
@@ -3610,15 +3620,15 @@ SMB2_query_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
36103620
36113621 iov [0 ].iov_base = (char * )req ;
36123622 /* 1 for Buffer */
3613- iov [0 ].iov_len = total_len - 1 + input_len ;
3623+ iov [0 ].iov_len = len ;
36143624 return 0 ;
36153625}
36163626
36173627void
36183628SMB2_query_info_free (struct smb_rqst * rqst )
36193629{
36203630 if (rqst && rqst -> rq_iov )
3621- cifs_small_buf_release (rqst -> rq_iov [0 ].iov_base ); /* request */
3631+ cifs_buf_release (rqst -> rq_iov [0 ].iov_base ); /* request */
36223632}
36233633
36243634static int
@@ -5493,6 +5503,11 @@ build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon,
54935503 return 0 ;
54945504}
54955505
5506+ static inline void free_qfs_info_req (struct kvec * iov )
5507+ {
5508+ cifs_buf_release (iov -> iov_base );
5509+ }
5510+
54965511int
54975512SMB311_posix_qfs_info (const unsigned int xid , struct cifs_tcon * tcon ,
54985513 u64 persistent_fid , u64 volatile_fid , struct kstatfs * fsdata )
@@ -5524,7 +5539,7 @@ SMB311_posix_qfs_info(const unsigned int xid, struct cifs_tcon *tcon,
55245539
55255540 rc = cifs_send_recv (xid , ses , server ,
55265541 & rqst , & resp_buftype , flags , & rsp_iov );
5527- cifs_small_buf_release ( iov . iov_base );
5542+ free_qfs_info_req ( & iov );
55285543 if (rc ) {
55295544 cifs_stats_fail_inc (tcon , SMB2_QUERY_INFO_HE );
55305545 goto posix_qfsinf_exit ;
@@ -5575,7 +5590,7 @@ SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
55755590
55765591 rc = cifs_send_recv (xid , ses , server ,
55775592 & rqst , & resp_buftype , flags , & rsp_iov );
5578- cifs_small_buf_release ( iov . iov_base );
5593+ free_qfs_info_req ( & iov );
55795594 if (rc ) {
55805595 cifs_stats_fail_inc (tcon , SMB2_QUERY_INFO_HE );
55815596 goto qfsinf_exit ;
@@ -5642,7 +5657,7 @@ SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
56425657
56435658 rc = cifs_send_recv (xid , ses , server ,
56445659 & rqst , & resp_buftype , flags , & rsp_iov );
5645- cifs_small_buf_release ( iov . iov_base );
5660+ free_qfs_info_req ( & iov );
56465661 if (rc ) {
56475662 cifs_stats_fail_inc (tcon , SMB2_QUERY_INFO_HE );
56485663 goto qfsattr_exit ;
0 commit comments