# Reproducer for `putenv()` self-overwrite UAF

This directory is the complete material for one Openwall report. The email
attachments are:

- `01-putenv-self-uaf.tar.gz`
- `README.md`

Archive SHA-256:

```text
1349b401e1c1f0124642add637171cbe68bfe516d4e98142936951ca27e5c015
```

The archive contains only this report's PoC files and `prepare.sh`:

```text
poc/run.sh
poc/putenv-self-uaf.c
poc/poc-compat.h
poc/linux/Dockerfile
poc/linux/run.sh
poc/linux/putenv-self-uaf.c
prepare.sh
```

`prepare.sh` downloads the official musl 1.2.5 source archive from
`https://musl.libc.org/releases/musl-1.2.5.tar.gz`, verifies its SHA-256, and
places this report's `poc/` directory into the source tree.

Official source SHA-256:

```text
a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4
```

## Requirements

- Docker with Linux containers for the native musl path.
- `curl` or `wget`, `tar`, and a SHA-256 utility.
- Network access for the official source and first base-image pull.
- Alternatively, a host C compiler with AddressSanitizer for the ASan path;
  this path does not need Docker.
- About 2 GB of free Docker storage.

## Reproduce

```sh
tar xzf 01-putenv-self-uaf.tar.gz
./prepare.sh
cd musl-1.2.5
./poc/linux/run.sh
```

Expected Docker marker:

```text
UAF_REPRODUCED=1
```

Observed native musl allocator-reuse output (pointer abbreviated):

```text
after reallocation: malloc returned <same pointer as entry>
after reallocation: getenv returned reallocated
UAF_REPRODUCED=1
```

Sanitizer-only path:

```sh
./poc/run.sh
```

It must report a heap-use-after-free in `getenv()` with the allocation freed
through `__env_rm_add()` and `__putenv()`.

Observed ASan output excerpt (addresses and stack details abbreviated):

```text
ERROR: AddressSanitizer: heap-use-after-free
READ ... in getenv
freed by __env_rm_add -> __putenv -> putenv
previously allocated by setenv
```

## Tested environment

- Docker client/server 29.3.1
- Docker Desktop 4.68.0
- Host: macOS ARM64 (`darwin/arm64`)
- Docker server: `linux/arm64`
- Kernel: `6.12.76-linuxkit`
- Storage: overlayfs, cgroup v2
- CPUs: 12
- Docker memory: 7.652 GiB
- Base image: `gcc:12-bookworm` pinned by digest

The Docker path was tested on the above environment. Native execution on an
ARM64 Linux host is equivalent; on other hosts Docker must provide ARM64
emulation.
