# GHSA-3mv5-343c-w2qg: Ref methods into_ref, into_mut, into_slice, and into_slice_mut are unsound when used with cell::Ref or cell::RefMut

> Unsound Ref methods in the zerocopy library allow safe code to trigger undefined behavior, potentially leading to memory corruption or crashes.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 14 Dec 2023
- **Also known as:** GHSA-rjhf-4mh8-9xjq, RUSTSEC-2023-0074

## What is GHSA-3mv5-343c-w2qg?

GHSA-3mv5-343c-w2qg is a memory corruption vulnerability in zerocopy, published on 14 Dec 2023. 

### Official description

*This advisory is also published as [RUSTSEC-2023-0074](https://rustsec.org/advisories/RUSTSEC-2023-0074.html).*

The `Ref` methods `into_ref`, `into_mut`, `into_slice`, and `into_slice_mut` are unsound and may allow safe code to exhibit undefined behavior when used with `Ref<B, T>` where `B` is [`cell::Ref`](https://doc.rust-lang.org/core/cell/struct.Ref.html) or [`cell::RefMut`](https://doc.rust-lang.org/core/cell/struct.RefMut.html). Note that these methods remain sound when used with `B` types other than `cell::Ref` or `cell::RefMut`.

See https://github.com/google/zerocopy/issues/716 for a more in-depth analysis.

The current plan is to yank the affected versions soon. See https://github.com/google/zerocopy/issues/679 for more detail.

## Which versions are affected by GHSA-3mv5-343c-w2qg?

25 open source packages ship an affected version, including zerocopy.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `zerocopy` | crates.io | From 0.2.2 | 0.2.9, 0.3.2, 0.4.1, 0.5.2, 0.6.6, 0.7.31 |
| `zerocopy` | crates.io | From 0.2.2 | 0.2.9 |
| `zerocopy` | crates.io | From 0.2.2 | 0.2.9 |
| `zerocopy` | crates.io | From 0.2.2 | 0.2.9 |
| `zerocopy` | crates.io | From 0.2.2 | 0.2.9 |
| `zerocopy` | crates.io | From 0.3.0 | 0.3.2 |
| `zerocopy` | crates.io | From 0.3.0 | 0.3.2 |
| `zerocopy` | crates.io | From 0.3.0 | 0.3.2 |
| `zerocopy` | crates.io | From 0.3.0 | 0.3.2 |
| `zerocopy` | crates.io | From 0.4.0 | 0.4.1 |
| `zerocopy` | crates.io | From 0.4.0 | 0.4.1 |
| `zerocopy` | crates.io | From 0.4.0 | 0.4.1 |
| `zerocopy` | crates.io | From 0.4.0 | 0.4.1 |
| `zerocopy` | crates.io | From 0.5.0 | 0.5.2 |
| `zerocopy` | crates.io | From 0.5.0 | 0.5.2 |
| `zerocopy` | crates.io | From 0.5.0 | 0.5.2 |
| `zerocopy` | crates.io | From 0.5.0 | 0.5.2 |
| `zerocopy` | crates.io | From 0.6.0 | 0.6.6 |
| `zerocopy` | crates.io | From 0.6.0 | 0.6.6 |
| `zerocopy` | crates.io | From 0.6.0 | 0.6.6 |
| `zerocopy` | crates.io | From 0.6.0 | 0.6.6 |
| `zerocopy` | crates.io | From 0.7.0 | 0.7.31 |
| `zerocopy` | crates.io | From 0.7.0 | 0.7.31 |
| `zerocopy` | crates.io | From 0.7.0 | 0.7.31 |
| `zerocopy` | crates.io | From 0.7.0 | 0.7.31 |

## How do I fix GHSA-3mv5-343c-w2qg?

Upgrade zerocopy to a fixed version for your release line: 0.2.9, 0.3.2, 0.4.1 or 0.5.2.

## Is GHSA-3mv5-343c-w2qg being exploited?

There is no known exploitation of GHSA-3mv5-343c-w2qg in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-3mv5-343c-w2qg and fix it if it is affected.

What it is: GHSA-3mv5-343c-w2qg is a memory corruption vulnerability in zerocopy, published on 14 Dec 2023. 
Exploitation: There is no known exploitation of GHSA-3mv5-343c-w2qg in the wild and no public exploit code.

Affected packages and fixed versions:
- zerocopy (crates.io): affected from 0.2.2; fixed in 0.2.9, 0.3.2, 0.4.1, 0.5.2, 0.6.6, 0.7.31
- zerocopy (crates.io): affected from 0.2.2; fixed in 0.2.9
- zerocopy (crates.io): affected from 0.2.2; fixed in 0.2.9
- zerocopy (crates.io): affected from 0.2.2; fixed in 0.2.9
- zerocopy (crates.io): affected from 0.2.2; fixed in 0.2.9
- zerocopy (crates.io): affected from 0.3.0; fixed in 0.3.2
- zerocopy (crates.io): affected from 0.3.0; fixed in 0.3.2
- zerocopy (crates.io): affected from 0.3.0; fixed in 0.3.2
- zerocopy (crates.io): affected from 0.3.0; fixed in 0.3.2
- zerocopy (crates.io): affected from 0.4.0; fixed in 0.4.1
- zerocopy (crates.io): affected from 0.4.0; fixed in 0.4.1
- zerocopy (crates.io): affected from 0.4.0; fixed in 0.4.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-3mv5-343c-w2qg/ (Markdown: https://insights.sbomify.com/GHSA-3mv5-343c-w2qg/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-3mv5-343c-w2qg

---
From sbomify Insights: https://insights.sbomify.com/GHSA-3mv5-343c-w2qg/
Summaries are generated and may contain mistakes; the official description above is the record.
