#33011·openssl

4.1 regression: provider unload can invalidate a live decoder context

Author: idrassiCreated Sep 27, 2026Updated Sep 29, 2026
Labelsbranch: mastertriaged: bugseverity: regressionbranch: 4.1

I found this while analyzing #33002. Here, the decoder context is already fully built before the provider is unloaded. The library context stays alive, but the decoder context can lose the methods it still holds.

This follows the reference counting changes in #31143. In default builds, OSSL_DECODER_up_ref returns success without incrementing the count for decoders with id != 0 and no_store == 0. Decoder contexts rely on that call to retain their methods.

Enumeration doesn't add a QUERY cache reference. A named fetch can retain a method separately, but otherwise the method store may be its only owner. When the provider's last activation is released, the store removes its methods and can free them while the decoder context still holds their pointers.

The attached reproducer uses public APIs in a single thread. On master at b20968dff5, ASan reports a use after free in decoder_process. The free stack goes through impl_free during provider unload.

On 3.6.4, the same test program completes without an ASan error. Decoding returns 0 because the RSA fetch after unload is unsupported, but the context still owns its methods.

The 3.5.8 and 4.0.2 sources still take real decoder references.

The encoder code shows a similar ownership problem, though the attached runtime evidence covers decoders.

Reproducer with ASan log. The ZIP also includes build instructions.

issue-4.1-method-up-ref-noop-reproducer.zip

Gist for the reproducer if zip link doesn't work: https://gist.github.com/idrassi/0a3036ef9337a6521fdb0783029009e9