public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "adhemerval.zanella at linaro dot org" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug dynamic-link/30186] RTLD_DEEPBIND interacts badly with LD_PRELOAD Date: Fri, 10 Mar 2023 19:20:49 +0000 [thread overview] Message-ID: <bug-30186-131-AwQvc2LW7A@http.sourceware.org/bugzilla/> (raw) In-Reply-To: <bug-30186-131@http.sourceware.org/bugzilla/> https://sourceware.org/bugzilla/show_bug.cgi?id=30186 --- Comment #3 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> --- (In reply to Matthew Parkinson from comment #2) > So based on a suggestion from a colleague Paul Lietar, we have an > alternative suggestion that is less invasive. > > Previously, the malloc hooks provided a layer of indirection which has now > been removed. We wonder if you could reintroduce the layer of indirection > but only accessible to the loader. > > If you make > > extern void* malloc(size_t s) > { > return __libc_malloc(s); > } > > Now, if you prevent inlining of __libc_malloc, then you can expose > __libc_malloc as something that can be overridden by LD_PRELOAD. As an > RTLD_DEEPBINDed library would call malloc, this would immediately jump to > what ever symbol exists for __libc_malloc, when libc was loaded, and this > would account for LD_PRELOAD. > > I have an example that suggests this could work: > > https://github.com/mjp41/deepbindexample/tree/main/solution This essentially adds another PLT indirection on *all* memory allocations, even for default binaries that do no dlopen or do not use RTLD_DEEPBIND. I don't think this is a good tradeoff. > > Many allocators already provide symbols for __libc_malloc, e.g.: > https://github.com/microsoft/mimalloc/blob/ > dd7348066fe40e8bf372fa4e9538910a5e24a75f/src/alloc-override.c#L273-L285 > > https://github.com/jemalloc/jemalloc/blob/ > 09e4b38fb1f9a9b505e35ac13b8f99282990bc2c/src/jemalloc.c#L3143-L3175 > > So these would just start working with RTLD_DEEPBIND. __libc_malloc is a strong alias to malloc, so there is no need to override for shared libraries. Jemalloc states it is required to enable static linking, which I am not sure it is true any longer (as long the malloc implementation implements all requires functions). > > The obvious question is how much performance would be lost in adding the > indirection. It would not affect existing allocator overrides as they could > override both, but for programs using the libc allocator, there would be a > cost. I don't think the performance overhead is acceptable, and I am almost sure other maintainers will frown upon it as well. I really think a tunable or an extra option on LD_PRELOAD would be better to instruct that RTLD_DEEPBIND should always consider LD_PRELOADS libraries on namespace resolution. It has the advantage of being backportable (where a new symbol indirection would require another set of symbols). > > I am sure there are many complexities that I am missing, but I thought this > is worth mentioning. -- You are receiving this mail because: You are on the CC list for the bug.
next prev parent reply other threads:[~2023-03-10 19:20 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-03-01 11:33 [Bug dynamic-link/30186] New: " parky at outlook dot com 2023-03-01 11:33 ` [Bug dynamic-link/30186] " parky at outlook dot com 2023-03-06 16:17 ` adhemerval.zanella at linaro dot org 2023-03-06 16:54 ` siddhesh at sourceware dot org 2023-03-08 20:41 ` parky at outlook dot com 2023-03-10 19:20 ` adhemerval.zanella at linaro dot org [this message] 2023-03-11 11:15 ` parky at outlook dot com 2023-03-13 11:52 ` parky at outlook dot com 2023-03-22 10:52 ` parky at outlook dot com 2023-03-22 11:39 ` adhemerval.zanella at linaro dot org 2023-03-22 11:48 ` parky at outlook dot com 2023-03-22 11:57 ` adhemerval.zanella at linaro dot org 2023-03-22 15:45 ` siddhesh at sourceware dot org 2023-03-22 16:25 ` adhemerval.zanella at linaro dot org 2023-03-22 16:25 ` adhemerval.zanella at linaro dot org 2023-03-22 16:57 ` siddhesh at sourceware dot org
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=bug-30186-131-AwQvc2LW7A@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).