public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Jonathon Anderson <janderson@rice.edu>
To: Matthew Parkinson <mattpark@microsoft.com>,
	"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Subject: Re: RTLD_DEEPBIND interaction with LD_PRELOAD
Date: Fri, 31 Mar 2023 09:52:39 -0500	[thread overview]
Message-ID: <0eb8cc4762942f5cf42ea11c3253280564204d96.camel@rice.edu> (raw)
In-Reply-To: <PR3PR83MB0474EC00EB327AB21C665D5DC5879@PR3PR83MB0474.EURPRD83.prod.outlook.com>

Hello all,

Wrapping symbols is of interest to us (the HPCToolkit folks), so I thought I would jump in here and bring up a 3rd option that we are excited about: LD_AUDIT-powered symbol injection.

We currently use LD_PRELOAD + dlsym(RTLD_NEXT) to wrap critical symbols, however we have also encountered unavoidable limitations with the approach for some applications in the wild. We haven't run into RTLD_DEEPBIND before, but we have found many other issues:
 - dlsym(): If the symbol is fetched directly with dlsym() LD_PRELOAD does not apply. (And yes, there is code out there that does `dlsym(dlopen(libc.so.6))`. :/)
 - dlopen(RTLD_LOCAL): dlsym(RTLD_NEXT) fails if the "victim" symbol is only loaded as the dependency of a library loaded with dlopen(RTLD_LOCAL).
 - dlmopen() namespaces: LD_PRELOAD only applies to the main namespace, symbols in private dlmopen() namespaces are unaffected.

The alternative we are considering uses LD_AUDIT's la_symbind hook to inject our wrappers. This hook fires *every* time a symbol gets bound or on dlsym(), avoiding the narrow application issues with LD_PRELOAD. The hook also receives the to-be-bound target as an argument, avoiding the issues with dlsym(RTLD_NEXT). The high power of this approach makes it a very appealing alternative to LD_PRELOAD.

We have not yet tried LD_AUDIT-powered symbol injection in the wild, but I did write [a small test matrix with some possible wrapper implementations][1] for preliminary research. So far, the basic LD_AUDIT-powered implementations are very promising and avoid the issues we see with LD_PRELOAD.

[1]: https://gitlab.com/blue42u/ldaudit-power-tests/-/tree/main/symbol-wrapping

-Jonathon

      reply	other threads:[~2023-03-31 14:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 11:06 Matthew Parkinson
2023-03-31 14:52 ` Jonathon Anderson [this message]

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=0eb8cc4762942f5cf42ea11c3253280564204d96.camel@rice.edu \
    --to=janderson@rice.edu \
    --cc=libc-alpha@sourceware.org \
    --cc=mattpark@microsoft.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.
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).