From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4731 Path: news.gmane.org!not-for-mail From: u-igbb@aetey.se Newsgroups: gmane.linux.lib.musl.general Subject: PATCH (Re: [musl] be able to break inheritance of LD_LIBRARY_PATH) Date: Fri, 28 Mar 2014 16:02:08 +0000 Message-ID: <20140328160208.GD8221@example.net> References: <20140328104208.GZ8221@example.net> <20140328131718.GH27448@port70.net> <20140328140036.GC8221@example.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="6sX45UoQRIJXqkqR" X-Trace: ger.gmane.org 1396022549 23189 80.91.229.3 (28 Mar 2014 16:02:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Mar 2014 16:02:29 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4735-gllmg-musl=m.gmane.org@lists.openwall.com Fri Mar 28 17:02:39 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WTZEo-0004bs-QH for gllmg-musl@plane.gmane.org; Fri, 28 Mar 2014 17:02:34 +0100 Original-Received: (qmail 2019 invoked by uid 550); 28 Mar 2014 16:02:34 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 2011 invoked from network); 28 Mar 2014 16:02:34 -0000 X-T2-Spam-Status: No, hits=0.0 required=5.0 Received-SPF: none receiver=mailfe02.swip.net; client-ip=192.99.8.96; envelope-from=u-igbb@aetey.se Content-Disposition: inline In-Reply-To: <20140328140036.GC8221@example.net> User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:4731 Archived-At: --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Mar 28, 2014 at 02:00:36PM +0000, u-igbb@aetey.se wrote: > By the way, when you say this - LD_PRELOAD should be actually usable > in a non-inheritable way too. It brings otherwise the same problems > as LD_LIBRARY_PATH. It could deserve its own loader argument I guess, > like --preload. > > > (there ar no "different versions of the loader" in musl) > > Yes this is why I thought that a LD_LIBRARY_PATH removal would > be enough. Of course it is much better to do this properly, by > extending the behaviour of the loader when it is being used standalone. > > This would cost just a few bytes I guess. I will look into proposing a patch. Attaching the patch. It seems to work, under some primitive testing. Could this or similar be considered for applying upstream? Regards, Rune --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="add--library-path.patch" --- src/ldso/dynlink.c.ori 2014-03-28 10:37:34.821317811 +0100 +++ src/ldso/dynlink.c 2014-03-28 16:45:26.435994022 +0100 @@ -1041,12 +1041,34 @@ size_t l = strlen(ldname); if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1; *argv++ = (void *)-1; - if (argv[0] && !strcmp(argv[0], "--")) *argv++ = (void *)-1; + while (argv[0] && argv[0][0] == '-') { + if (argv[0][1] == '-' && argv[0][2] == 0) { /* "--" */ + *argv++ = (void *)-1; + break; + } + /* care about someone making the dynamic loader + * itself (!) setuid? (s)he has possibly good + * reasons, who am I to interfere -- thus + * no setuid checking here -- rl */ + if (!strcmp(argv[0], "--library-path")) { + *argv++ = (void *)-1; + env_path = argv[0]; /* even if NULL */ + } else if (!strcmp(argv[0], "--preload")) { + *argv++ = (void *)-1; + env_preload = argv[0]; /* even if NULL */ + } else + /* any - stops parsing */ + break; + if (!argv[0]) + /* missing argument? */ + break; + *argv++ = (void *)-1; + } if (!argv[0]) { dprintf(2, "musl libc\n" "Version %s\n" "Dynamic Program Loader\n" - "Usage: %s [--] pathname%s\n", + "Usage: %s [--library-path path] [--preload path] [--] pathname%s\n", __libc_get_version(), ldname, ldd_mode ? "" : " [args]"); _exit(1); --6sX45UoQRIJXqkqR--