mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: incompatibility between libtheora/mmx and musl ?
Date: Wed, 14 Sep 2016 13:24:00 +0200	[thread overview]
Message-ID: <20160914112400.GS1280@port70.net> (raw)
In-Reply-To: <20160914103253.GO16436@example.net>

* u-uy74@aetey.se <u-uy74@aetey.se> [2016-09-14 12:32:53 +0200]:
> On Tue, Sep 13, 2016 at 04:43:04PM -0400, Rich Felker wrote:
> > > Libtheora contains an assembler part for ia32 and x86_64 which has been
> > > in use for many years, with at least both glibc and uclibc.
> > > 
> > > Now, musl-based builds of libtheora for ia32 with this code enabled
> > > lead to the encoder segfaulting. No problem when using the C version.
> 
> > >  https://trac.xiph.org/ticket/2287
> > > 
> > > There is also a corresponding
> > > 
> > >  https://bugs.alpinelinux.org/issues/6132
> > 
> > The most likely explanation is that they're overflowing a heap buffer.
> > Perhaps it would be possible to pad all their malloc/realloc calls
> > with +64 or so to see if that makes the problem go away. If so that
> > gives a good starting point for tracking down the bug.
> 
> Thanks for the suggestion, indeed libtheora seems to consistently use
> ogg_malloc() which is redefinable.
> 
> Building with
> 
>  #define _ogg_malloc(x)  malloc((x)+256)
>  #define _ogg_calloc(x,y)  calloc((x)+256,(y))
>  #define _ogg_realloc(y,x) realloc((y),(x)+256)
>  #define _ogg_free    free
> 
> instead of the default
> 
>  #define _ogg_malloc  malloc
>  #define _ogg_calloc  calloc
>  #define _ogg_realloc realloc
>  #define _ogg_free    free
> 
> did not make any difference. The crash on a test file occurs in the same
> way and the resulting partial output file is as long as otherwise.
> 
> This may mean that this is not a simple overflowing but rather
> overwriting or reading distant "random" places (?) (register corruption?)
> 

can be underflow (or the way they align the pointer returned by malloc)

you can increase/decrease alignment of musl's alloc by
changing SIZE_ALIGN in src/malloc/malloc.c
(or you can try some hack in _ogg_malloc/free if you are
sure that's what they are using)

there can be some call abi issue (register clobbering,
stack alignment,..) because of the asm, but that's hard
to check.

you may try tracing malloc calls (i don't know an easy
way other than instrumenting musl, you can try python
scripting gdb, the default gdb command language is not
enough for reporting malloc args and return values).


  reply	other threads:[~2016-09-14 11:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13 18:06 u-uy74
2016-09-13 19:20 ` Markus Wichmann
2016-09-13 20:41   ` Rich Felker
2016-09-13 20:43 ` Rich Felker
2016-09-14 10:32   ` u-uy74
2016-09-14 11:24     ` Szabolcs Nagy [this message]
2016-09-14 14:04       ` u-uy74
2016-09-14 14:28         ` Rich Felker
2016-09-14 14:31           ` Timo Teras
2016-09-14 14:39             ` Rich Felker
2016-09-14 14:40           ` Rich Felker
2016-09-14 14:41           ` Szabolcs Nagy
2016-09-14 15:11             ` u-uy74
2016-10-02 10:59             ` "non-float" malloc (was: incompatibility between libtheora/mmx and musl) u-uy74
2016-10-02 11:17               ` u-uy74
2016-10-02 12:08               ` Szabolcs Nagy
2016-10-02 12:24                 ` u-uy74
2016-10-02 13:24                   ` u-uy74

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=20160914112400.GS1280@port70.net \
    --to=nsz@port70.net \
    --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).