GitHub Advisoryadvisory · crates.io
GHSA-rwq6-crjg-9cpw ic-cdk has a memory leak when calling a canister method via `ic_cdk::call`
HIGH
Official page ↗
- Aliases
- CVE-2024-7884
- Ecosystem
- crates.io
- Packages
- ic_cdk
- Severity
- High
- CVSS vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
- Weaknesses
- CWE-401
- Reviewed
- 2024-09-05
Affected packages
• crates.io ic_cdk: >= 0.8.0, < 0.8.2 → fixed in 0.8.2
• crates.io ic_cdk: >= 0.9.0, < 0.9.3 → fixed in 0.9.3
• crates.io ic_cdk: >= 0.10.0, < 0.10.1 → fixed in 0.10.1
• crates.io ic_cdk: >= 0.11.0, < 0.11.6 → fixed in 0.11.6
• crates.io ic_cdk: >= 0.12.0, < 0.12.2 → fixed in 0.12.2
• crates.io ic_cdk: >= 0.13.0, < 0.13.5 → fixed in 0.13.5
• crates.io ic_cdk: >= 0.14.0, < 0.14.1 → fixed in 0.14.1
• crates.io ic_cdk: >= 0.15.0, < 0.15.1 → fixed in 0.15.1
Description
When a canister method is called via `ic_cdk::call*`, a new Future `CallFuture` is created and can be awaited by the caller to get the execution result. Internally, the state of the Future is tracked and stored in a struct called `CallFutureState`. A bug in the polling implementation of the `CallFuture` allows multiple references to be held for this internal state and not all references were dropped before the `Future` is resolved. Since we have unaccounted references held, a copy of the internal state ended up being persisted in the canister's heap and thus causing a memory leak.
Impact
Canisters built in Rust with `ic_cdk` and `ic_cdk_timers` are affected. If these canisters call a canister method, use timers or heartbeat, they will likely leak a small amount of memory on every such operation. In the worst case, this could lead to heap memory exhaustion triggered by an attacker.
Motoko based canisters are not affected by the bug.
Patches
The patch has been backported to all minor versions between `>= 0.8.0, [!NOTE]
> Upgrading the canisters (without updating `ic_cdk`) also frees the leaked memory but it's only a temporary solution.
References
• dfinity/cdk-rs/pull/509
• ic_cdk docs
• Internet Computer Specification
Related
Alias · CVE (1)
- CVE-2024-7884 When a canister method is called via ic_cdk::call* , a new Future CallFuture is created and can be awaited by the caller to get the… vulnerability
Weakness · CWE (1)
- CWE-401 Missing Release of Memory after Effective Lifetime weakness
References
- https://github.com/dfinity/cdk-rs/security/advisories/GHSA-rwq6-crjg-9cpw web
- https://nvd.nist.gov/vuln/detail/CVE-2024-7884 advisory
- https://github.com/dfinity/cdk-rs/pull/509 web
- https://github.com/dfinity/cdk-rs/commit/bd17d57a7b8ca59665fea5fad6143ca02724d03b web
- https://docs.rs/ic-cdk/latest/ic_cdk web
- https://github.com/dfinity/cdk-rs package
- https://internetcomputer.org/docs/current/references/ic-interface-spec web
- https://rustsec.org/advisories/RUSTSEC-2024-0372.html web