Skia integer-overflow in SkPathRef::resetToSize()
Categories
(Core :: Graphics, defect)
Tracking
()
People
(Reporter: dveditz, Assigned: lsalzman)
References
Details
(Keywords: csectype-intoverflow, sec-high, Whiteboard: [adv-main65.0.1+][adv-esr60.5.1+] (Google CVE-2018-18356))
Attachments
(1 file)
2.08 KB,
patch
|
rhunt
:
review+
RyanVM
:
approval-mozilla-beta+
RyanVM
:
approval-mozilla-release+
RyanVM
:
approval-mozilla-esr60+
dveditz
:
sec-approval+
|
Details | Diff | Splinter Review |
The Chrome 71 stable release blogpost references a use-after-free bug in Skia (crbug/883666). The bug itself says it's an integer overflow in SkPathRef::resetToSize().
This was found by fuzzing Skia directly under ASAN, and the Chrome team declined to award a bounty because they weren't convinced the conditions could happen in Chrome. That's probably true for us, too, but filing in case we want to uplift rather than wait for a future merge.
https://bugs.chromium.org/p/chromium/issues/detail?id=883666
https://skia.googlesource.com/skia/+/6a388006f5e3b270d206fb4c7e24accadb1c790f
A portion of the original bug:
To trigger this bug, we create a shallow copy of path object and call method incReserve. The program would run into SkPathRef::resetToSize() within reserveVerbs and reservePoints as value we pass into incReserve.
If reserveVerbs and reservePoints are large enough, we have an integer-overflow that lead to heap-buffer-overflow.REPRODUCTION CASE
Build Skia program with ASAN
#include "SkPath.h"
int main (int argc, char * const argv[]) {
SkPath path;
path.conicTo({0, 0}, {1, 1}, SK_FloatNegativeInfinity);
SkPath shallowPath = path; // <== use a copy path object to force program run into SkPathRef::copy() and SkPathRef::resetToSize()
shallowPath.incReserve(0xffffffff); // <== add 0xffffffff points trigger integer-overflow
return 0;
}
Reporter | ||
Comment 1•6 years ago
|
||
Lee: are we unaffected by this bug in practice, like Chrome, so we can wait to inherit the fix?
Assignee | ||
Comment 2•6 years ago
|
||
The supposition is that incReserve() would never get called with so high a value, and I believe that is why Chrome believes that it can't be used in practice. However, I can't see the Chromium bug report, so I can't confirm that.
The bad news is, I think I see a way to actually exploit this using Canvas2D. It would also theoretically affect Chrome, meaning their own assessment of this might be wrong. I will play with writing a testcase tomorrow.
Assignee | ||
Comment 3•6 years ago
|
||
I believe this is exploitable, so we should patch this.
Assignee | ||
Comment 4•6 years ago
|
||
Rough outline of an exploit:
SkPath p;
for(size_t i = 0; i < 45000000; i++) {
static const SkPoint pts[] = { { 0, 0 }, { -1, 3 }, { 0, 6 }, { -1, 9 }, { 0, 12 }, { 3, 13 }, { 6, 12 }, { 9, 13 }, { 12, 12 }, { 13, 9 }, { 12, 6 }, { 13, 3 }, { 12, 0 }, { 9, -1 }, { 6, 0 }, { 3, -1 } };
p.addPoly(pts, sizeof(pts) / sizeof(pts[0]), true);
}
SkPaint paint;
paint.setStrokeWidth(2);
paint.setStyle(SkPaint::kStroke_Style);
SkPath pp;
paint.getFillPath(p, &pp);
Essentially just create a path that has about 2^31/3 points in it. Then stroke it. The stroking code has a line that blindly multiplies countPoints() * 3, which then makes the int value negative, since countPoints() is int-typed, which gets passed into incReserve().
This could be reproduced fairly easily in Canvas2D.
Assignee | ||
Comment 5•6 years ago
|
||
Just a simple backport of upstream Skia fix.
Security Approval Request
How easily could an exploit be constructed based on the patch?
Upstream disclosed vulnerability.
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?
60+
If not all supported branches, which bug introduced the flaw?
None
Do you have backports for the affected branches?
Yes
If not, how different, hard to create, and risky will they be?
How likely is this patch to cause regressions; how much testing does it need?
Already tested by upstream
Beta/Release Uplift Approval Request
Feature/Bug causing the regression
None
User impact if declined
Upstream disclosed vulnerability
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)
Already tested by upstream
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
Upstream disclosed vulnerability
Fix Landed on Version
Risk to taking this patch
Low
Why is the change risky/not risky? (and alternatives if risky)
Already tested by upstream
String or UUID changes made by this patch
Reporter | ||
Comment 6•6 years ago
|
||
[Tracking Requested - why for this release]:
re-rating sec-high based on comment 4. The original rating was based on the Chrome bug's rating but they didn't think it was reachable from web content. And given that we should consider it for the fix-skia-things point release we're planning.
Updated•6 years ago
|
Reporter | ||
Comment 7•6 years ago
|
||
Updated•6 years ago
|
Comment 8•6 years ago
|
||
Updated•6 years ago
|
Comment 9•6 years ago
|
||
Comment 10•6 years ago
|
||
Comment 11•6 years ago
|
||
uplift |
Comment 12•6 years ago
|
||
uplift |
Comment 13•6 years ago
|
||
uplift |
Comment 14•6 years ago
|
||
(In reply to Lee Salzman [:lsalzman] from comment #5)
Is this code covered by automated tests?
Yes
Needs manual test from QE?
No
Setting this as qe-verify-.
Updated•6 years ago
|
Reporter | ||
Updated•6 years ago
|
Description
•