InsertD3D11FormatInfo can read beyond end of swizzleMap
In release builds, InsertD3D11FormatInfo dereferences an iterator without checking it against the map's end, so a missing swizzle entry causes an out-of-bounds read. The reporter observed the corresponding assertion fire in a debug build while loading a WebGL demo, indicating that external factors such as the video driver can trigger the condition.
- Fixed in 5.5 years
- Paid in 4 months
- Disclosed after 5.5 years
InsertD3D11FormatInfo (gfx\angle\src\libGLESv2\renderer\d3d\d3d11\formatutils11.cpp) does not, in the release version, check whether its swizzleIter != swizzleMap () end before dereferencing it:
687: static const SwizzleInfoMap swizzleMap = BuildSwizzleInfoMap();
688: SwizzleInfoMap::const_iterator swizzleIter = swizzleMap.find(SwizzleSizeType(maxBits, formatInfo.componentType));
689: ASSERT(swizzleIter != swizzleMap.end());
690:
691: const SwizzleFormatInfo &swizzleInfo = swizzleIter->second;
692: info.swizzleTexFormat = swizzleInfo.mTexFormat;
693: info.swizzleSRVFormat = swizzleInfo.mSRVFormat;
694: info.swizzleRTVFormat = swizzleInfo.mRTVFormat;
This can cause the function to read an element beyond the map's end, with unknown consequences.
I found this bug when the assert fired under 36.0.1 debug when testing WebGL with a new video card (NVIDIA GeForce GT 610 GPU, NVIDIA drivers 353.06, Win7 SP1 x64). I was visiting https://developer.cdn.mozilla.net/media/uploads/demos/j/c/jcarpenter/5ba2bcfa7e453d50149ba76819a02ec2/the-polar-sea_1415735678_demo_package/index.html , and got the following stack trace:
> msvcr120.dll!675f7cbd() Unknown [this is _wassert]
[Frames below may be incorrect and/or missing, no symbols loaded for msvcr120.dll]
libGLESv2.dll!rx::d3d11::InsertD3D11FormatInfo(std::map<unsigned int,rx::d3d11::TextureFormat,std::less<unsigned int>,std::allocator<std::pair<unsigned int const ,rx::d3d11::TextureFormat> > > * map, unsigned int internalFormat, DXGI_FORMAT texFormat, DXGI_FORMAT srvFormat, DXGI_FORMAT rtvFormat, DXGI_FORMAT dsvFormat) Line 687 C++
libGLESv2.dll!rx::d3d11::BuildD3D11FormatMap() Line 817 C++
libGLESv2.dll!rx::d3d11::GetTextureFormatInfo(unsigned int internalFormat) Line 851 C++
libGLESv2.dll!rx::d3d11_gl::GenerateTextureFormatCaps(unsigned int internalFormat, ID3D11Device * device) Line 233 C++
libGLESv2.dll!rx::d3d11_gl::GenerateCaps(ID3D11Device * device, gl::Caps * caps, gl::TextureCapsMap * textureCapsMap, gl::Extensions * extensions) Line 864 C++
libGLESv2.dll!rx::Renderer11::generateCaps(gl::Caps * outCaps, gl::TextureCapsMap * outTextureCaps, gl::Extensions * outExtensions) Line 3130 C++
libGLESv2.dll!rx::Renderer::getRendererCaps() Line 55 C++
libGLESv2.dll!rx::Blit11::Blit11(rx::Renderer11 * renderer) Line 188 C++
libGLESv2.dll!rx::Renderer11::initializeDevice() Line 312 C++
libGLESv2.dll!rx::Renderer11::initialize() Line 296 C++
libGLESv2.dll!glCreateRenderer(egl::Display * display, HDC__ * nativeDisplay, int requestedDisplayType) Line 155 C++
libEGL.dll!egl::Display::initialize() Line 81 C++
libEGL.dll!eglInitialize(void * dpy, int * major, int * minor) Line 187 C++
xul.dll!mozilla::gl::GLLibraryEGL::fInitialize(void * dpy, int * major, int * minor) Line 248 C++
xul.dll!mozilla::gl::GetAndInitDisplay(mozilla::gl::GLLibraryEGL & egl, void * displayType) Line 109 C++
xul.dll!mozilla::gl::GLLibraryEGL::EnsureInitialized() Line 274 C++
xul.dll!mozilla::gl::GLContextProviderEGL::CreateHeadless() Line 883 C++
xul.dll!CreateHeadlessANGLE(bool forceEnabled, const nsCOMPtr<nsIGfxInfo> & gfxInfo, mozilla::WebGLContext * webgl) Line 525 C++
xul.dll!CreateHeadlessGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo> & gfxInfo, mozilla::WebGLContext * webgl) Line 571 C++
xul.dll!mozilla::WebGLContext::CreateOffscreenGL(bool forceEnabled) Line 698 C++
xul.dll!mozilla::WebGLContext::SetDimensions(int signedWidth, int signedHeight) Line 851 C++
xul.dll!mozilla::dom::HTMLCanvasElement::UpdateContext(JSContext * aCx, JS::Handle<JS::Value> aNewContextOptions) Line 839 C++
xul.dll!mozilla::dom::HTMLCanvasElement::GetContext(JSContext * aCx, const nsAString_internal & aContextId, JS::Handle<JS::Value> aContextOptions, mozilla::ErrorResult & rv) Line 763 C++
xul.dll!mozilla::dom::HTMLCanvasElementBinding::getContext(JSContext * cx, JS::Handle<JSObject *> obj, mozilla::dom::HTMLCanvasElement * self, const JSJitMethodCallArgs & args) Line 215 C++
xul.dll!mozilla::dom::GenericBindingMethod(JSContext * cx, unsigned int argc, JS::Value * vp) Line 2434 C++
xul.dll!js::CallJSNative(JSContext * cx, bool (JSContext *, unsigned int, JS::Value *) * native, const JS::CallArgs & args) Line 231 C++
xul.dll!js::Invoke(JSContext * cx, JS::CallArgs args, js::MaybeConstruct construct) Line 484 C++
xul.dll!Interpret(JSContext * cx, js::RunState & state) Line 2541 C++
xul.dll!js::RunScript(JSContext * cx, js::RunState & state) Line 434 C++
xul.dll!js::ExecuteKernel(JSContext * cx, JS::Handle<JSScript *> script, JSObject & scopeChainArg, const JS::Value & thisv, js::ExecuteType type, js::AbstractFramePtr evalInFrame, JS::Value * result) Line 643 C++
xul.dll!js::Execute(JSContext * cx, JS::Handle<JSScript *> script, JSObject & scopeChainArg, JS::Value * rval) Line 680 C++
xul.dll!Evaluate(JSContext * cx, JS::Handle<JSObject *> obj, const JS::ReadOnlyCompileOptions & optionsArg, JS::SourceBufferHolder & srcBuf, JS::MutableHandle<JS::Value> rval) Line 4791 C++
xul.dll!Evaluate(JSContext * cx, JS::AutoObjectVector & scopeChain, const JS::ReadOnlyCompileOptions & optionsArg, JS::SourceBufferHolder & srcBuf, JS::MutableHandle<JS::Value> rval) Line 4817 C++
xul.dll!JS::Evaluate(JSContext * cx, JS::AutoObjectVector & scopeChain, const JS::ReadOnlyCompileOptions & optionsArg, JS::SourceBufferHolder & srcBuf, JS::MutableHandle<JS::Value> rval) Line 4872 C++
xul.dll!nsJSUtils::EvaluateString(JSContext * aCx, JS::SourceBufferHolder & aSrcBuf, JS::Handle<JSObject *> aEvaluationGlobal, JS::CompileOptions & aCompileOptions, const nsJSUtils::EvaluateOptions & aEvaluateOptions, JS::MutableHandle<JS::Value> aRetValue, void * * aOffThreadToken) Line 256 C++
xul.dll!nsJSUtils::EvaluateString(JSContext * aCx, JS::SourceBufferHolder & aSrcBuf, JS::Handle<JSObject *> aEvaluationGlobal, JS::CompileOptions & aCompileOptions, void * * aOffThreadToken) Line 329 C++
xul.dll!nsScriptLoader::EvaluateScript(nsScriptLoadRequest * aRequest, JS::SourceBufferHolder & aSrcBuf, void * * aOffThreadToken) Line 1144 C++
xul.dll!nsScriptLoader::ProcessRequest(nsScriptLoadRequest * aRequest, void * * aOffThreadToken) Line 973 C++
xul.dll!nsScriptLoader::ProcessScriptElement(nsIScriptElement * aElement) Line 781 C++
xul.dll!nsScriptElement::MaybeProcessScript() Line 140 C++
xul.dll!nsIScriptElement::AttemptToExecute() Line 220 C++
xul.dll!nsHtml5TreeOpExecutor::RunScript(nsIContent * aScriptElement) Line 663 C++
xul.dll!nsHtml5TreeOpExecutor::RunFlushLoop() Line 491 C++
xul.dll!nsHtml5ExecutorReflusher::Run() Line 56 C++
xul.dll!nsThread::ProcessNextEvent(bool aMayWait, bool * aResult) Line 830 C++
xul.dll!NS_ProcessNextEvent(nsIThread * aThread, bool aMayWait) Line 265 C++
xul.dll!mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate * aDelegate) Line 99 C++
xul.dll!MessageLoop::RunInternal() Line 234 C++
xul.dll!MessageLoop::RunHandler() Line 227 C++
xul.dll!MessageLoop::Run() Line 201 C++
xul.dll!nsBaseAppShell::Run() Line 166 C++
xul.dll!nsAppShell::Run() Line 178 C++
xul.dll!nsAppStartup::Run() Line 281 C++
xul.dll!XREMain::XRE_mainRun() Line 4220 C++
xul.dll!XREMain::XRE_main(int argc, char * * argv, const nsXREAppData * aAppData) Line 4296 C++
xul.dll!XRE_main(int argc, char * * argv, const nsXREAppData * aAppData, unsigned int aFlags) Line 4516 C++
firefox.exe!do_main(int argc, char * * argv, nsIFile * xreDirectory) Line 292 C++
firefox.exe!NS_internal_main(int argc, char * * argv) Line 661 C++
firefox.exe!wmain(int argc, wchar_t * * argv) Line 117 C++
[External Code]
Tracing this code under 39.0 release (on the same system) shows that swizzleIter never == swizzleMap.end(), presumably due to some other change.
The lack of a release-version failout is a bug unless it's now impossible for external code (e.g., a video driver) to cause InsertD3D11FormatInfo to go off the map's end.
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 code assumes the swizzle map always contains an entry for the given format and only guards the lookup with a debug assertion, so release builds proceed to dereference an end iterator.
Impact
The out-of-bounds read could have unknown consequences, though the reporter notes that in a later release the iterator never reached the end, possibly due to other changes.
What the attacker needed
Browser debug build; specific NVIDIA GPU and drivers; visiting a WebGL page
The fix
The code should check the iterator against the map's end in release builds and handle the missing entry safely, unless it is proven impossible for external code to trigger the condition.
How it was found
- Open a browser debug build on a system with the specified NVIDIA GPU and drivers.
- Visit the WebGL demo page that triggers the code path.
- Observe the assertion failure in InsertD3D11FormatInfo.
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 program looks up a value in a table but forgets to check whether the value is actually there. If it is missing, the program reads past the end of the table, which can cause crashes or unpredictable behaviour. The reporter saw this happen when a web page used WebGL, a browser feature for 3D graphics.
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.