Send close_notify after user_canceled even under quiet shutdown - #11264
Send close_notify after user_canceled even under quiet shutdown#11264night1rider wants to merge 4 commits into
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11264
Scan targets checked: wolfssl-bugs, wolfssl-src
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
|
Can one of the admins verify this patch? |
Guard the quiet-shutdown setter against a NULL ssl_s and assert quietShutdown is restored after SendUserCanceled, per PR wolfSSL#11264 review.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11264
Scan targets checked: wolfssl-bugs, wolfssl-src
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
|
Guard the quiet-shutdown setter against a NULL ssl_s and assert quietShutdown is restored after SendUserCanceled, per PR wolfSSL#11264 review.
b331d05 to
cd382c8
Compare
There was a problem hiding this comment.
Pull request overview
This PR ensures wolfSSL_SendUserCanceled() still emits the RFC 9846-required paired close_notify even when quiet shutdown is enabled, and expands the API test to cover the quiet-shutdown scenario.
Changes:
- Temporarily clears
ssl->options.quietShutdownaround the internalwolfSSL_shutdown()call inwolfSSL_SendUserCanceled(), then restores it. - Extends
test_wolfSSL_SendUserCanceled()to run each protocol variant twice (normal + quiet shutdown where available) and validate the expected alert history behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/ssl_api_rw.c |
Clears quiet shutdown across wolfSSL_shutdown() inside wolfSSL_SendUserCanceled() to guarantee the paired close_notify is sent. |
tests/api.c |
Adds a quiet-shutdown test pass for wolfSSL_SendUserCanceled() and asserts the close-notify behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Clear quiet shutdown across the shutdown call in wolfSSL_SendUserCanceled so the RFC 9846 paired close_notify is emitted, and cover it in test_wolfSSL_SendUserCanceled.
Guard the quiet-shutdown setter against a NULL ssl_s and assert quietShutdown is restored after SendUserCanceled, per PR wolfSSL#11264 review.
Have the wolfSSL_shutdown quiet path send a close_notify already left in the output buffer by WANT_WRITE, so the retry after wolfSSL_SendUserCanceled restores quiet shutdown still delivers it; cover it with a WANT_WRITE write callback and check restoration via wolfSSL_shutdown instead of ssl->options, per PR wolfSSL#11264 review.
cd382c8 to
6040e2a
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core shutdown behavior in a security-critical API path (wolfSSL_shutdown / alert flushing), so it warrants final human review despite targeted test coverage.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11264
Scan targets checked: wolfssl-bugs, wolfssl-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
| * shutdown only for the call that sends the RFC 9846 paired | ||
| * close_notify and then restores it, so the retry that gets the | ||
| * alert out lands here. Flush it before reporting success. */ | ||
| if (ssl->options.sentNotify) { |
There was a problem hiding this comment.
Quiet shutdown flushes unrelated buffered data · API contract violations
wolfSSL_set_shutdown() can set sentNotify without sending an alert. With application data buffered after WANT_WRITE, this branch transmits that data during quiet shutdown. Known #10650 instead covers a missing required close_notify.
Related known finding #10650 (similar but distinct): Both affect quiet-shutdown handling in wolfSSL_shutdown, but the candidate's faulting operation is flushing pre-existing buffered application data after sentNotify is set, whereas #10650 omits a required close_notify. Their root causes and required patches differ: state-gating the flush versus sending the closure alert.
Suggested fix: Gate the quiet-path flush on dedicated state set only when wolfSSL_SendUserCanceled() buffers its paired close_notify.
Basis: OpenSSL SSL_CTX_set_quiet_shutdown(3), Quiet Shutdown requires SSL_shutdown() to succeed immediately without transmitting an alert.
| /* Transport writable again: the retry must flush the | ||
| * buffered close_notify even though quiet shutdown has been | ||
| * restored in the meantime. */ | ||
| if (ssl_s != NULL) |
There was a problem hiding this comment.
Permanent flush failures remain untested · Missing edge-case coverage on a function the PR also changed
The test restores a successful callback before retrying, leaving the new branch that preserves fatal SendBuffered() errors untested. A regression converting permanent write failure to success would pass.
Suggested fix: Add a quiet-shutdown retry whose callback returns WOLFSSL_CBIO_ERR_GENERAL, then assert the fatal return and stored error.
Basis: The wolfSSL_shutdown() API contract requires errors to return WOLFSSL_FATAL_ERROR with the reason available through wolfSSL_get_error().
|
|
||
| /* Last alert will be close notify because user_canceled should be | ||
| * followed by a close_notify */ | ||
| ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS); |
There was a problem hiding this comment.
Test never verifies the user_canceled alert · Weak or missing assertions
test_wolfSSL_SendUserCanceled() checks only the record count and final close_notify, so two close_notify records satisfy it without a user_canceled. Unlike known #10650's runtime defect, this is a distinct test-oracle gap.
Suggested fix: Capture both alerts and assert user_canceled then close_notify, at minimum for every TLS/DTLS 1.3 quiet/WANT_WRITE variant.
Basis: RFC 9846 Section 6.1 requires a user_canceled alert to be followed by a close_notify.
Use a flag set by wolfSSL_SendUserCanceled so quiet shutdown never sends data on its own, and test alert order, a failed retry, and that the setting comes back.
Clear quiet shutdown across the shutdown call in wolfSSL_SendUserCanceled so the RFC 9846 paired close_notify is emitted, and cover it in test_wolfSSL_SendUserCanceled.