Skip to content

Send close_notify after user_canceled even under quiet shutdown - #11264

Open
night1rider wants to merge 4 commits into
wolfSSL:masterfrom
night1rider:fenrir-10650
Open

Send close_notify after user_canceled even under quiet shutdown#11264
night1rider wants to merge 4 commits into
wolfSSL:masterfrom
night1rider:fenrir-10650

Conversation

@night1rider

Copy link
Copy Markdown
Contributor

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.

@night1rider night1rider self-assigned this Aug 25, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wolfSSL-Bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

night1rider added a commit to night1rider/wolfssl that referenced this pull request Aug 25, 2026
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 wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m3

  • FLASH: .text +92 B (+0.1%, 125,867 B / 262,144 B, total: 48% used)

gcc-arm-cortex-m4

  • FLASH: .text +64 B (+0.0%, 205,021 B / 262,144 B, total: 78% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +128 B (+0.1%, 186,748 B / 1,048,576 B, total: 18% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +64 B (+0.0%, 783,268 B / 1,048,576 B, total: 75% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +64 B (+0.0%, 301,704 B / 1,048,576 B, total: 29% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +64 B (+0.0%, 332,512 B / 1,048,576 B, total: 32% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +64 B (+0.1%, 126,643 B / 262,144 B, total: 48% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +128 B (+0.1%, 242,255 B / 262,144 B, total: 92% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 205,021 B / 262,144 B, total: 78% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +64 B (+0.0%, 302,664 B / 1,048,576 B, total: 29% used)

gcc-arm-cortex-m7-tls13

night1rider added a commit to night1rider/wolfssl that referenced this pull request Aug 27, 2026
Guard the quiet-shutdown setter against a NULL ssl_s and assert quietShutdown is restored after SendUserCanceled, per PR wolfSSL#11264 review.
Copilot AI lite review requested due to automatic review settings August 27, 2026 03:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.quietShutdown around the internal wolfSSL_shutdown() call in wolfSSL_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.

Comment thread tests/api.c Outdated
Comment thread src/ssl_api_rw.c Outdated
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/ssl_api_rw.c Outdated
* 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/api.c Outdated
/* 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Comment thread tests/api.c Outdated

/* 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants