-
Notifications
You must be signed in to change notification settings - Fork 1.9k
tls: fix regression and proper shutdown #10924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| #include <fluent-bit/flb_info.h> | ||
| #include <fluent-bit/flb_upstream.h> | ||
| #include <fluent-bit/flb_upstream_conn.h> | ||
| #include <fluent-bit/flb_connection.h> | ||
| #include <fluent-bit/flb_pipe.h> | ||
| #include <fluent-bit/flb_socket.h> | ||
| #include <fluent-bit/tls/flb_tls.h> | ||
|
|
||
| #include "flb_tests_internal.h" | ||
|
|
||
| #ifdef FLB_HAVE_TLS | ||
|
|
||
| #ifdef FLB_SYSTEM_WINDOWS | ||
| #include <fluent-bit/flb_compat.h> | ||
| #endif | ||
|
|
||
| struct test_backend_ctx { | ||
| int invalidate_calls; | ||
| }; | ||
|
|
||
| static void test_session_invalidate(void *session) | ||
| { | ||
| struct test_backend_ctx *ctx = session; | ||
|
|
||
| if (ctx != NULL) { | ||
| ctx->invalidate_calls++; | ||
| } | ||
| } | ||
|
|
||
| void test_prepare_destroy_conn_marks_tls_session_stale(void) | ||
| { | ||
| struct test_backend_ctx backend_session = {0}; | ||
| struct flb_tls_backend backend_api = {0}; | ||
| struct flb_tls tls_context = {0}; | ||
| struct flb_tls_session tls_session = {0}; | ||
| struct flb_connection conn = {0}; | ||
| struct flb_upstream upstream = {0}; | ||
| struct flb_config config = {0}; | ||
| struct flb_upstream_queue *queue; | ||
| flb_pipefd_t socket_pair[2]; | ||
| int ret; | ||
|
|
||
| #ifdef FLB_SYSTEM_WINDOWS | ||
| WSADATA wsa_data; | ||
|
|
||
| WSAStartup(0x0201, &wsa_data); | ||
| #endif | ||
|
|
||
| ret = flb_pipe_create(socket_pair); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| backend_api.session_invalidate = test_session_invalidate; | ||
| tls_context.api = &backend_api; | ||
|
|
||
| tls_session.ptr = &backend_session; | ||
| tls_session.tls = &tls_context; | ||
| tls_session.connection = &conn; | ||
|
|
||
| config.is_shutting_down = FLB_FALSE; | ||
| upstream.base.config = &config; | ||
| upstream.base.net.keepalive = FLB_FALSE; | ||
| upstream.tcp_host = "example"; | ||
| upstream.tcp_port = 443; | ||
|
|
||
| flb_upstream_queue_init(&upstream.queue); | ||
|
|
||
| conn.fd = socket_pair[0]; | ||
| conn.event.fd = conn.fd; | ||
| conn.event.status = 0; | ||
| conn.stream = (struct flb_stream *) &upstream; | ||
| conn.net = &upstream.base.net; | ||
| conn.tls_session = &tls_session; | ||
| conn.net_error = 0; | ||
|
|
||
| mk_list_init(&conn._head); | ||
| queue = &upstream.queue; | ||
| mk_list_add(&conn._head, &queue->busy_queue); | ||
|
|
||
| ret = flb_upstream_conn_release(&conn); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| TEST_CHECK(backend_session.invalidate_calls == 1); | ||
| TEST_CHECK(conn.fd == -1); | ||
| TEST_CHECK(conn.event.fd == -1); | ||
| TEST_CHECK(mk_list_size(&queue->destroy_queue) == 1); | ||
| TEST_CHECK(conn.shutdown_flag == FLB_TRUE); | ||
|
|
||
| flb_pipe_close(socket_pair[1]); | ||
|
|
||
| #ifdef FLB_SYSTEM_WINDOWS | ||
| WSACleanup(); | ||
| #endif | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| TEST_LIST = { | ||
| #ifdef FLB_HAVE_TLS | ||
| {"prepare_destroy_conn_marks_tls_session_stale", test_prepare_destroy_conn_marks_tls_session_stale}, | ||
| #endif | ||
| {0} | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set conn.upstream and use upstream.base for conn.stream (fix crash risk).
flb_upstream_conn_release dereferences conn->upstream. Here it’s never set, and conn->stream is pointing to &upstream (not &upstream.base). This can lead to NULL deref/UB at runtime.
Apply this diff:
conn.fd = socket_pair[0]; conn.event.fd = conn.fd; conn.event.status = 0; - conn.stream = (struct flb_stream *) &upstream; + conn.upstream = &upstream; + conn.stream = &upstream.base; conn.net = &upstream.base.net; conn.tls_session = &tls_session; - conn.net_error = 0; + /* -1 is the sentinel used in keepalive path checks for “no error” */ + conn.net_error = -1;📝 Committable suggestion
🤖 Prompt for AI Agents