mailing list of musl libc
 help / color / mirror / code / Atom feed
* be able to break inheritance of LD_LIBRARY_PATH
@ 2014-03-28 10:42 u-igbb
  2014-03-28 12:18 ` orc
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: u-igbb @ 2014-03-28 10:42 UTC (permalink / raw)
  To: musl

Hello,

I was aware of musl for some time and now consider deploying it as
a default library for new software builds, due to its very appealing
virtues.

Yet there is a small but important issue.

For our software setup it is crucial (quite useful otherwise in general)
to be able to specify the location of the dynamic libraries per binary/run
_without_ the unconditional inheritance imposed by LD_LIBRARY_PATH.

A very nice solution would be the ability to explicitely run a standalone
dynamic loader, as implemented in both glibc and uclibc. We are heavily
relying on this functionality.

I do not know how hard it would be to teach the musl loader
to be runnable standalone and which corner cases this might create.

As a simpler approach I might suggest simply being able to drop
LD_LIBRARY_PATH as soon as it has been read. An extra environment
variable as a flag would do.

Compared to a standalone loader this lacks the ability to run
a binary with a different version of the loader/musl but at least
makes it straightforward and safe to freely specify where to find other
libraries.

A naïve implementation might look as follows:

--- src/ldso/dynlink.c.ori      2014-03-28 10:37:34.821317811 +0100
+++ src/ldso/dynlink.c  2014-03-28 11:21:16.828047766 +0100
@@ -962,6 +962,7 @@
        size_t vdso_base;
        size_t *auxv;
        char **envp = argv+argc+1;
+       int forget_ld_library_path = 0;
 
        /* Find aux vector just past environ[] */
        for (i=argc+1; argv[i]; i++)
@@ -969,8 +970,19 @@
                        env_path = argv[i]+16;
                else if (!memcmp(argv[i], "LD_PRELOAD=", 11))
                        env_preload = argv[i]+11;
+               else if (!memcmp(argv[i], "FORGET_LD_LIBRARY_PATH=", 23))
+                       forget_ld_library_path = 1;
        auxv = (void *)(argv+i+1);
 
+       /* one _may_ wish to break the inheritance of LD_LIBRARY_PATH,
+        * the hack below only works if the corresponding memory is writable
+        * -- rl */
+       if (forget_ld_library_path)
+               for (i=argc+1; argv[i]; i++)
+                       if (!memcmp(argv[i], "LD_LIBRARY_PATH=", 16) ||
+                           !memcmp(argv[i], "FORGET_LD_LIBRARY_PATH=", 23))
+                               argv[i][0] = 'X';
+
        decode_vec(auxv, aux, AUX_CNT);
 
        /* Only trust user/env if kernel says we're not suid/sgid */


What do you think about this? Can this or something better be done?
I would love to be able to go with musl.

Regards,
Rune



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-03-29  7:25 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-28 10:42 be able to break inheritance of LD_LIBRARY_PATH u-igbb
2014-03-28 12:18 ` orc
2014-03-28 12:52   ` u-igbb
2014-03-28 12:27 ` Alexander Monakov
2014-03-28 13:04   ` u-igbb
2014-03-28 13:17 ` Szabolcs Nagy
2014-03-28 14:00   ` u-igbb
2014-03-28 15:25     ` Szabolcs Nagy
2014-03-28 15:34       ` Alexander Monakov
2014-03-28 16:02     ` PATCH (Re: [musl] be able to break inheritance of LD_LIBRARY_PATH) u-igbb
2014-03-28 16:34 ` be able to break inheritance of LD_LIBRARY_PATH Daniel Cegiełka
2014-03-28 17:50   ` u-igbb
2014-03-28 18:03     ` Daniel Cegiełka
2014-03-28 18:21       ` u-igbb
2014-03-28 19:46 ` Rich Felker
2014-03-28 21:07   ` u-igbb
2014-03-28 21:48     ` Rich Felker
2014-03-29  7:25       ` u-igbb

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).