Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20261119142501.GD5716@brightrain.aerifal.cx>
Date: Thu, 19 Nov 2026 09:25:01 -0500
From: Rich Felker <dalias@...c.org>
To: zhaotq@....edu.cn
Cc: musl@...ts.openwall.com
Subject: Re: musl libc 1.2.5: fmemopen(NULL, 0, "w+") writes past a
 zero-capacity buffer

On Thu, Nov 19, 2026 at 01:34:05PM +0800, zhaotq@....edu.cn wrote:
> Hello,
> 
> We found a deterministic one-byte heap out-of-bounds write in musl 1.2.5:
> 
>     fmemopen(NULL, 0, "w+");
> 
> [...]
> 
> The guarded PoC replaces malloc() so the stream object ends immediately
> before a PROT_NONE page. The fault address falls in that page, confirming
> the out-of-bounds write at the public API boundary. The key implementation is:
> 
>     static int arm_guard;
> 
>     void *malloc(size_t n)
>     {
>         if (arm_guard) {
>             unsigned char *pages =
>                 mmap(0, 8192, PROT_READ|PROT_WRITE,
>                      MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
>             if (pages == MAP_FAILED) return 0;
>             mprotect(pages + 4096, 4096, PROT_NONE);
>             return pages + 4096 - n;
>         }
>         return 0;
>     }
> 
>     int main(void)
>     {
>         arm_guard = 1;
>         fmemopen(0, 0, "w+");
>         return 0;
>     }

Simpler test case:

fmemopen("", 0, "w+");

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.