Skip to content

Make TLS session timeout test deterministic - #589

Open
nox wants to merge 2 commits into
cloudflare:masterfrom
nox:nox/session-time-callback
Open

nox wants to merge 2 commits into
cloudflare:masterfrom
nox:nox/session-time-callback

Conversation

@nox

@nox nox commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

This wraps BoringSSL’s current-time callback and adds a public thread-local mock clock with checked Duration-based set and advance operations. The TLS 1.3 PSK-DHE session timeout test drives both handshakes on one thread with nonblocking sockets so both contexts observe the same deterministic clock.

@clanky-the-clanker clanky-the-clanker 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.

Superseded by the review of d2e7e477.

This review, of dfdeafd8

💬 Approved with comments — One WARNING: the safe set_current_time_callback lets safe code break a soundness contract. There is also one test-coverage note. No production-impacting defects.

Findings: 1 warning (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #589.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] `boring/src/ssl/mod.rs:2392`: safe `set_current_time_callback` installs an arbitrary `unsafe extern "C" fn` that BoringSSL will call, so safe code can cause UB.
- **File:** boring/src/ssl/mod.rs:2392

📋 Code Quality: ⚠️ 1 warning

The safe setter takes a callback with an unchecked safety contract, and the test does not check that the mock clock was observed.

Recommendation: 📝 Minor Comments

  • [WARNING] boring/src/ssl/mod.rs:2392: safe set_current_time_callback installs an arbitrary unsafe extern "C" fn that BoringSSL will call, so safe code can cause UB. (boring/src/ssl/mod.rs:2392)
View full review
  • boring/src/ssl/mod.rs:2392: set_current_time_callback is a safe pub fn, but whether it is sound depends on a contract it cannot check.
  • boring/src/ssl/test/session.rs:446: the test sets the clock but never checks that BoringSSL used it.

The rest checks out. ThreadLocalMockClock::new checks the time_t conversions, and advance_thread_local_mock_clock leaves the clock unchanged when it returns an error. raw_thread_local_mock_time always writes out_clock and never panics. use_thread_local_mock_clock(true) fails before it changes the context.


✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found. The mock clock is something the embedding application has to turn on, and a remote peer cannot reach it. If the thread-local clock is unavailable, the callback writes a zeroed timeval.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues in this change.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: dfdeafd8

Comment thread boring/src/ssl/mod.rs Outdated
///
/// This is intended for testing. See [`SslCurrentTimeCallback`] for the callback's contract.
#[corresponds(SSL_CTX_set_current_time_cb)]
pub fn set_current_time_callback(&mut self, callback: SslCurrentTimeCallback) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ WARNING · Code Quality

boring/src/ssl/mod.rs:2392: safe set_current_time_callback installs an arbitrary unsafe extern "C" fn that BoringSSL will call, so safe code can cause UB.

set_current_time_callback is a safe pub fn, but BoringSSL will call any unsafe extern "C" fn it is given. The callback must fully initialize out_clock and must not unwind, and nothing checks either. Safe code can pass a callback that leaves out_clock uninitialized, and BoringSSL then reads uninitialized memory. The # Safety section on the type alias does not make the setter unsafe to call. Mark the method unsafe fn with a # Safety section, or remove it from the public API and keep only the internal thread-local mock.

@clanky-the-clanker clanky-the-clanker 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.

✅ Approved — Both earlier findings are fixed at this commit, and no new issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No security issues found. The mock clock is off unless the application turns it on, and a remote peer cannot reach it.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues in this change.


📋 Code Quality: ✅ LGTM

Both earlier findings are fixed.

  • Arbitrary callback: the callback is now private (boring/src/ssl/mock_clock.rs:67). use_thread_local_mock_clock can install only that callback or clear it.
  • Clock never checked: the test now asserts session.time() against the mock time.

The checked conversions, the clock left unchanged on error, and the failure before any change to the context all work as intended.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: d2e7e477

This branch has not been deployed

No deployments
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.

1 participant