This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: fortification and valgrind/memcheck (Was: [PATCH BZ#20422] Do not allow asan/msan/tsan and fortify@the same time)
On Wed, 2016-10-05 at 13:49 +0200, Florian Weimer wrote:
> On 10/04/2016 02:15 PM, Mark Wielaard wrote:
> > My proposal was to extend __chk_fail (or introduce a new __chk_fail_addr
> > function) that provides the address that would have been accessed. Then
> > valgrind just intercepts __chk_fail and uses that address to provide
> > some additional information.
>
> There many different reasons why __chk_fail might be called. For
> example, you get a fortify failure if you call snprintf with a buffer
> size that is larger than what is inferred by the compiler. This happens
> even if the actual written value fits within the shorter space. So you
> have a fortify failure without any invalid memory accesses.
Right. And this is where I think valgrind can augment the fortification
check if given the address. You don't want to rely on valgrind/memcheck
noticing an invalid access, because in such cases it might not actually
be. You would call __chk_fail_addr (s + slen) and valgrind can tell you
where the block associated with that pointer came from (backtrace),
whether it was recently freed, how far inside/beyond an existing block
it is, etc.
Cheers,
Mark