From 6688945fa03f4a448708f729083ea4a1cdd1ab88 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 26 Jan 2024 14:42:40 +0100 Subject: [PATCH] s3:lib/tls: we need to call tstream_tls_retry_handshake/disconnect() until all buffers are flushed Before the handshare or disconnect is over we need to wait until we delivered the lowlevel messages to the transport/kernel socket. Otherwise we'll have a problem if another tevent_context is used after the handshake. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15621 Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- source4/lib/tls/tls_tstream.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source4/lib/tls/tls_tstream.c b/source4/lib/tls/tls_tstream.c index 085da5e6473..364bb421078 100644 --- a/source4/lib/tls/tls_tstream.c +++ b/source4/lib/tls/tls_tstream.c @@ -70,6 +70,10 @@ struct tstream_tls { struct tevent_immediate *retry_im; + struct { + struct tevent_req *mgmt_req; + } waiting_flush; + struct { uint8_t *buf; off_t ofs; @@ -121,6 +125,17 @@ static void tstream_tls_retry(struct tstream_context *stream, bool deferred) tstream_context_data(stream, struct tstream_tls); + if (tlss->push.subreq == NULL && tlss->pull.subreq == NULL) { + if (tlss->waiting_flush.mgmt_req != NULL) { + struct tevent_req *req = tlss->waiting_flush.mgmt_req; + + tlss->waiting_flush.mgmt_req = NULL; + + tevent_req_done(req); + return; + } + } + if (tlss->disconnect.req) { tstream_tls_retry_disconnect(stream); return; @@ -785,6 +800,11 @@ static void tstream_tls_retry_disconnect(struct tstream_context *stream) return; } + if (tlss->push.subreq != NULL || tlss->pull.subreq != NULL) { + tlss->waiting_flush.mgmt_req = req; + return; + } + tevent_req_done(req); } @@ -1477,6 +1497,11 @@ static void tstream_tls_retry_handshake(struct tstream_context *stream) } } + if (tlss->push.subreq != NULL || tlss->pull.subreq != NULL) { + tlss->waiting_flush.mgmt_req = req; + return; + } + tevent_req_done(req); } -- 2.34.1