Null pointer dereference in OP_ENTER
A crafted Ruby class hierarchy where a subclass method calls super with a block argument and splatted arguments causes the interpreter to dereference a null array pointer. An attacker who can supply Ruby code could crash the interpreter process.
- Triaged in 37 hours
- Fixed in 9 days
- Paid in 9 days
- Disclosed after 13 days
PoC
The following demonstrates a crash:
class A
def foo
end
end
class B < A
def foo(*args)
super(*args, &:b)
end
end
B.new.foo
Debug info
The null pointer dereference happens in vm.c:1572 in both mruby and mruby-engine:
1570│ if (argc < 0) {
1571│ struct RArray *ary = mrb_ary_ptr(regs[1]);
1572├> argv = ary->ptr;
(gdb) p ary
$1 = (struct RArray *) 0x0
Test platform
- Linux Mint 17.3 (Cinnamon 64-bit), built with gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3
mruby SHA: a14a930c800aa50a191922580d53a2ce09287912 mruby-engine SHA: 09be20e67888b20bebf9b0588bc3cbec7f55325f
Thank you, Dinko Galetic Denis Kasak
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 OP_ENTER instruction handling does not account for a super call that combines splatted arguments with a block, leaving the argument array register unset before it is dereferenced.
Impact
The interpreter crashes when this code is run.
What the attacker needed
Ability to run Ruby code in mruby
How it was found
- Define a parent class with a method that takes no arguments.
- Define a child class whose method of the same name takes splatted arguments and calls super with those arguments plus a block.
- Instantiate the child class and call the method, which triggers the crash.
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.
A null pointer dereference is when a program tries to read from an address that points to nothing, which usually makes it crash. Here, a particular way of writing a Ruby method that passes arguments and a block up to its parent class leaves an internal array empty, and the interpreter then reads from it anyway. The result is a crash of the program running the code.
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.