could be trigger oom problem with WebGLBuffer::BufferData
Categories
(Core :: Graphics: CanvasWebGL, defect, P1)
Tracking
()
People
(Reporter: pwning.me, Assigned: sotaro)
References
Details
(Keywords: csectype-intoverflow, reporter-external, sec-high, Whiteboard: [adv-main67+][adv-esr60.7+])
Attachments
(7 files)
327 bytes,
text/html
|
Details | |
5.17 KB,
text/plain
|
Details | |
258 bytes,
text/html
|
Details | |
14.17 KB,
text/plain
|
Details | |
47 bytes,
text/x-phabricator-request
|
pascalc
:
approval-mozilla-beta+
lizzard
:
approval-mozilla-esr60+
abillings
:
sec-approval+
|
Details | Review |
265.49 KB,
image/png
|
Details | |
152.73 KB,
image/png
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36
Steps to reproduce:
void WebGLBuffer::BufferData(GLenum target, size_t size, const void* data,
GLenum usage) {
// Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr
// is like intptr_t.
if (!CheckedInt<GLsizeiptr>(size).isValid())
return mContext->ErrorOutOfMemory("bad size");
if (!ValidateBufferUsageEnum(mContext, usage)) return;
#ifdef XP_MACOSX
// bug 790879
if (mContext->gl->WorkAroundDriverBugs() && size > INT32_MAX) {
mContext->ErrorOutOfMemory("Allocation size too large.");
return;
}
#endif
const void* uploadData = data;
UniqueBuffer newIndexCache;
if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER &&
mContext->mNeedsIndexValidation) {
newIndexCache = malloc(size);
if (!newIndexCache) {
mContext->ErrorOutOfMemory("Failed to alloc index cache.");
return;
}
memcpy(newIndexCache.get(), data, size);
uploadData = newIndexCache.get();
}
The bufferdata function does not have an appropriate check for size value.
This coulde cause problems in the attached code.
I think it's almost impossible to exploit, but I think it's a security issue. :)
Updated•6 years ago
|
Comment 2•6 years ago
|
||
Ugh, we need to get rid of size_t.
Updated•6 years ago
|
Comment 3•6 years ago
|
||
Comment 4•6 years ago
|
||
It never occurred to me how dangerous malloc/calloc taking size_t was, but it's obvious now.
Comment 5•6 years ago
|
||
I'm not seeing the bug you're hitting in ASAN, except if it's a driver bug. I do see one frame of driver call in the asan stack, so that's possible.
Comment 6•6 years ago
|
||
In particular, this keeps everything here safe:
if (!CheckedInt<GLsizeiptr>(size).isValid())
return mContext->ErrorOutOfMemory("bad size");
This will error out if size_t size
is too large for GLsizeiptr. (size_t is unsigned, so it can never be too small)
So what do you think is the root cause of the bug?
I didn't see that properly code, but I knew for sure that oom occurred when i use bufferdata function.
(In reply to crixer from comment #8)
and i couldn't get that message when i test a poc
Comment 10•6 years ago
|
||
crixer: Why do you keep saying "oom" (out of memory)? is there some other data you haven't provided?
Jeff: are you saying this is not a security problem in comment 6, or is that just part of what's going on?
Updated•6 years ago
|
Comment 11•6 years ago
|
||
There's definitely issues here on 32bit builds, but I think on 64bit we should be doing everything correctly on our end. There's a chance the driver has a bug here though.
FWIW, WebGLintptr and WebGLsizeiptr are both int64_t, while GLintptr and GLsizeiptr are equivalent to intptr_t, which is int64_t on 64bit, but int32_t on 32bit. size_t is naturally uint64_t on 64bit, uint32_t on 32bit.
There is also an issue with handling GL_OUT_OF_MEMORY resulting from the glBufferData call, but I don't see how the POC could trigger it.
Reporter | ||
Comment 12•6 years ago
|
||
(In reply to Daniel Veditz [:dveditz] from comment #10)
crixer: Why do you keep saying "oom" (out of memory)? is there some other data you haven't provided?
Jeff: are you saying this is not a security problem in comment 6, or is that just part of what's going on?
the reason why i can say this is oom that i tested poc code on ubuntu and confirmed oom through dmesg.
Reporter | ||
Comment 13•6 years ago
|
||
but if test this case that will cause a heap overflow.
we also need to process this case too.
Reporter | ||
Comment 14•6 years ago
|
||
this is asan log for the new case.
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Comment 15•6 years ago
|
||
I'll be spinning up an ASAN env to dig into this better.
Updated•6 years ago
|
Comment 16•6 years ago
|
||
Hey Sotaro - would you be able to help with this bug this week?
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Comment 18•6 years ago
|
||
I tested Attachment 9049736 [details] on Windows10, I did not see the problem. Log had the following error.
WARN: handleError(8102): Error: 0x00000505, in c:/firefox_bld_dsk_2/mozilla-central/gfx/angle/checkout/src/libANGLE/renderer/d3d/d3d11/ResourceManager11.cpp, allocate:404. Internal D3D11 error: HRESULT: 0x8007000E: Error allocating Buffer
JavaScript warning: https://bug1532525.bmoattachments.org/attachment.cgi?id=9049736&t=kdFtTLYAqSqFIDisgxpZu9, line 7: Error: WebGL warning: bufferData: Error from driver: 0x0505
Assignee | ||
Comment 19•6 years ago
|
||
When I tested attachment 9049736 [details] on ubuntu 18.04.1 on VMWare, I could reproduce the problem, though I did not see the problem on ubuntu 18.04.1 that run as native on PC. From it, it seems like a driver specific problem.
Assignee | ||
Comment 20•6 years ago
|
||
about:support had the following driver info on ubuntu 18.04.1 on VMWare
GPU #1
- Description: SVGA3D; build: RELEASE; LLVM;
- Vendor ID: mesa/swrast
- Device ID: 0x0405
- Driver Version: 18.0.5.0
Assignee | ||
Comment 21•6 years ago
|
||
I tested attachment 9049736 [details] by modifying the size on ubuntu 18.04.1 on VMWare. From it, the driver might use int32_t for the size handling.
size 0x7fffffff : gl->fBufferData() failed
size 0x80000000 : gl->fBufferData() failed
size 0x80000001 : gl->fBufferData() did not exit
size 0xfffffff0 : gl->fBufferData() did not exit
size 0xfffffff1 : gl->fBufferData() caused "AddressSanitizer: stack-buffer-underflow"
size 0xfffffffe : gl->fBufferData() caused "AddressSanitizer: stack-buffer-underflow"
size 0xffffffff : gl->fBufferData() caused "AddressSanitizer: stack-buffer-underflow"
Assignee | ||
Comment 22•6 years ago
|
||
crixer, can you provide a graphics driver information from about:support?
Assignee | ||
Comment 23•6 years ago
|
||
Assignee | ||
Comment 24•6 years ago
|
||
Attachment 9060325 [details] is a simple fix for the problem.
Reporter | ||
Comment 26•6 years ago
|
||
Assignee | ||
Comment 27•6 years ago
|
||
Thanks!
Comment 28•6 years ago
|
||
We should figure out a path towards re-enabling this on supportive drivers, but that's a P3.
Assignee | ||
Comment 29•6 years ago
|
||
I will create a bug of comment 28.
Assignee | ||
Comment 30•6 years ago
|
||
Comment on attachment 9060325 [details]
Bug 1532525 - Enable size limit on linux
Security Approval Request
- How easily could an exploit be constructed based on the patch?: It seems relatively easy.
- Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: No
- Which older supported branches are affected by this flaw?: Since WebGL supprot
- If not all supported branches, which bug introduced the flaw?: None
- Do you have backports for the affected branches?: No
- If not, how different, hard to create, and risky will they be?: It is easy to create the backports.
- How likely is this patch to cause regressions; how much testing does it need?: It seems not cause regressions, since it just added max size limit on Linux that was already done on mac.
Security Approval Request
- How easily could an exploit be constructed based on the patch?: It seems relatively easy.
- Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: No
- Which older supported branches are affected by this flaw?: Since WebGL supprot
- If not all supported branches, which bug introduced the flaw?: None
- Do you have backports for the affected branches?: No
- If not, how different, hard to create, and risky will they be?: It is easy to create the backports.
- How likely is this patch to cause regressions; how much testing does it need?: It seems not cause regressions, since it just added max size limit on Linux that was already done on mac.
Assignee | ||
Comment 31•6 years ago
|
||
Updated•6 years ago
|
Comment 32•6 years ago
|
||
Comment on attachment 9060325 [details]
Bug 1532525 - Enable size limit on linux
sec-approval+ for trunk after discussion with Liz in release management. We'll want Beta and ESR60 patches made and nominated.
Updated•6 years ago
|
Assignee | ||
Comment 33•6 years ago
|
||
The same patch could be applied to Beta and ESR60.
Assignee | ||
Comment 34•6 years ago
|
||
Comment on attachment 9060325 [details]
Bug 1532525 - Enable size limit on linux
Beta/Release Uplift Approval Request
- User impact if declined: Malicious content could freeze or crash tab when a PC has a specific graphic driver on linux.
- Is this code covered by automated tests?: Yes
- Has the fix been verified in Nightly?: No
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: none
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): It added max size limit on Linux that was already done on mac.
- String changes made/needed:
ESR Uplift Approval Request
- If this is not a sec:{high,crit} bug, please state case for ESR consideration:
- User impact if declined: Malicious content could freeze or crash tab when a PC has a specific graphic driver on linux.
- Fix Landed on Version:
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): It added max size limit on Linux that was already done on mac.
- String or UUID changes made by this patch: none
Comment 35•6 years ago
|
||
This is not on trunk yet, will it land in time for our last betas this week?
Assignee | ||
Comment 36•6 years ago
|
||
Comment 37•6 years ago
|
||
Comment 38•6 years ago
|
||
Comment on attachment 9060325 [details]
Bug 1532525 - Enable size limit on linux
Uplift approved for 67 beta 15, thanks.
Comment 39•6 years ago
|
||
uplift |
Updated•6 years ago
|
Comment 40•6 years ago
|
||
Comment on attachment 9060325 [details]
Bug 1532525 - Enable size limit on linux
Fix for sec-high issue, seems low risk, linux-only.
OK for esr 60.7.
Comment 41•6 years ago
|
||
uplift |
Updated•6 years ago
|
Updated•6 years ago
|
Updated•5 years ago
|
Updated•8 months ago
|
Description
•