Skip to content

Upstream the mruby stack_init() nil-init fix (multi-VM-per-process crash) #60

Open

Description

@apotema

PR #59 fixed a latent upstream mruby bug (present through mruby 3.4.0): stack_init() in vendor/mruby/src/vm.c mallocs the initial 128-slot VM stack but never nil-initializes it, unlike stack_extend_alloc() which stack_clear()s its grown region. GC's mark_context_stack() then reads uninitialized slots — harmless on a first boot (fresh zero mmap) but on a later mrb_open (after prior VMs dirtied the heap), a leftover word is marked as a bogus object pointer and dereferenced → SEGV. Linux-only (glibc/musl recycle dirty memory eagerly; macOS libmalloc masked it). Valgrind-confirmed dirty-memory-reuse, not OOB.

Our fix (one line, stack_clear(c->stbase, STACK_INIT_SIZE) in stack_init) is a local vendored patch documented in vendor/mruby/README.md as re-apply-on-bump. It should be reported/PR'd upstream to mruby — it affects anyone embedding multiple VMs per process. Task: file the upstream mruby issue + PR, link here; once upstream merges + we bump past it, drop the local patch.

Refs #56, PR #59. https://claude.ai/code/session_011szWvquoss1yNX7KWSKCaM

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions