Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix a panic using tables with the wrong type #8283

Conversation

alexcrichton
Copy link
Member

This commit fixes an accidental issue introduced in #8018 where using an element segment which had been dropped with an externref table would cause a panic. The panic happened due to an assertion that tables are being used with the right type of item and that was being mismatched. The underlying issue was that dropped element segments are modeled as an empty element segment but the empty element segment was using the "functions" encoding as opposed to the "expressions" encoding. This meant that code later assumed that due to the use of functions the table must be a table-of-functions, but this was not correct for externref-based tables.

The fix in this commit is to instead model the encoding as an "expressions" list which means that the table type is dispatched on to call the appropriate initializer.

There is no memory safety issue with this mistake as the assertion was specifically targetted at preventing memory safety. This does, however, enable any WebAssembly module to panic a host.

Closes #8281

This commit fixes an accidental issue introduced in bytecodealliance#8018 where using an
element segment which had been dropped with an `externref` table would
cause a panic. The panic happened due to an assertion that tables are
being used with the right type of item and that was being mismatched.
The underlying issue was that dropped element segments are modeled as an
empty element segment but the empty element segment was using the
"functions" encoding as opposed to the "expressions" encoding. This
meant that code later assumed that due to the use of functions the table
must be a table-of-functions, but this was not correct for
externref-based tables.

The fix in this commit is to instead model the encoding as an
"expressions" list which means that the table type is dispatched on to
call the appropriate initializer.

There is no memory safety issue with this mistake as the assertion was
specifically targetted at preventing memory safety. This does, however,
enable any WebAssembly module to panic a host.

Closes bytecodealliance#8281
@alexcrichton alexcrichton requested a review from a team as a code owner April 2, 2024 14:51
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team April 2, 2024 14:51
@alexcrichton
Copy link
Member Author

As I noted on the issue and per our policy this is actually a security vulnerability. I'll work on getting a 19.0.1 out today with this fix.

@alexcrichton alexcrichton added this pull request to the merge queue Apr 2, 2024
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Apr 2, 2024
This commit fixes an accidental issue introduced in bytecodealliance#8018 where using an
element segment which had been dropped with an `externref` table would
cause a panic. The panic happened due to an assertion that tables are
being used with the right type of item and that was being mismatched.
The underlying issue was that dropped element segments are modeled as an
empty element segment but the empty element segment was using the
"functions" encoding as opposed to the "expressions" encoding. This
meant that code later assumed that due to the use of functions the table
must be a table-of-functions, but this was not correct for
externref-based tables.

The fix in this commit is to instead model the encoding as an
"expressions" list which means that the table type is dispatched on to
call the appropriate initializer.

There is no memory safety issue with this mistake as the assertion was
specifically targetted at preventing memory safety. This does, however,
enable any WebAssembly module to panic a host.

Closes bytecodealliance#8281
Merged via the queue into bytecodealliance:main with commit 7f57d0b Apr 2, 2024
19 checks passed
@alexcrichton alexcrichton deleted the fix-panic-with-dropped-segment branch April 2, 2024 16:26
alexcrichton added a commit that referenced this pull request Apr 2, 2024
This commit fixes an accidental issue introduced in #8018 where using an
element segment which had been dropped with an `externref` table would
cause a panic. The panic happened due to an assertion that tables are
being used with the right type of item and that was being mismatched.
The underlying issue was that dropped element segments are modeled as an
empty element segment but the empty element segment was using the
"functions" encoding as opposed to the "expressions" encoding. This
meant that code later assumed that due to the use of functions the table
must be a table-of-functions, but this was not correct for
externref-based tables.

The fix in this commit is to instead model the encoding as an
"expressions" list which means that the table type is dispatched on to
call the appropriate initializer.

There is no memory safety issue with this mistake as the assertion was
specifically targetted at preventing memory safety. This does, however,
enable any WebAssembly module to panic a host.

Closes #8281
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Apr 2, 2024
gitlab-dfinity pushed a commit to dfinity/ic that referenced this pull request Apr 15, 2024
Chore: Upgrade wasmtime to v19.0.1

Upgrading wasmtime to v19.0.1

https://github.com/bytecodealliance/wasmtime/blob/main/RELEASES.md#1900

plus this change

bytecodealliance/wasmtime#8283

GHSA-75hq-h6g9-h4q5

We can upgrade other crates, such as wasmparser and wasm-encoder at a later time. Currently it seems that a lot of new types got introduced there, and it may be a good idea to give these changes a moment to settle. 

See merge request dfinity-lab/public/ic!18590
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic in table.init
2 participants