From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13717 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Markus Wichmann Newsgroups: gmane.linux.lib.musl.general Subject: Re: dlsym(handle) may search in unrelated libraries Date: Wed, 6 Feb 2019 21:25:18 +0100 Message-ID: <20190206202518.GC5469@voyager> References: <20190206160248.GB5469@voyager> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="4ZLFUWh1odzi/v6L" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="227751"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: Alexey Izbyshev To: musl@lists.openwall.com Original-X-From: musl-return-13733-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 06 21:26:36 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1grTmG-000x6b-JI for gllmg-musl@m.gmane.org; Wed, 06 Feb 2019 21:26:36 +0100 Original-Received: (qmail 11716 invoked by uid 550); 6 Feb 2019 20:26:34 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 11695 invoked from network); 6 Feb 2019 20:26:33 -0000 Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:ln0xcJ9AJkLcp4elG4URGjBC+IeiF+2Swl0izl5bE1Oh3vi3Btg xpXgq68FumvDNjyHNYtjMP3f9YFw2E7feou7fdfKnS3ImGZbSEOQFX1kSPO79NoL0wxEZlL EG4KF2tODNKGMko/MBk8bxNhZnrt+ZipbVJatTPHjfSolUjzhRYpoWOA7/SU/InlaxKj81m 5PkOHtUAXibA/qaDsWzlw== X-UI-Out-Filterresults: notjunk:1;V03:K0:eWF7RR+ozsk=:ILjTzgTmww0S4FRrDs3L43 mBUEeSGa6f9ggMpyR9+11tbbi5Gfdx/YB2xnZzjSXHjkADd31wkQDWSrPyFEHu8L9X1/UhQR5 kXrbNr23AwXHZMarwAsV3soYYh4OSjgLf2ynLCHRsCFRbdDNV70rfs8jKS3JjOdSgxeVWNLfi PeOqZ9ufC9P+7YnqBgN3O4MB8o3VPl2+zYCjfhtlfRTtabeNcJP0XbZAhvrbBxBEU/GfR3/QS 89iqjRLP5MNvTkGAytjDzkfF62qblMv0Jpe+OrCLmaeXBmsU1BnCj/Sh8CWeN8epJA1KI2d7U X48ANxoHfgA+uUlSWTzJWXs0W01XFiwcZDUMddd/LkroOsT1fKotZ9i3Ylx6LHO+ZWgvJOGyB thnLP8lSTGpZGMJ181QQrs9Qv3leBGvJk08I6eEOvgy0mLe7G35yexzVrv9rFHhZcQjRmvnM6 4xqB0VCNX8vFFl5ehdcUHtb745y9NjynFSRwiKS4Pj0xdMnMs3pajgZ1A8+G9gagToRi4W101 yMWnCFF6Jw7mD+G6jlXJiZK9qPG9z7IJFM4s9J4C562l1jm9mQKnDZ8bRvnmxSWnKRZoHmOZG /8E1VQaRb5hBCOruDUiTg4wZSmb4Uawid8X3b85WM894ExsqvQnA5RFKhl5JbA9y6kTsHVDAI TQYkXoL/nQezSXwn8PmvRZ0YoVNkf1NCQFtWM39ZvHBYxILL7+zMMyUQy5IghSSWh+LXnw9p9 VzNGNcl5r9ttuaGESF+eBRpLLGOF3ssSWK7AZvFZuQMmQbd4SY2XnUtzv1oC5SWdzcZT3sAL Xref: news.gmane.org gmane.linux.lib.musl.general:13717 Archived-At: --4ZLFUWh1odzi/v6L Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Feb 06, 2019 at 08:02:28PM +0300, Alexey Izbyshev wrote: > Unfortunately, my test case was a simplified example of a general problem: > dso->deps is assigned only for the main app and for libraries opened with > dlopen(), but not for their dependencies. Consider the following: Right you are. It took me a while to understand what the deps array was even for (since musl's dlclose() doesn't do anything, tracking dependencies is mostly pointless), but I found it is needed for lazy relocation processing. So it is necessary for all libs opened by dlopen() directly to contain a list of all their dependencies. All the other libs can have an empty list. So I propose the attached patch in addition to the previous one. This will set dso->deps to the empty list in all libs not directly loaded from dlopen(). The previous patch is still necessary, as nothing ever calls load_deps() on the libc or the vdso, but all other modules get a load_deps() treatment. > > Alexey > > Ciao, Markus --4ZLFUWh1odzi/v6L Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0007-Initialize-deps-on-non-directly-loaded-libs.patch" >From 841dd4e075040e2aeb01adea8ef5e2f7c0fc006a Mon Sep 17 00:00:00 2001 From: Markus Wichmann Date: Wed, 6 Feb 2019 21:13:05 +0100 Subject: [PATCH 7/7] Initialize deps on non-directly loaded libs. As pointed out by Alexey Izbyshev, having the deps member be zero opens dlopen() and dlsym() up to malfunctions, if a library was previously loaded as dependency and is then dlopen()ed. Therefore, we now set the deps member of the dso descriptor to the sentry value in all libs loaded as dependencies. --- ldso/dynlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 6ffeca85..f8346c54 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -1158,8 +1158,8 @@ static void load_deps(struct dso *p) *deps = tmp; } } + if (!p->deps) p->deps = (struct dso**)&nodeps_dummy; } - if (!*deps) *deps = (struct dso **)&nodeps_dummy; } static void load_preload(char *s) -- 2.20.1 --4ZLFUWh1odzi/v6L--