Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 29 Mar 2014 19:15:02 +0200
From: Timo Teras <>
Subject: Re: malloc not behaving well when brk space is limited?

On Sat, 29 Mar 2014 17:00:32 +0000 wrote:

> Background:
>  Compiling a native musl-based toolchain for ia32 on Linux 2.6+.
>  Using the standalone dynamic loader mode.
>  (The latter seems to lead to a quite limited heap space, by kernel
>  behaviour/design)
> I encounter out of memory errors. A look at the malloc source does not
> find any fallback to mmap when heap is exhausted. What would you
> suggest as a suitable approach to make it work?
> Somebody has possibly already encountered and solved this with musl?

Yes, been there done that. I patched kernel.

The thread that follows on sending the patch upstream is e.g. at:!msg/linux.kernel/mOf1EWrrhZc/bl96BAE4fyQJ

Also using grsec kernel would fix the issue mostly, since grsec creates
"better" memory layout for PIE binaries.

> I see also reports about a related out of memory problem with
> pae-executables which means a solution might help many musl users.
> The other standard libraries I am using (glibc, uclibc) seem to
> happily switch to allocation from mmap() when the heap is full. I
> understand that this costs some code and performance but a breakup is
> no good either.
> Any ideas? Maintaining and using an external libmalloc or substituting
> malloc in musl? This feels like quite a burden...
> (Would musl internal calls to malloc notice the external library
> and resolve to its entry points instead of the internal malloc?)

musl does not support external malloc. musl internal calls to
malloc() are not overridable.

I think you need to fix kernel. Rewrite allocator in musl. Or add the
fallback code to mmap - but dalias said it's "hard". Perhaps still
should be still reconsidered.

- Timo

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.