mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] ldso/dynlink: Protect LD_ env vars from getting clobbered by apps
@ 2022-08-17  5:45 Elvis Pranskevichus
  2022-08-17  6:23 ` [musl] [RESEND PATCH] " Elvis Pranskevichus
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Elvis Pranskevichus @ 2022-08-17  5:45 UTC (permalink / raw)
  To: musl; +Cc: elvis

There is no guarantee that the environment block will remain intact.
For example, PostgreSQL clobbers argv/environ area to implement its
"setproctitle" emulation on non-BSD [1], and there is a popular Python
library inspired by it [2].  As a result, setting `LD_LIBRARY_PATH`
or `LD_PRELOAD` has no effect on Postgres subprocesses when linking
against musl.

Protect against this by making a copies instead of storing the
original pointers directly.

(please CC me, I'm not subscribed to the list)

---
 ldso/dynlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index cc677952..703342b8 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1756,8 +1756,8 @@ void __dls3(size_t *sp, size_t *auxv)

 	/* Only trust user/env if kernel says we're not suid/sgid */
 	if (!libc.secure) {
-		env_path = getenv("LD_LIBRARY_PATH");
-		env_preload = getenv("LD_PRELOAD");
+		env_path = strdup(getenv("LD_LIBRARY_PATH"));
+		env_preload = strdup(getenv("LD_PRELOAD"));
 	}

 	/* Activate error handler function */





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

end of thread, other threads:[~2022-08-17 21:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-17  5:45 [musl] [PATCH] ldso/dynlink: Protect LD_ env vars from getting clobbered by apps Elvis Pranskevichus
2022-08-17  6:23 ` [musl] [RESEND PATCH] " Elvis Pranskevichus
2022-08-17 15:29 ` [musl] [PATCH] " Rich Felker
2022-08-17 16:26   ` Elvis Pranskevichus
2022-08-17 16:10 ` James Y Knight
2022-08-17 19:28   ` Rich Felker
2022-08-17 21:30     ` James Y Knight

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