Skip to content

Use the core libctx when wolfProvider replaces the default provider to fix a deadlock on musl - #530

Merged
ColtonWilley merged 1 commit into
wolfSSL:masterfrom
aidangarske:replace-default-musl-deadlock
Nov 12, 2026
Merged

ColtonWilley merged 1 commit into
wolfSSL:masterfrom
aidangarske:replace-default-musl-deadlock

Conversation

@aidangarske

Copy link
Copy Markdown
Member
  • With replace-default and no config activating a provider, OpenSSL starts wolfProvider as its fallback default provider in
    provider_activate_fallbacks(). That function holds the provider store write lock while it calls the provider's init.
    OpenSSL's comment there assumes fallbacks are never third-party providers.
  • wolfssl_provider_init() calls OSSL_LIB_CTX_new_child(). Registering the child's callbacks with the parent takes that
    same store lock again.
  • glibc's rwlock returns EDEADLK, so the child libctx creation fails and the libctx stays NULL. musl blocks in futex
    forever.
  • On musl, any program with no OpenSSL config hangs at its first crypto call, and so does any program that creates its own
    libctx. For example, OPENSSL_CONF=/dev/null openssl list -providers hangs on OpenWrt 23.05 ARM32, and the build script's
    own openssl list -providers check hangs on Alpine.
  • Fix: in WOLFPROV_REPLACE_DEFAULT builds, init takes OSSL_FUNC_core_get_libctx and uses the core's libctx. This is what
    OpenSSL's built-in default provider does (providers/defltprov.c), and with replace-default wolfProvider is registered as
    that built-in default. It takes no lock, and internal fetches go to the libctx the provider was started in.
  • The core's libctx belongs to OpenSSL or the application, so teardown frees the libctx only in normal builds, where it's
    the child we created. This overlaps provider: free the child libctx on teardown #519, whose unconditional free would release the core's libctx under replace-default.
  • Builds without replace-default still create the child libctx.
  • New musl.yml: an Alpine 3.20 container builds standard and replace-default against the latest OpenSSL and 3.0.17. It
    runs the unit tests, the cmd tests normally and with WOLFPROV_FORCE_FAIL=1, and a no-config load with a timeout. Current
    CI is glibc only, so it can't catch this.

@aidangarske aidangarske self-assigned this Nov 11, 2026
@aidangarske
aidangarske requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 11, 2026 23:59

Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded that would block approval.

No open issues 🎉

What changed in this PR

This PR addresses the musl deadlock when wolfProvider is activated as OpenSSL’s fallback default provider, while preserving child-context behavior in standard builds.

Changes:

  • Borrow the core library context in replace-default builds to avoid recursive locking.
  • Free only provider-owned child contexts during teardown, addressing the ownership concern described in #519.
  • Add Alpine CI covering standard and replace-default builds, command-line tests, and no-config fallback activation.
File Description
src/​wp_wolfprov.c Selects the appropriate library context and frees only owned contexts.
.github/​workflows/​README.md Documents the new musl test coverage.
.github/​workflows/​musl.yml Adds Alpine build and regression tests against latest OpenSSL and 3.0.17.

Review effort: Balanced

@aidangarske aidangarske added the ci:all PR OSP toggle: run all label Nov 12, 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 #530

Scan targets checked: wolfprovider-src, wolfprovider-bugs
Not reviewed (no scan target covers them): .github/workflows/README.md, .github/workflows/musl.yml
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

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.

Review tier: Max

Comment thread src/wp_wolfprov.c Resolved
@aidangarske aidangarske removed the ci:all PR OSP toggle: run all label Nov 12, 2026
@aidangarske
aidangarske force-pushed the replace-default-musl-deadlock branch from 1d28980 to ad453cf Compare November 12, 2026 00:43

@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 #530

Scan targets checked: wolfprovider-src, wolfprovider-bugs
Not reviewed (no scan target covers them): .github/workflows/README.md, .github/workflows/musl.yml, .github/workflows/nightly-osp.yml, .github/workflows/pr-osp-select.yml
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: include/wolfprovider/internal.h

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed their stale review November 12, 2026 16:09

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@aidangarske aidangarske added the ci:all PR OSP toggle: run all label Nov 12, 2026
@ColtonWilley
ColtonWilley merged commit dd715b7 into wolfSSL:master Nov 12, 2026
899 checks passed
@aidangarske
aidangarske deleted the replace-default-musl-deadlock branch November 12, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:all PR OSP toggle: run all

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants