WAVM: Incorrect bounds check when translating a reference type can results in buffer overrun
When translating an offset to wasm memory for a reference, the bounds check is as following:
At wavm.hpp, line 585:
if(!mem || ptr+sizeof(T) >= IR::numBytesPerPage*Runtime::getMemoryNumPages(mem))
Runtime::causeException(Exception::Cause::accessViolation);
Here |ptr|'s type is I32, which means it can be a negative value, so in the below situation when -sizeof(T) < ptr < 0, ptr+sizeof(T) will be a very small value which can bypass this check,
And later,
T &base = (T)(getMemoryBaseAddress(mem)+ptr);
|base| will points beyond the wasm memory base, which means we can read/write beyond the wasm memory buffer.
This is a submission to the EOS bug bounty program.
This bug credits to:
Yuki Chen of Qihoo 360 Vulcan Team.
Thank you!
Hi,
Quick & Nice fix. Now may I know if this submission is eligible for your bug bounty program? thank you!
Hey, guys, should we check the overflow of (U32)ptr+sizeof(T) ?
On May 30, 2018, at 10:47 PM, Daniel Larimer [email protected] wrote:
Closed #3540 https://github.com/EOSIO/eos/issues/3540.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/EOSIO/eos/issues/3540#event-1653756424, or mute the thread https://github.com/notifications/unsubscribe-auth/Ad6ZPltkD5tChjIHhAUdCssjJwlrY_PKks5t3rDogaJpZM4URZ4o.
Well, since the type of sizeof(T) is an unsigned long(8 bytes on x64 platform), so compiler will expand (U32)ptr(4 bytes) to unsigned long, there is no need to worry about overflow. Thank goodness.
On May 31, 2018, at 1:27 AM, john rok [email protected] wrote:
Hey, guys, should we check the overflow of (U32)ptr+sizeof(T) ?
On May 30, 2018, at 10:47 PM, Daniel Larimer <[email protected] mailto:[email protected]> wrote:
Closed #3540 https://github.com/EOSIO/eos/issues/3540.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/EOSIO/eos/issues/3540#event-1653756424, or mute the thread https://github.com/notifications/unsubscribe-auth/Ad6ZPltkD5tChjIHhAUdCssjJwlrY_PKks5t3rDogaJpZM4URZ4o.