# GHSA-q669-2vfg-cxcg: Nervos CKB Unaligned Pointer Dereference

> Unaligned pointer dereferences in Nervos CKB library can cause undefined behavior and buffer overreads on malformed input, potentially leading to crashes or information disclosure.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 2 Feb 2024

## What is GHSA-q669-2vfg-cxcg?

GHSA-q669-2vfg-cxcg is a memory corruption vulnerability in ckb, published on 2 Feb 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

via bounty@nervos.org

There are multiple type conversions in ckb that unsafely cast between byte pointers and other types of pointers. This results in unaligned pointers, which are not allowed by the Rust language, and are considered undefined behavior, meaning that the compiler is free to do anything with code. This can lead to unpredictable bugs that can become security vulnerabilities.

Some of the bugs here could potentially lead to buffer overreads in malformed data (it's not clear to me as I haven't investigated the practical impact of these bugs).

Two of these (in blockchain.rs) do not create unaligned data. They do though perform an unsafe operation that may not uphold the invariants of the safe function they are in, and could lead to undefined behavior and buffer overreads on malformed input.

These are of the same nature as those in my previous report about the molecule crate.

Patch attached for commit 1b09e37c8e1b7945495cd18d9782417fbe51e986 that fixes all cases I know of at this time.

Please consider this report for reward under the terms of the bug bounty program.

Related advisory: https://github.com/nervosnetwork/molecule/security/advisories/GHSA-rffv-8x7x-p7pw

## Which versions are affected by GHSA-q669-2vfg-cxcg?

2 open source packages ship an affected version, including ckb.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `ckb` | crates.io | All versions | 0.31.1 |
| `ckb` | crates.io | All versions | 0.31.1 |

## How do I fix GHSA-q669-2vfg-cxcg?

Upgrade ckb to 0.31.1 or later.

## Is GHSA-q669-2vfg-cxcg being exploited?

There is no known exploitation of GHSA-q669-2vfg-cxcg in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-q669-2vfg-cxcg and fix it if it is affected.

What it is: GHSA-q669-2vfg-cxcg is a memory corruption vulnerability in ckb, published on 2 Feb 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-q669-2vfg-cxcg in the wild and no public exploit code.

Affected packages and fixed versions:
- ckb (crates.io): affected all versions; fixed in 0.31.1
- ckb (crates.io): affected all versions; fixed in 0.31.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-q669-2vfg-cxcg/ (Markdown: https://insights.sbomify.com/GHSA-q669-2vfg-cxcg/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-q669-2vfg-cxcg

---
From sbomify Insights: https://insights.sbomify.com/GHSA-q669-2vfg-cxcg/
Summaries are generated and may contain mistakes; the official description above is the record.
