Skip to content

Commit cecd2ed

Browse files
gahaasCommit Bot
authored andcommitted
[wasm] Return immediately if code generation is not allowed
There was a bug in WebAssembly.instantiate in the case where a CSP disallows WebAssembly compilation. In this case the promise returned by WebAssembly.instantiate was rejected immediately because of the CSP, but then compilation was started anyways, and the promise was resolved after compilation for a second time, which caused the crash. With this CL we do not start compilation if CSP disallows WebAssembly compilation. [email protected] Bug: chromium:881978 Change-Id: Iffdb3e02c3006eb7f86211ab197f81cf20438f0e Reviewed-on: https://chromium-review.googlesource.com/1219706 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Clemens Hammacher <[email protected]> Cr-Commit-Position: refs/heads/master@{#55788}
1 parent e0e9461 commit cecd2ed

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/wasm/wasm-js.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ void WebAssemblyInstantiate(const v8::FunctionCallbackInfo<v8::Value>& args) {
818818
if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
819819
thrower.CompileError("Wasm code generation disallowed by embedder");
820820
compilation_resolver->OnCompilationFailed(thrower.Reify());
821+
return;
821822
}
822823

823824
// Asynchronous compilation handles copying wire bytes if necessary.

test/mjsunit/wasm/disallow-codegen.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ async function AsyncTestOk() {
6565
promise, module => assertInstanceof(module, WebAssembly.Module));
6666
}
6767

68+
async function AsyncTestWithInstantiateOk() {
69+
print('async module instantiate (ok)...');
70+
%DisallowCodegenFromStrings(false);
71+
%DisallowWasmCodegen(false);
72+
let promise = WebAssembly.instantiate(buffer);
73+
assertPromiseResult(
74+
promise,
75+
module => assertInstanceof(module.instance, WebAssembly.Instance));
76+
}
77+
6878
async function AsyncTestFail() {
6979
print('async module compile (fail)...');
7080
%DisallowCodegenFromStrings(true);
@@ -78,6 +88,19 @@ async function AsyncTestFail() {
7888
}
7989
}
8090

91+
async function AsyncTestWithInstantiateFail() {
92+
print('async module instantiate (fail)...');
93+
%DisallowCodegenFromStrings(true);
94+
%DisallowWasmCodegen(false);
95+
try {
96+
let m = await WebAssembly.instantiate(buffer);
97+
assertUnreachable();
98+
} catch (e) {
99+
print(" " + e);
100+
assertInstanceof(e, WebAssembly.CompileError);
101+
}
102+
}
103+
81104
async function AsyncTestWasmFail(disallow_codegen) {
82105
print('async wasm module compile (fail)...');
83106
%DisallowCodegenFromStrings(disallow_codegen);
@@ -91,6 +114,19 @@ async function AsyncTestWasmFail(disallow_codegen) {
91114
}
92115
}
93116

117+
async function AsyncTestWasmWithInstantiateFail(disallow_codegen) {
118+
print('async wasm module instantiate (fail)...');
119+
%DisallowCodegenFromStrings(disallow_codegen);
120+
%DisallowWasmCodegen(true);
121+
try {
122+
let m = await WebAssembly.instantiate(buffer);
123+
assertUnreachable();
124+
} catch (e) {
125+
print(" " + e);
126+
assertInstanceof(e, WebAssembly.CompileError);
127+
}
128+
}
129+
94130
async function StreamingTestOk() {
95131
print('streaming module compile (ok)...');
96132
// TODO(titzer): compileStreaming must be supplied by embedder.
@@ -149,14 +185,17 @@ async function RunAll() {
149185
await SyncTestOk();
150186
await SyncTestFail();
151187
await AsyncTestOk();
188+
await AsyncTestWithInstantiateOk();
152189
await AsyncTestFail();
190+
await AsyncTestWithInstantiateFail();
153191
await StreamingTestOk();
154192
await StreamingTestFail();
155193

156194
disallow_codegen = false;
157195
for (count = 0; count < 2; ++count) {
158196
SyncTestWasmFail(disallow_codegen);
159197
AsyncTestWasmFail(disallow_codegen);
198+
AsyncTestWasmWithInstantiateFail(disallow_codegen);
160199
StreamingTestWasmFail(disallow_codegen)
161200
disallow_codegen = true;
162201
}

0 commit comments

Comments
 (0)