Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170702143539.GK1627@brightrain.aerifal.cx>
Date: Sun, 2 Jul 2017 10:35:39 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [RFC PATCH] Allow annotating calloc for Valgrind

On Sun, Jul 02, 2017 at 04:55:08PM +0300, Alexander Monakov wrote:
> On Thu, 29 Jun 2017, Rich Felker wrote:
> > It reached the point of an faq item on irc; perhaps it was never
> > discussed on the ml.
> 
> I feel a quick reminder of what was discussed would be very nice.

I'm not sure I can do the topic justice without digging through a lot
of old logs. I don't want to misrepresent what anyone said.

> > If that happens, it's just a valgrind bug. It can see the memory was
> > returned by calloc and therefore the contents are defined. But maybe
> > before discussing this further we need to clarify what the actual
> > scenario is.
> 
> Alright. As far as I can tell, everyone hits this (only) with static
> linking. Valgrind core *does* have a concept of a symbol table being
> distinct from dynamic symbol table (info from symtab is successfully
> used for backtracing for example), so in principle Memcheck could use
> just the .symtab when running unstripped static executables.
> 
> Unfortunately, historically the implementation of Memcheck relies
> entirely on dynamic linking to intercept allocation functions. As a
> result, Memcheck's functionality on static executables degrades
> significantly (it can still find a subset of uninit access errors).
> 
> I guess the proper fix - wiring up .symtab-based interception - might
> require more time than anyone was prepared to volunteer.
> 
> I think at the moment client requests are the only straightforward way
> to use Memcheck fully with statically-linked programs.  But for full
> functionality, people would need extra requests informing Memcheck
> about the effects of static malloc & free. Where would such a patch
> belong?

I'm not sure it makes sense to do -- is there a good reason dynamic
linking can't be used when debugging memory errors? Surely some apps
(especially proprietary ones) might be shipped as static binaries, but
these will likely lack debugging symbols anyway.

There are also fundamental limits to the correctness of any approach
that uses static linking, since too much information has already been
lost. It's calling the _name_ malloc, realloc, or free (not the code
at the location; think aliases etc.) that must have the allocation
semantics. Even if nothing weird is happening with aliases at the libc
implementation level, the compiler could do major transformations with
IPA (especially with LTO) that end up resulting in code being shared
in unexpected ways.

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.