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 13:22:12 -0400
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Cc: u-igbb@...ey.se
Subject: Re: malloc not behaving well when brk space is limited?

On Sat, Mar 29, 2014 at 07:15:02PM +0200, Timo Teras wrote:
> On Sat, 29 Mar 2014 17:00:32 +0000
> u-igbb@...ey.se 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:
> https://groups.google.com/forum/#!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.

Unfortunately the approach I want to use with mmap seems to be what
glibc uses for its thread-local arenas, and it performs something like
2 to 10 times worse than brk... So unless we can solve that, I don't
think it's a good option. It could be a fallback, but I still don't
want PIE binaries running that much slower just because the kernel is
doing something wacky and wrong.

We need a good solution for this problem but I don't have one yet.

Rich

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.