Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <2631c431.2a5e9.1a1f24047d3.Coremail.zhaotq@pku.edu.cn>
Date: Thu, 19 Nov 2026 13:21:01 +0800 (GMT+08:00)
From: zhaotq@....edu.cn
To: musl@...ts.openwall.com
Subject: musl libc 1.2.5: putenv() self-overwrite leaves a dangling environ
 entry

Hello,

We are developing a software verification tool. During an audit of musl libc
1.2.5 we found a heap use-after-free in the environment implementation. The
local test used musl 1.2.5 and the same source is still present in current
musl master at the time of writing.

The issue occurs when an application obtains a name=value entry allocated by
setenv(), and passes that same pointer back to putenv():

    setenv("MUSL_PUTENV_SELF_UAF", "initial-value", 1);
    entry = find_entry_in_environ("MUSL_PUTENV_SELF_UAF");
    putenv(entry);

musl's __putenv() replaces the pointer in environ, then passes the old pointer
to __env_rm_add(). For this self-overwrite, the old and new pointers are the
same, but __env_rm_add() still frees the allocation. environ continues to point
at the freed buffer, and a later getenv() reads freed heap memory.

This is a memory-safety bug, and it also conflicts with POSIX.1-2024 XSH
putenv(): its DESCRIPTION requires that, on success, the string passed to
putenv() shall become part of the environment, and its RETURN VALUE section
requires successful completion to return 0. A successful call cannot leave
environ holding invalid storage that getenv() then consumes.

A reduced ASan PoC is:

    #define _GNU_SOURCE
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    int main(void)
    {
        char *entry = 0;
        if (clearenv() || setenv("MUSL_PUTENV_SELF_UAF",
                                 "initial-value", 1))
            return 1;
        for (char **e = environ; e && *e; e++)
            if (!strncmp(*e, "MUSL_PUTENV_SELF_UAF=", 21)) {
                entry = *e;
                break;
            }
        if (!entry || putenv(entry))
            return 2;
        puts(getenv("MUSL_PUTENV_SELF_UAF"));
        return 0;
    }

Reproduction:

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

Expected marker: UAF_REPRODUCED=1. The optional ASan path is
`./poc/run.sh`; it requires a host C compiler with AddressSanitizer.

`prepare.sh` downloads the official musl 1.2.5 source from
https://musl.libc.org/releases/musl-1.2.5.tar.gz and verifies this SHA-256:
a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4.

Attached are the PoC archive and README.md. The README provides the
checksum, environment requirements, reproduction commands for both the Docker
and host ASan paths, and observed output excerpts.

Archive SHA-256: 1349b401e1c1f0124642add637171cbe68bfe516d4e98142936951ca27e5c015

We would appreciate your assessment of the security impact and whether
a CVE is warranted. 

Thanks,
Tianqi

Download attachment "01-putenv-self-uaf.tar.gz" of type "application/x-gzip" (3576 bytes)

Download attachment "README.md" of type "application/octet-stream" (2353 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.