Interger overflow in str_substr leading to read/write out of bound memory
An integer overflow in the str_substr function of mruby allows a crafted string slice request to bypass a length check, leading to out-of-bounds memory read/write. An attacker could potentially cause memory corruption or achieve remote code execution.
Originally disclosed on HackerOne
- Triaged in 15 days
- Fixed in 15 days
- Paid in 30 days
- Disclosed after 30 days
Failed check len & beg in str_substr when call mrb_str_aref_m by String. This can lead to read/write into invalid memory which may be memory corruption or RCE. this snippet causes a crash in mruby(i can't check mruby-engine by error undefined symbol >rb_utf8_str_new ):
$b="B"*2048
$expand=$b[0x40,0x7fffffff]
puts $expand.size()
puts $expand
And, here is error: beg=0x40, len=0x7fffffff, clen=0x800=> beg+len < clen(Integer Overflow)
static mrb_value
str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
{
/**
*..some code here
**/
if (beg + len > clen) => Integer overflow here
len = clen - beg;
if (len <= 0) {
len = 0;
}
return str_subseq(mrb, str, beg, len);
}
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 an integer overflow in the check 'beg + len > clen' when beg and len are large, causing the condition to evaluate incorrectly and allowing out-of-bounds access.
Impact
This could lead to memory corruption or remote code execution, though the report only demonstrates a crash.
What the attacker needed
Ability to run mruby code
How it was found
- Create a string of 2048 'B' characters.
- Request a substring starting at offset 0x40 with length 0x7fffffff.
- Observe the crash due to integer overflow in the length check.
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.
When you ask for part of a string, the program checks that the requested range fits inside the string. Here, adding two large numbers overflowed, so the check passed incorrectly, and the program then read or wrote memory outside the string. This can crash the program or let an attacker run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.