GHSA-H6XM-C6R4-VMWF
Vulnerability from github – Published: 2024-12-23 19:29 – Updated: 2024-12-23 19:29The library provides a safe public API unpack to cast u8 array to arbitrary types, which can cause to undefined behaviors. The length check of array can only prevent out-of-bound access on the return type. However, it can't prevent misaligned pointer when casting u8 pointer to a type aligned to larger bytes. For example, if we assign u16 to T, misaligned raw pointer dereference could happen and cause to panic. Even if we pass the type aligned to same byte as u8 (e.g., bool), it could construct a illegal type since bool can only have 0 or 1 as bit patterns, which is also an undefined behavior. The further exploits of the bug here are still not clear, so we would report this issue as unsound.
The details of PoC to reproduce undefined behavior are provided in the issue.
{
"affected": [
{
"package": {
"ecosystem": "crates.io",
"name": "spl-token-swap"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"last_affected": "3.0.0"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [],
"database_specific": {
"cwe_ids": [],
"github_reviewed": true,
"github_reviewed_at": "2024-12-23T19:29:44Z",
"nvd_published_at": null,
"severity": "MODERATE"
},
"details": "The library provides a safe public API `unpack` to cast `u8` array to arbitrary types, which can cause to undefined behaviors. The length check of array can only prevent out-of-bound access on the return type. However, it can\u0027t prevent misaligned pointer when casting `u8` pointer to a type aligned to larger bytes. For example, if we assign `u16` to `T`, **misaligned raw pointer dereference** could happen and cause to panic. Even if we pass the type aligned to same byte as `u8` (e.g., `bool`), it could construct a illegal type since `bool` can only have 0 or 1 as bit patterns, which is also an undefined behavior. The further exploits of the bug here are still not clear, so we would report this issue as unsound. \n\nThe details of PoC to reproduce undefined behavior are provided in the [issue](https://github.com/solana-labs/solana-program-library/issues/5243). \n",
"id": "GHSA-h6xm-c6r4-vmwf",
"modified": "2024-12-23T19:29:44Z",
"published": "2024-12-23T19:29:44Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/solana-labs/solana-program-library/issues/5243"
},
{
"type": "PACKAGE",
"url": "https://github.com/solana-labs/solana-program-library"
},
{
"type": "WEB",
"url": "https://rustsec.org/advisories/RUSTSEC-2024-0426.html"
}
],
"schema_version": "1.4.0",
"severity": [],
"summary": "Unsound usages of `u8` type casting in spl-token-swap"
}
Sightings
| Author | Source | Type | Date |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.