tls: openssl: preserve syscall error details - #12178
Open
edsiper wants to merge 4 commits into
Open
Conversation
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
📝 WalkthroughWalkthroughTLS OpenSSL read and write paths now centralize error logging and preserve syscall errno values. Forward integration tests inject connection resets and corrupted TLS records, verify diagnostic output, and confirm subsequent valid traffic remains accepted. ChangesTLS I/O error handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ForwardTest
participant TLSListener
participant tls_net_read
participant tls_log_io_error
ForwardTest->>TLSListener: send reset or corrupted TLS record
TLSListener->>tls_net_read: read TLS data
tls_net_read->>tls_log_io_error: report TLS I/O error
tls_log_io_error-->>TLSListener: emit diagnostic and errno result
ForwardTest->>TLSListener: send subsequent valid traffic
TLSListener-->>ForwardTest: accept and ingest traffic
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
errnoimmediately afterSSL_read()andSSL_write()SSL_ERROR_SSLfailures instead of silently discarding the error queueSSL_ERROR_SYSCALLand corrupted-record/SSL_ERROR_SSLpathsRoot cause
The
SSL_ERROR_SYSCALLread path calledflb_errno()before usingerrnoagain. Fluent Bit's error rendering callsisatty(stderr); with redirected stderr that call can replace the original value withENOTTY. The followingstrerror(errno)andconnection->net_errorassignment therefore reported and stored the diagnostic side effect. The write path had the same delayed-errnopattern.The read path also had a dead
ssl_ret < 0condition.SSL_get_error()returns nonnegative constants, soSSL_ERROR_SSLand other fatal results fell through silently and leftconnection->net_error == -1. On OpenSSL 3.x this included unexpected peer EOF, which is reported asSSL_ERROR_SSLwithSSL_R_UNEXPECTED_EOF_WHILE_READINGin the queue.The fix snapshots
errnoimmediately after OpenSSL I/O and classifies failures as follows:SSL_ERROR_SYSCALLwith saved nonzeroerrno: report the real syscall failure and preserve that errnoSSL_ERROR_SYSCALLwith an empty queue and zero errno: report legacy unexpected EOF and useECONNRESETas the terminal markerWANT_READ/WANT_WRITE and the existing
SSL_ERROR_ZERO_RETURNclose-notify handling remain unchanged. This does not include #12141's retry work or alter handshake EOF behavior.Compatibility and severity
An established-session peer EOF without
close_notifyis logged at error level. OpenSSL 3.x classifies this as a fatal TLS truncation/protocol error, and older OpenSSL versions already reached the error-levelSSL_ERROR_SYSCALLpath. This may make abrupt disconnects from non-compliant clients more visible, but Fluent Bit does not enableSSL_OP_IGNORE_UNEXPECTED_EOFbecause that would discard TLS truncation protection. An abrupt EOF during an incompleteSSL_write()is also error-level because application data may have been lost. Ordinary handshake-disconnect behavior is untouched.Regression proof
The known-broken syscall path emitted contradictory diagnostics:
It now reports only the saved reset error. Before the fatal-error correction, a corrupted encrypted record reached
SSL_ERROR_SSLbut produced no TLS log. It now reports the authoritative queue entry, such asdecryption failed or bad record mac.Both tests submit a valid TLS Forward payload afterward and verify responsiveness.
Validation
Both normal and strict-Valgrind tests pass. Valgrind reports 0 errors, all heap blocks freed, and no allocations remaining at exit. The full commit range passes the repository prefix checker against
master.