summaryrefslogtreecommitdiff
path: root/net/tls/tls_device.c
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2023-06-07 19:19:12 +0100
committerJakub Kicinski <kuba@kernel.org>2023-06-08 19:40:30 -0700
commitd4c1e80b0d1bacbbca5184f122b9893c5920c598 (patch)
tree7c43ae2ca0148883ac725b16e372d5a8486070bf /net/tls/tls_device.c
parentdf720d288dbb1793e82b6ccbfc670ec871e9def4 (diff)
tls/device: Use splice_eof() to flush
Allow splice to end a TLS record after prematurely ending a splice/sendfile due to getting an EOF condition (->splice_read() returned 0) after splice had called TLS with a sendmsg() with MSG_MORE set when the user didn't set MSG_MORE. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/r/CAHk-=wh=V579PDYvkpnTobCLGczbgxpMgGmmhqiTyE34Cpi5Gg@mail.gmail.com/ Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> cc: Chuck Lever <chuck.lever@oracle.com> cc: Boris Pismenny <borisp@nvidia.com> cc: John Fastabend <john.fastabend@gmail.com> cc: Jens Axboe <axboe@kernel.dk> cc: Matthew Wilcox <willy@infradead.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/tls/tls_device.c')
-rw-r--r--net/tls/tls_device.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index 9ef766e41c7a..439be833dcf9 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -590,6 +590,29 @@ out:
return rc;
}
+void tls_device_splice_eof(struct socket *sock)
+{
+ struct sock *sk = sock->sk;
+ struct tls_context *tls_ctx = tls_get_ctx(sk);
+ union tls_iter_offset iter;
+ struct iov_iter iov_iter = {};
+
+ if (!tls_is_partially_sent_record(tls_ctx))
+ return;
+
+ mutex_lock(&tls_ctx->tx_lock);
+ lock_sock(sk);
+
+ if (tls_is_partially_sent_record(tls_ctx)) {
+ iov_iter_bvec(&iov_iter, ITER_SOURCE, NULL, 0, 0);
+ iter.msg_iter = &iov_iter;
+ tls_push_data(sk, iter, 0, 0, TLS_RECORD_TYPE_DATA, NULL);
+ }
+
+ release_sock(sk);
+ mutex_unlock(&tls_ctx->tx_lock);
+}
+
int tls_device_sendpage(struct sock *sk, struct page *page,
int offset, size_t size, int flags)
{