Memory-safety bug in Image11::map
- Fixed in 7 months
- Paid in 4 months
- Disclosed after 7 months
Image11::map (gfx\angle\src\libGLESv2\renderer\d3d\d3d11\image11.cpp) does not properly report error status if its call to deviceContext -> Map fails due to a "device lost" error. Instead, it returns GL_NO_ERROR. This can cause a caller to use an uninitialized D3D11_MAPPED_SUBRESOURCE object. One such caller is Image11::loadData, which uses an uninitialized D3D11_MAPPED_SUBRESOURCE to determine where to copy the data specified by its |input| argument. This can cause loadData to overwrite an arbitrary (and possibly quite large) block of memory with data from |input|.
The bug is at line 613, which should be followed by something like |return result;|
588:gl::Error Image11::map(D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map)
... [*map is not initialized]
608: HRESULT result = deviceContext->Map(stagingTexture, subresourceIndex, mapType, 0, map);
609:
610: // this can fail if the device is removed (from TDR)
611: if (d3d11::isDeviceLostError(result))
612: {
613: mRenderer->notifyDeviceLost();
614: }
615: else if (FAILED(result))
616: {
617: return gl::Error(GL_OUT_OF_MEMORY, "Failed to map staging texture, result: 0x%X.", result);
618: }
619:
620: mDirty = true;
621:
622: return gl::Error(GL_NO_ERROR);
623:}
The bug is activated by, e.g., loadData:
...
264: D3D11_MAPPED_SUBRESOURCE mappedImage;
265: gl::Error error = map(D3D11_MAP_WRITE, &mappedImage);
266: if (error.isError())
267: {
268: return error;
269: }
270:
271: uint8_t* offsetMappedData = (reinterpret_cast<uint8_t*>(mappedImage.pData) + (yoffset * mappedImage.RowPitch + xoffset * outputPixelSize + zoffset * mappedImage.DepthPitch));
272: loadFunction(width, height, depth,
273: reinterpret_cast<const uint8_t*>(input), inputRowPitch, inputDepthPitch,
274: offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch);
275:
276: unmap();
277:
278: return gl::Error(GL_NO_ERROR);
279:}
mappedImage is neither explicitly nor implicitly initialized before line 265 passes it to map. Line 271 then uses it to compute the destination address for a copy operation, and line 272 calls loadFunction to do the copy (which it does without testing for the error status set by map at line 613).
I have verified the above by using the debugger to to skip line 608 and force isDeviceLostError on line 611 to return |true|.
Additionally, unmap() on line 276 probably does something bad if line 608 fails.
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 high-severity security bug in Graphics. Mozilla made it public on 2 March 2016.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.