Closed Bug 1525817 (CVE-2018-18356) Opened 1 year ago Closed 1 year ago

Skia integer-overflow in SkPathRef::resetToSize()


(Core :: Graphics, defect)

Not set



Tracking Status
firefox-esr60 65+ fixed
firefox65 + fixed
firefox66 + fixed
firefox67 + fixed


(Reporter: dveditz, Assigned: lsalzman)



(Keywords: csectype-intoverflow, sec-high, Whiteboard: [adv-main65.0.1+][adv-esr60.5.1+] (Google CVE-2018-18356))


(1 file)

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.

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.

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; 

Lee: are we unaffected by this bug in practice, like Chrome, so we can wait to inherit the fix?

Flags: needinfo?(lsalzman)
Whiteboard: (Google CVE-2018-18356)

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.

Flags: needinfo?(lsalzman)

I believe this is exploitable, so we should patch this.

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;
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.

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?


Which older supported branches are affected by this flaw?


If not all supported branches, which bug introduced the flaw?


Do you have backports for the affected branches?


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


User impact if declined

Upstream disclosed vulnerability

Is this code covered by automated tests?


Has the fix been verified in Nightly?


Needs manual test from QE?


If yes, steps to reproduce

List of other uplifts needed


Risk to taking this patch


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


Why is the change risky/not risky? (and alternatives if risky)

Already tested by upstream

String or UUID changes made by this patch

Assignee: nobody → lsalzman
Attachment #9042284 - Flags: sec-approval?
Attachment #9042284 - Flags: review?(rhunt)
Attachment #9042284 - Flags: approval-mozilla-release?
Attachment #9042284 - Flags: approval-mozilla-esr60?
Attachment #9042284 - Flags: approval-mozilla-beta?

[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.

Comment on attachment 9042284 [details] [diff] [review]
be consistent about int for incReserve

sec-approval=dveditz assuming review and branch approvals will be granted.
Attachment #9042284 - Flags: sec-approval? → sec-approval+
Attachment #9042284 - Flags: review?(rhunt) → review+
Alias: CVE-2018-18356
Group: gfx-core-security → core-security-release
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
Comment on attachment 9042284 [details] [diff] [review]
be consistent about int for incReserve

[Triage Comment]
Approved for 66.0b7, 65.0.1, and 60.5.1esr.
Attachment #9042284 - Flags: approval-mozilla-release?
Attachment #9042284 - Flags: approval-mozilla-release+
Attachment #9042284 - Flags: approval-mozilla-esr60?
Attachment #9042284 - Flags: approval-mozilla-esr60+
Attachment #9042284 - Flags: approval-mozilla-beta?
Attachment #9042284 - Flags: approval-mozilla-beta+

(In reply to Lee Salzman [:lsalzman] from comment #5)

Is this code covered by automated tests?


Needs manual test from QE?


Setting this as qe-verify-.

Flags: qe-verify-
Whiteboard: (Google CVE-2018-18356) → [adv-main65.0.1+][adv-esr60.5.1+] (Google CVE-2018-18356)
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.