@@ -1157,6 +1157,80 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
11571157 return copied > 0 ? copied : ret ;
11581158}
11591159
1160+ /*
1161+ * Handle unexpected EOF during splice without SPLICE_F_MORE set.
1162+ */
1163+ void tls_sw_splice_eof (struct socket * sock )
1164+ {
1165+ struct sock * sk = sock -> sk ;
1166+ struct tls_context * tls_ctx = tls_get_ctx (sk );
1167+ struct tls_sw_context_tx * ctx = tls_sw_ctx_tx (tls_ctx );
1168+ struct tls_rec * rec ;
1169+ struct sk_msg * msg_pl ;
1170+ ssize_t copied = 0 ;
1171+ bool retrying = false;
1172+ int ret = 0 ;
1173+ int pending ;
1174+
1175+ if (!ctx -> open_rec )
1176+ return ;
1177+
1178+ mutex_lock (& tls_ctx -> tx_lock );
1179+ lock_sock (sk );
1180+
1181+ retry :
1182+ rec = ctx -> open_rec ;
1183+ if (!rec )
1184+ goto unlock ;
1185+
1186+ msg_pl = & rec -> msg_plaintext ;
1187+
1188+ /* Check the BPF advisor and perform transmission. */
1189+ ret = bpf_exec_tx_verdict (msg_pl , sk , false, TLS_RECORD_TYPE_DATA ,
1190+ & copied , 0 );
1191+ switch (ret ) {
1192+ case 0 :
1193+ case - EAGAIN :
1194+ if (retrying )
1195+ goto unlock ;
1196+ retrying = true;
1197+ goto retry ;
1198+ case - EINPROGRESS :
1199+ break ;
1200+ default :
1201+ goto unlock ;
1202+ }
1203+
1204+ /* Wait for pending encryptions to get completed */
1205+ spin_lock_bh (& ctx -> encrypt_compl_lock );
1206+ ctx -> async_notify = true;
1207+
1208+ pending = atomic_read (& ctx -> encrypt_pending );
1209+ spin_unlock_bh (& ctx -> encrypt_compl_lock );
1210+ if (pending )
1211+ crypto_wait_req (- EINPROGRESS , & ctx -> async_wait );
1212+ else
1213+ reinit_completion (& ctx -> async_wait .completion );
1214+
1215+ /* There can be no concurrent accesses, since we have no pending
1216+ * encrypt operations
1217+ */
1218+ WRITE_ONCE (ctx -> async_notify , false);
1219+
1220+ if (ctx -> async_wait .err )
1221+ goto unlock ;
1222+
1223+ /* Transmit if any encryptions have completed */
1224+ if (test_and_clear_bit (BIT_TX_SCHEDULED , & ctx -> tx_bitmask )) {
1225+ cancel_delayed_work (& ctx -> tx_work .work );
1226+ tls_tx_records (sk , 0 );
1227+ }
1228+
1229+ unlock :
1230+ release_sock (sk );
1231+ mutex_unlock (& tls_ctx -> tx_lock );
1232+ }
1233+
11601234static int tls_sw_do_sendpage (struct sock * sk , struct page * page ,
11611235 int offset , size_t size , int flags )
11621236{
0 commit comments