Skip to content

x509store: do not suppress exceptions in verify_callback - #1166

Merged
rhenium merged 2 commits into
ruby:masterfrom
rhenium:ky/x509store-verify-callback-reraise
Nov 23, 2026
Merged

rhenium merged 2 commits into
ruby:masterfrom
rhenium:ky/x509store-verify-callback-reraise

Conversation

@rhenium

@rhenium rhenium commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Extracted from #1080


x509store: do not suppress exceptions in verify_callback

Currently, verify_callback has no common place to store the jump tag type when an exception is raised or the thread is interrupted, so it suppresses the jump and emits a warning instead.

Use Fiber-local storage for the callback state. Wrap all callers that may invoke verify_callback with ssl_cb_state_{begin,end}() so that the suspended jump can be resumed afterward.

Known limitations: A user can freeze the Thread object to make it suppress exceptions again. A user can store a random Fixnum in Thread.current[:__ossl_cb_state__] to break ruby/openssl. I consider these out of scope at this time, because there doesn't seem to be a better alternative.


ossl.c: fix possible exceptions in ossl_clear_error()

ossl_clear_error() is often used when we are about to resume a jump with rb_jump_tag(). It should not raise an exception or clobber the current errinfo.

Currently, verify_callback has no common place to store the jump tag
type when an exception is raised or the thread is interrupted, so it
suppresses the jump and emits a warning instead.

Use Fiber-local storage for the callback state. Wrap all callers that
may invoke verify_callback with ossl_cb_state_{begin,end}()  so that
the suspended jump can be resumed afterward.

[ Known limitations: A user can freeze the Thread object to make it
  suppress exceptions again. A user can store a random Fixnum in
  Thread.current[:__ossl_cb_state__] to break ruby/openssl. I consider
  these out of scope at this time, because there doesn't seem to be a
  better alternative. ]
ossl_clear_error() is often used when we are about to resume a jump
with rb_jump_tag(). It should not raise an exception or clobber the
current errinfo.
@rhenium
rhenium merged commit fed24ba into ruby:master Nov 23, 2026
48 checks passed
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