mailing list of musl libc
 help / color / mirror / code / Atom feed
From: d.dorau@avm.de
To: "Rich Felker" <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re[2]: Issue with musl and valgrind
Date: Mon, 6 Jan 2020 17:24:35 +0100	[thread overview]
Message-ID: <OF8AD17947.D5D5D702-ONC12584E7.00597957-C12584E7.005A245E@avm.de> (raw)
In-Reply-To: <20200106135623.GO30412@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 2550 bytes --]

"Rich Felker" <dalias@aerifal.cx> schrieb am 06.01.2020 14:56:23:
[...]
> 
> This is really a bug in valgrind, that it's relying on a mix of the
> dynamic linker and its own mechanism for interposing malloc. Either
> the interposition should not take place until after line 1913 of
> __dls3 in dynlink.c (this is what would happen if you did it via
> LD_PRELOAD without valgrind), or valgrind should do its own loading
> and relocation of vgpreload_memcheck-*.so independent of the tracee's
> dynamic linker.
> 
> On most archs, the problem does not manifest as things are setup so
> that it's safe to call free in an unrelocated context. However
> realloc is gratuitously not safe and Adélie Linux has a patch for it
> to do it like free:
> 
> 
https://code.foxkit.us/adelie/packages/blob/master/user/valgrind/realloc.patch

> 
> But on MIPS, where there are no PC-relative references and everything
> goes through the GOT, this blows up.
> 
> I'm not sure how practical it is to get valgrind to fix this upstream.
> In the either/or above, if the first course of action is taken, the
> mechanism should probably be by inserting a breakpoint (or valgrind's
> equivalent) at the main program's e_entry address and not doing the
> replacement hack until then. Alternatively, it could just rely on
> LD_PRELOAD working without trying to do additional tricks, but maybe
> they have a good reason they're not doing that.
> 
> Rich

I was not aware of this when debugging the crash, but after looking at 
additional
debug statements and valgrind code my current understanding is that 
valgrind
actually inserts

LD_PRELOAD="
/usr/lib/valgrind/vgpreload_core-mips32-linux.so:/usr/lib/valgrind/vgpreload_memcheck-mips32-linux.so"

into the environment before loading the executable to test.
(coregrind/m_initimg/initimg-linux.c:123)

425:11:32:696 --4757:1:    main Split up command line
425:11:32:696 --4757:1:    main (early_) Process Valgrind's command line 
options
425:11:32:696 --4757:1:    main Create initial image
425:11:32:712 --4757:1: initimg Loading client
425:11:32:712 --4757:1: initimg Setup client env
425:11:32:712 --4757:2: initimg   preload_string:
425:11:32:728 --4757:2: initimg 
"/usr/lib/valgrind/vgpreload_core-mips32-linux.so:/usr/lib/valgrind/vgpreload_memcheck-mips32-linux.so"
425:11:32:728 --4757:1: initimg Setup client stack: size will be 1048576


Is my understanding correct that you would expect it to not run into
the crash I described earlier then?


Daniel

[-- Attachment #2: Type: text/html, Size: 3606 bytes --]

  reply	other threads:[~2020-01-06 16:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-06 11:01 d.dorau
2020-01-06 13:56 ` Rich Felker
2020-01-06 16:24   ` d.dorau [this message]
2020-01-06 16:32     ` 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=OF8AD17947.D5D5D702-ONC12584E7.00597957-C12584E7.005A245E@avm.de \
    --to=d.dorau@avm.de \
    --cc=dalias@libc.org \
    --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).