Overflow in XDRBuffer::grow can cause memory-safety bug
- Fixed in 51 days
- Paid in 58 days
- Disclosed after 51 days
XDRBuffer::grow (js/src/vm/Xdr.cpp, current trunk) can cause an overflow when computing the new buffer size. If this happens, grow allocates a buffer that is much too small, and its callers write far beyond its end:
27: bool
28: XDRBuffer::grow(size_t n)
29: {
30: MOZ_ASSERT(n > size_t(limit - cursor));
31:
32: const size_t MIN_CAPACITY = 8192;
33: size_t offset = cursor - base;
34: size_t newCapacity = mozilla::RoundUpPow2(offset + n);
35: if (newCapacity < MIN_CAPACITY)
36: newCapacity = MIN_CAPACITY;
37: if (isUint32Overflow(newCapacity)) {
38: js::gc::AutoSuppressGC suppressGC(cx());
39: JS_ReportErrorNumber(cx(), GetErrorMessage, nullptr, JSMSG_TOO_BIG_TO_ENCODE);
40: return false;
41: }
42:
43: void* data = js_realloc(base, newCapacity);
44: if (!data) {
45: ReportOutOfMemory(cx());
46: return false;
47: }
48: base = static_cast<uint8_t*>(data);
49: cursor = base + offset;
50: limit = base + newCapacity;
51: return true;
52: }
The problem occurs on 32-bit platforms only. If offset + n on line 34 exceeds 0x80000001, RoundUpPow2 returns 1 (1 << 32) under Windows 32-bit (note that this is actually undefined per C++11 s.5.8(1)). Lines 35-6 then calculate newCapacity==MIN_CAPACITY (8192). The test on line 37 is useless because newCapacity has already overflowed. Line 43 then allocates the tiny buffer, line 49 computes a cursor well outside the buffer's bounds, and the function returns true. Its caller then uses cursor to write into the buffer.
XDRBuffer appears to be used to serialize compiled javascripts. Is it possible for a web page to contain one or more gigantic javascripts that would invoke this bug?
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity security bug in JavaScript Engine. Mozilla made it public on 18 August 2015 as CVE-2015-7220.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.