Repository navigation
Conversation
|
@ctz If you had a few minutes to spare for a review of this I'd appreciate it. |
|
In the mean time, someone sneakily stole test number 2607 so you need to pick a new one... ( |
Thanks for noting. I'll tackle the conflicts that have accrued + Joe's feedback shortly (likely this weekend). |
The rustls vTLS backend may accept plaintext but be blocked from writing the TLS output. In this case we remember how much of the plaintext data buffer we consumed, and then return CURLE_AGAIN. The caller must then provide the same data buffer on a subsequent retry. The same API contract is also required by the OpenSSL backend. However, if through happenstance (e.g. bugs) the caller provides a buffer smaller than the already consumed count for the retry, return an error instead of mangling our accounting. This too matches the OpenSSL vTLS backend's handling of the situation, including a debug assertion for the invalid retry since it indicates programmer error. We do the new check before flushing because while Curl_conn_send already catches an excessive write count, it only does it after the backend has flushed and cleared the saved count. Direct Curl_conn_cf_send callers have no such check. By rejecting the retry early we leave the accounting intact and return an explicit CURLE_BAD_FUNCTION_ARGUMENT in non-debug builds, so a correct retry can still succeed. For calls providing a null/empty buffer we continue to drain the TLS output without touching the plaintext or clearing the count already consumed when handling a subsequent retry. Handshake write readiness now depends only on Rustls' queued TLS output. Test coverage is added using a real Rustls connection and a lower filter that blocks output. It covers short retries, moving and extending an unchanged buffer, partial TLS writes, flush-only calls and fatal output errors through both origin and proxy TLS filters. The pre-handshake buffer lets the test exercise this accounting without a server or certificates. Short-retry error checks run in non-debug builds, since debug builds assert on them.
Document the same-data retry requirement imposed by WebSocket send bookkeeping. Also fix the instruction to wait for readability when a send blocks. Wait for writability, as curl_easy_send does.
9c4330b to
a32219a
Compare
Done. The dragonfly BSD CI failures appear unrelated. |
There was a problem hiding this comment.
🔵 Needs a closer look
Security-sensitive TLS accounting needs human confirmation of Rustls-enabled debug and release test results, which were not independently verified here.
No open issues 🎉
What changed in this PR
This PR hardens Rustls blocked-send handling by rejecting retries shorter than already-buffered plaintext while preserving accounting across internal flush-only calls.
Changes:
- Validates retry lengths and keeps flush-only calls from acknowledging application plaintext.
- Adds regression coverage for blocked sends, partial writes, retry lengths, flushes, and fatal errors.
- Clarifies WebSocket send retry documentation to wait for writability and reuse the same data and length.
| File | Description |
|---|---|
| tests/unit/unit2640.c | Tests Rustls retry accounting through direct and proxy TLS filters. |
| tests/unit/Makefile.inc | Registers the new unit-test source. |
| tests/data/test2640 | Defines the Rustls regression test and required features. |
| tests/data/Makefile.am | Registers the new test case. |
| lib/vtls/rustls.c | Adds retry validation, preserves flush-only accounting, and supplies test initialization. |
| docs/libcurl/curl_ws_send.md | Corrects socket readiness guidance and clarifies retry requirements. |
Review effort: Balanced
|
Thanks! |
See the commit messages for full detail. This is an alternative to #23260 that also considers the accounting across internal flush-only calls, adds test coverage, and tries to make the API docs a little bit more explicit.
See #23260 for a discussion of an alternative I considered and ultimately discarded as being both a much more invasive patch and also incompatible with connect-only applications and the existing API semantics.
For full disclosure, I used Codex & GPT-6-Astra to help implement the test coverage (but have reviewed the output myself). The non-test components were implemented by hand. The test coverage fails as expected when the fix is backed out, and passes otherwise. Because of the new
DEBUGASSERT(0);matching the OpenSSL/mbedtls backends the test has someDEBUGBUILDgates to test the non-debug error return path. If that's too much complexity we could drop that part. LMK!