mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Cc: Alexey Izbyshev <izbyshev@ispras.ru>
Subject: Re: dlsym(handle) may search in unrelated libraries
Date: Wed, 6 Feb 2019 21:25:18 +0100	[thread overview]
Message-ID: <20190206202518.GC5469@voyager> (raw)
In-Reply-To: <a2f119d3-d359-ee02-db46-66299c1c3536@ispras.ru>

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

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

[-- Attachment #2: 0007-Initialize-deps-on-non-directly-loaded-libs.patch --]
[-- Type: text/x-diff, Size: 964 bytes --]

From 841dd4e075040e2aeb01adea8ef5e2f7c0fc006a Mon Sep 17 00:00:00 2001
From: Markus Wichmann <nullplan@gmx.net>
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


  reply	other threads:[~2019-02-06 20:25 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-05 21:02 Alexey Izbyshev
2019-02-06 13:40 ` Alexey Izbyshev
2019-02-06 16:02 ` Markus Wichmann
2019-02-06 17:02   ` Alexey Izbyshev
2019-02-06 20:25     ` Markus Wichmann [this message]
2019-02-06 21:23       ` Alexey Izbyshev
2019-02-07  5:33         ` Markus Wichmann
2019-02-07 13:42           ` Alexey Izbyshev
2019-02-07 17:43             ` Markus Wichmann
2019-02-07 20:37               ` Markus Wichmann
2019-02-07 21:29               ` Rich Felker
2019-02-07 16:54           ` Rich Felker
2019-02-07 18:36             ` Markus Wichmann
2019-02-07 18:57               ` Rich Felker
2019-02-07 20:31                 ` Markus Wichmann
2019-02-07 21:33                   ` Rich Felker
2019-02-07 21:37                     ` Rich Felker
2019-02-08 10:19             ` A. Wilcox
2019-02-08 12:00               ` Szabolcs Nagy
2019-02-08 16:09                 ` Rich Felker
2019-02-09 22:53 Alexey Izbyshev
2019-02-10  1:03 ` Rich Felker
2019-02-26 15:07   ` Rich Felker
2019-03-04  2:11     ` 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=20190206202518.GC5469@voyager \
    --to=nullplan@gmx.net \
    --cc=izbyshev@ispras.ru \
    --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).