From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13716 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alexey Izbyshev Newsgroups: gmane.linux.lib.musl.general Subject: Re: dlsym(handle) may search in unrelated libraries Date: Wed, 6 Feb 2019 20:02:28 +0300 Message-ID: References: <20190206160248.GB5469@voyager> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="253149"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 To: Markus Wichmann , musl@lists.openwall.com Original-X-From: musl-return-13732-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 06 18:02:14 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 1grQaU-0013fO-CQ for gllmg-musl@m.gmane.org; Wed, 06 Feb 2019 18:02:14 +0100 Original-Received: (qmail 5682 invoked by uid 550); 6 Feb 2019 17:02:12 -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 5661 invoked from network); 6 Feb 2019 17:02:11 -0000 In-Reply-To: <20190206160248.GB5469@voyager> Content-Language: en-US Xref: news.gmane.org gmane.linux.lib.musl.general:13716 Archived-At: On 2/6/19 7:02 PM, Markus Wichmann wrote: > > Thankfully the patch is simple: Explicitly make ldso and vdso have no > deps. I was tempted to put this into kernel_mapped_dso(), but then I > remembered that the app is also a kernel mapped dso, and it usually does > have deps that need processing. At least, in nontrivial cases. > > The attached patch should tide you over. > Thank you for the quick response and the patch, Markus! Your patch fixes the exact test case I posted. 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: $ cat bar.c int bar = 42; $ musl-gcc -fPIC -shared bar.c -o libbar.so $ cat foo.c extern int bar; int *foo = &bar; $ cat baz.c extern int bazdep; int *baz = &bazdep; $ cat bazdep.c int bazdep = 1; $ cat main.c #include #include int main(void) { if (!dlopen("libbaz.so", RTLD_NOW|RTLD_LOCAL)) return 1; if (!dlopen("libfoo.so", RTLD_NOW|RTLD_LOCAL)) return 1; void *h = dlopen("libbazdep.so", RTLD_NOW|RTLD_LOCAL); printf("%p\n", dlsym(h, "bar")); } $ musl-gcc main.c -Wl,-rpath='$ORIGIN' -ldl $ ./a.out 0x7f66ed371020 Here, "libbazdep.so" assumes the role of "libc.so" from the previous test: it's a library with dso->deps == NULL that is loaded before "libfoo.so". So, when "libbazdep.so" is dlopen'd, musl considers it to be a "first load" and erroneously includes "libbar.so" to the list of dependencies of "libbazdep.so". Alexey