@@ -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
@@ -5510,6 +5520,11 @@ build_qfs_info_req(struct kvec *iov, struct cifs_tcon *tcon,
55105520 return 0 ;
55115521}
55125522
5523+ static inline void free_qfs_info_req (struct kvec * iov )
5524+ {
5525+ cifs_buf_release (iov -> iov_base );
5526+ }
5527+
55135528int
55145529SMB311_posix_qfs_info (const unsigned int xid , struct cifs_tcon * tcon ,
55155530 u64 persistent_fid , u64 volatile_fid , struct kstatfs * fsdata )
@@ -5541,7 +5556,7 @@ SMB311_posix_qfs_info(const unsigned int xid, struct cifs_tcon *tcon,
55415556
55425557 rc = cifs_send_recv (xid , ses , server ,
55435558 & rqst , & resp_buftype , flags , & rsp_iov );
5544- cifs_small_buf_release ( iov . iov_base );
5559+ free_qfs_info_req ( & iov );
55455560 if (rc ) {
55465561 cifs_stats_fail_inc (tcon , SMB2_QUERY_INFO_HE );
55475562 goto posix_qfsinf_exit ;
@@ -5592,7 +5607,7 @@ SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
55925607
55935608 rc = cifs_send_recv (xid , ses , server ,
55945609 & rqst , & resp_buftype , flags , & rsp_iov );
5595- cifs_small_buf_release ( iov . iov_base );
5610+ free_qfs_info_req ( & iov );
55965611 if (rc ) {
55975612 cifs_stats_fail_inc (tcon , SMB2_QUERY_INFO_HE );
55985613 goto qfsinf_exit ;
@@ -5659,7 +5674,7 @@ SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
56595674
56605675 rc = cifs_send_recv (xid , ses , server ,
56615676 & rqst , & resp_buftype , flags , & rsp_iov );
5662- cifs_small_buf_release ( iov . iov_base );
5677+ free_qfs_info_req ( & iov );
56635678 if (rc ) {
56645679 cifs_stats_fail_inc (tcon , SMB2_QUERY_INFO_HE );
56655680 goto qfsattr_exit ;
0 commit comments