Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add title and description to CWA-2023-004 #46

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion CWAs/CWA-2023-004.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CWA-2023-004
# CWA-2023-004: Excessive number of function paramters in compiled Wasm

**Severity**

Expand All @@ -20,6 +20,39 @@ and are neither patched nor analyzed.
- [wasmvm 1.4.2](https://github.com/CosmWasm/wasmvm/releases/tag/v1.4.2) (cosmwasm-vm 1.4.2)
- [wasmvm 1.5.1](https://github.com/CosmWasm/wasmvm/releases/tag/v1.5.1) (cosmwasm-vm 1.5.1)

## Description of the bug

In a Wasm file, the signature of a function is stored separately and referenced in the function.
This is demonstrated in the following example where you see

1. a function signature with two integers input and one integer output is defined
2. two functions referencing this signature are defined (`a+b` and `a-b`)
3. the two functions are exported under the names "sum" and "diff"

```wasm
(module
(type $binary_operation_t (func (param i32 i32) (result i32)))
(func $sum_f (type $binary_operation_t)
local.get 0
local.get 1
i32.add)
(func $diff_f (type $binary_operation_t)
local.get 0
local.get 1
i32.sub)
(export "sum" (func $sum_f))
(export "diff" (func $diff_f))
)
```

This is harmless in Wasm bytecode, but once the function is compiled, signatures are inlined multiple times
in the compiled code.
Using a large signature that is referenced by a large number of functions,
you get pretty much a compression bomb – small in the uploaded Wasm blob but huge after compilation.
This can lead to
modules of several hundreds of megabytes or even gigabytes, leading to unexpected cache behaviour, unexpected disk
consumption, slowdows and in some cases even crashes of the node process.

## Patch

- 1.5: https://github.com/CosmWasm/cosmwasm/compare/v1.5.0...v1.5.1
Expand Down Expand Up @@ -73,3 +106,4 @@ We extend our gratitude to the CertiK team for their professionalism and commitm
- 2024-01-08: Patch release announcement is sent to the notification list and posted in the Cosmos Hub Forum.
- 2024-01-09: Backports to CosmWasm 1.2, 1.3, 1.4, 1.5 are finalized.
- 2024-01-10: Patch released
- 2024-08-21: Title and description added to advisory
12 changes: 6 additions & 6 deletions CWAs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

## 2023

| Severity[^1] | Scope[^2] | ID |
| ------------ | --------- | --------------------------------------------------------------------------- |
| High | VM | [CWA-2023-004][CWA-2023-004] |
| Medium | x/wasm | [CWA-2023-003: Inefficient ListChannels query implementation][CWA-2023-003] |
| | VM | [CWA-2023-002: Stack overflow crash (Codename Cherry)][CWA-2023-002] |
| | VM | [CWA-2023-001: Potential overflow in cache statistics][CWA-2023-001] |
| Severity[^1] | Scope[^2] | ID |
| ------------ | --------- | ------------------------------------------------------------------------------------- |
| High | VM | [CWA-2023-004: Excessive number of function paramters in compiled Wasm][CWA-2023-004] |
| Medium | x/wasm | [CWA-2023-003: Inefficient ListChannels query implementation][CWA-2023-003] |
| | VM | [CWA-2023-002: Stack overflow crash (Codename Cherry)][CWA-2023-002] |
| | VM | [CWA-2023-001: Potential overflow in cache statistics][CWA-2023-001] |

[CWA-2023-004]: ./CWA-2023-004.md
[CWA-2023-003]: ./CWA-2023-003.md
Expand Down