From: sva sva <azharivs@gmail.com>
To: musl@lists.openwall.com
Subject: Re: Hijacking malloc called within musl libc
Date: Fri, 31 May 2019 00:13:27 -0400 [thread overview]
Message-ID: <CAKsLdYw=aG95w5tWD9_-KNKZid-cM=DvCS9huWaADVT-_ONK1g@mail.gmail.com> (raw)
In-Reply-To: <20190530222959.GU16415@port70.net>
[-- Attachment #1: Type: text/plain, Size: 1794 bytes --]
I am interposing all malloc/calloc/realloc/free/memalign but still the
realloc in scandir gets called from musl's libc. Does that make sense?
Vahid
On Thu, May 30, 2019 at 6:30 PM Szabolcs Nagy <nsz@port70.net> wrote:
> * sva sva <azharivs@gmail.com> [2019-05-30 16:39:48 -0400]:
> > I am LD_PRELOADing an application my own malloc which eventually calls
> the
> > libc malloc. Everything is fine until the code hits malloc which is
> called
>
> musl has explicit checks not to allow libc internal malloc
> calls if user malloc is used (at least for memalign),
> because mixing user malloc and libc malloc is problematic.
>
> this means that currently the common malloc wrapping methods
> don't work on musl. (you can try to copy the musl malloc
> implementation into an external library and work with that
> instead of calling back to libc malloc, but it might need
> some changes)
>
> > from musl's own libc which doesn't get overloaded. I want those to be
> > overloaded as well.
> >
> > More specifically this is the part of libc for scandir code at
> > src/dirent/scandir.c:
> > tmp = realloc(names, len * sizeof *names);
>
> if you define malloc/calloc/realloc/memalign/free then
> all musl internal calls to those functions will go to
> your definitions (including the realloc in scandir).
>
> (if you only interpose a subset of the malloc functions
> that's broken and cannot work)
>
> >
> > I checked how this works for glibc, and apparently they use
> > __libc_malloc/etc. internally and have malloc as a weak alias for that
> > which is used every where including the rest of the standard library.
> > However in musl, there is no such thing as a weak alias defined for
> > malloc/etc.
> >
> > I am kind of stuck here so would appreciate some help.
> >
> > Thanks
> >
> > Vahid
>
[-- Attachment #2: Type: text/html, Size: 2374 bytes --]
next prev parent reply other threads:[~2019-05-31 4:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-30 20:39 sva sva
2019-05-30 22:29 ` Szabolcs Nagy
2019-05-31 4:13 ` sva sva [this message]
2019-05-31 11:43 ` Szabolcs Nagy
2019-05-31 13:34 ` Rich Felker
2019-06-03 18:46 ` sva sva
2019-06-03 20:18 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKsLdYw=aG95w5tWD9_-KNKZid-cM=DvCS9huWaADVT-_ONK1g@mail.gmail.com' \
--to=azharivs@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).