Skip to content

NULL pointer dereferencing and use-after-free in systhreads due to delayed init #11434

@gadmm

Description

@gadmm

This is a follow-up to #11403, which noticed that the domain threads initialization code runs from OCaml code. Thus there is an interval during which arbitrary OCaml code can run before initialization (e.g. GC, async callbacks and at_each_spawn callbacks). This can cause NULL pointer dereferencing and use-after-free inside caml_thread_self and caml_enter_blocking_section. Following the discussion at #11403, it appears that the best solution is:

  • Replace the use of Domain.at_each_spawn to call caml_thread_initialize_domain with a C hook caml_domain_at_each_spawn similar to caml_domain_stop_hook (internal, non-atomic).
  • Optionally remove the API Domain.at_each_spawn, which is a bad API for other reasons discussed somewhere else.

Targets 5.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions