@@ -884,7 +884,6 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
884884 struct cifs_sb_info * cifs_sb )
885885{
886886 struct cifs_ses * ses = tcon -> ses ;
887- struct TCP_Server_Info * server = ses -> server ;
888887 __le16 * utf16_path = NULL ;
889888 int ea_name_len = strlen (ea_name );
890889 int flags = 0 ;
@@ -936,7 +935,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
936935 rc = SMB2_open_init (tcon , & rqst [0 ], & oplock , & oparms , utf16_path );
937936 if (rc )
938937 goto sea_exit ;
939- smb2_set_next_command (ses -> server , & rqst [0 ], 0 );
938+ smb2_set_next_command (tcon , & rqst [0 ]);
940939
941940
942941 /* Set Info */
@@ -963,7 +962,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
963962 COMPOUND_FID , current -> tgid ,
964963 FILE_FULL_EA_INFORMATION ,
965964 SMB2_O_INFO_FILE , 0 , data , size );
966- smb2_set_next_command (server , & rqst [1 ], 0 );
965+ smb2_set_next_command (tcon , & rqst [1 ]);
967966 smb2_set_related (& rqst [1 ]);
968967
969968
@@ -1222,7 +1221,7 @@ smb2_ioctl_query_info(const unsigned int xid,
12221221 rc = SMB2_open_init (tcon , & rqst [0 ], & oplock , & oparms , path );
12231222 if (rc )
12241223 goto iqinf_exit ;
1225- smb2_set_next_command (ses -> server , & rqst [0 ], 0 );
1224+ smb2_set_next_command (tcon , & rqst [0 ]);
12261225
12271226 /* Query */
12281227 memset (& qi_iov , 0 , sizeof (qi_iov ));
@@ -1236,7 +1235,7 @@ smb2_ioctl_query_info(const unsigned int xid,
12361235 qi .output_buffer_length , buffer );
12371236 if (rc )
12381237 goto iqinf_exit ;
1239- smb2_set_next_command (ses -> server , & rqst [1 ], 0 );
1238+ smb2_set_next_command (tcon , & rqst [1 ]);
12401239 smb2_set_related (& rqst [1 ]);
12411240
12421241 /* Close */
@@ -1789,26 +1788,53 @@ smb2_set_related(struct smb_rqst *rqst)
17891788char smb2_padding [7 ] = {0 , 0 , 0 , 0 , 0 , 0 , 0 };
17901789
17911790void
1792- smb2_set_next_command (struct TCP_Server_Info * server , struct smb_rqst * rqst ,
1793- bool has_space_for_padding )
1791+ smb2_set_next_command (struct cifs_tcon * tcon , struct smb_rqst * rqst )
17941792{
17951793 struct smb2_sync_hdr * shdr ;
1794+ struct cifs_ses * ses = tcon -> ses ;
1795+ struct TCP_Server_Info * server = ses -> server ;
17961796 unsigned long len = smb_rqst_len (server , rqst );
1797+ int i , num_padding ;
17971798
17981799 /* SMB headers in a compound are 8 byte aligned. */
1799- if (len & 7 ) {
1800- if (has_space_for_padding ) {
1801- len = rqst -> rq_iov [rqst -> rq_nvec - 1 ].iov_len ;
1802- rqst -> rq_iov [rqst -> rq_nvec - 1 ].iov_len =
1803- (len + 7 ) & ~7 ;
1804- } else {
1805- rqst -> rq_iov [rqst -> rq_nvec ].iov_base = smb2_padding ;
1806- rqst -> rq_iov [rqst -> rq_nvec ].iov_len = 8 - (len & 7 );
1807- rqst -> rq_nvec ++ ;
1800+
1801+ /* No padding needed */
1802+ if (!(len & 7 ))
1803+ goto finished ;
1804+
1805+ num_padding = 8 - (len & 7 );
1806+ if (!smb3_encryption_required (tcon )) {
1807+ /*
1808+ * If we do not have encryption then we can just add an extra
1809+ * iov for the padding.
1810+ */
1811+ rqst -> rq_iov [rqst -> rq_nvec ].iov_base = smb2_padding ;
1812+ rqst -> rq_iov [rqst -> rq_nvec ].iov_len = num_padding ;
1813+ rqst -> rq_nvec ++ ;
1814+ len += num_padding ;
1815+ } else {
1816+ /*
1817+ * We can not add a small padding iov for the encryption case
1818+ * because the encryption framework can not handle the padding
1819+ * iovs.
1820+ * We have to flatten this into a single buffer and add
1821+ * the padding to it.
1822+ */
1823+ for (i = 1 ; i < rqst -> rq_nvec ; i ++ ) {
1824+ memcpy (rqst -> rq_iov [0 ].iov_base +
1825+ rqst -> rq_iov [0 ].iov_len ,
1826+ rqst -> rq_iov [i ].iov_base ,
1827+ rqst -> rq_iov [i ].iov_len );
1828+ rqst -> rq_iov [0 ].iov_len += rqst -> rq_iov [i ].iov_len ;
18081829 }
1809- len = smb_rqst_len (server , rqst );
1830+ memset (rqst -> rq_iov [0 ].iov_base + rqst -> rq_iov [0 ].iov_len ,
1831+ 0 , num_padding );
1832+ rqst -> rq_iov [0 ].iov_len += num_padding ;
1833+ len += num_padding ;
1834+ rqst -> rq_nvec = 1 ;
18101835 }
18111836
1837+ finished :
18121838 shdr = (struct smb2_sync_hdr * )(rqst -> rq_iov [0 ].iov_base );
18131839 shdr -> NextCommand = cpu_to_le32 (len );
18141840}
@@ -1825,7 +1851,6 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
18251851 struct cifs_sb_info * cifs_sb )
18261852{
18271853 struct cifs_ses * ses = tcon -> ses ;
1828- struct TCP_Server_Info * server = ses -> server ;
18291854 int flags = 0 ;
18301855 struct smb_rqst rqst [3 ];
18311856 int resp_buftype [3 ];
@@ -1862,7 +1887,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
18621887 rc = SMB2_open_init (tcon , & rqst [0 ], & oplock , & oparms , utf16_path );
18631888 if (rc )
18641889 goto qic_exit ;
1865- smb2_set_next_command (server , & rqst [0 ], 0 );
1890+ smb2_set_next_command (tcon , & rqst [0 ]);
18661891
18671892 memset (& qi_iov , 0 , sizeof (qi_iov ));
18681893 rqst [1 ].rq_iov = qi_iov ;
@@ -1874,7 +1899,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
18741899 NULL );
18751900 if (rc )
18761901 goto qic_exit ;
1877- smb2_set_next_command (server , & rqst [1 ], 0 );
1902+ smb2_set_next_command (tcon , & rqst [1 ]);
18781903 smb2_set_related (& rqst [1 ]);
18791904
18801905 memset (& close_iov , 0 , sizeof (close_iov ));
@@ -2806,7 +2831,7 @@ init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
28062831 smb2_sg_set_buf (& sg [idx ++ ],
28072832 rqst [i ].rq_iov [j ].iov_base + skip ,
28082833 rqst [i ].rq_iov [j ].iov_len - skip );
2809- }
2834+ }
28102835
28112836 for (j = 0 ; j < rqst [i ].rq_npages ; j ++ ) {
28122837 unsigned int len , offset ;
0 commit comments