Skip to content
DoS Disclosed report Intermediate

Undefined method_missing null pointer dereference

Undefining BasicObject#method_missing causes a null pointer dereference in mruby's method lookup fallback, leading to a segfault. An attacker could crash the interpreter by invoking a missing method via __send__ or super.

h72 Follow

Originally disclosed on HackerOne

Bounty$8,000 High View original
  • Triaged in 3 days
  • Fixed in 7 days
  • Paid in 35 days
  • Disclosed after 35 days

It's possible to segfault mruby by undefining BasicObject#method_missing in certain cases.

There is a fallback method_missing C function (mrb_method_missing) which is called in some cases when the VM fails to look up the method_missing method:

> BasicObject.remove_method(:method_missing); 1.foo
NoMethodError: undefined method 'foo' for 1

However the mrb_method_missing fallback is not consistently used.

Kernel#__send__ calls into mrb_funcall_with_block in vm.c, which contains the following code at line 362 (as of commit 88604e39ac9c25ffdad2e3f03be26516fe866038):

    c = mrb_class(mrb, self);
    p = mrb_method_search_vm(mrb, &c, mid);
    if (!p) {
      undef = mid;
      mid = mrb_intern_lit(mrb, "method_missing");
      p = mrb_method_search_vm(mrb, &c, mid);
      n++; argc++;
    }

If the method search for method_missing fails, p will be a null pointer. Further down on line 380, p is tested with MRB_PROC_CFUNC_P, which deferences p.

This segfault can be reproduced with the following code:

BasicObject.remove_method(:method_missing)
1.__send__(:foo)

The method search logic in the OP_SUPER instruction is also buggy. The same bug can be triggered through OP_SUPER with the following code:

BasicObject.remove_method(:method_missing)

class A
  def foo
    super
  end
end

A.new.foo

I'm not familiar enough with the mruby VM internals to write a patch for this. It should just be a matter of making sure mrb_method_missing is called if a method_missing method search fails (as the logic in OP_SEND instruction does).

The original report as published on HackerOne, by h72. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the method lookup for method_missing returns a null pointer, and later code dereferences it without checking.

What the attacker needed

Ability to run mruby code; ability to undefine method_missing

The fix

The fix should ensure that the fallback method_missing C function is called when the method search fails, as is done in the OP_SEND instruction.

How it was found

  1. Remove the method_missing method from BasicObject.
  2. Call a missing method using __send__ or super.
  3. Observe the segfault.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

mruby is a small Ruby interpreter. When you call a method that doesn't exist, Ruby normally calls a fallback called method_missing. If you remove that fallback, the interpreter tries to use a null pointer and crashes. This means a program can be crashed by calling a missing method after removing the fallback.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by h72

View all

6 more disclosed reports, best first.

More from shopify-scripts

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.