|
Message-ID: <4834483.e9J7NaK4W3@vulcan.edgedb.net> Date: Tue, 16 Aug 2022 23:23:02 -0700 From: Elvis Pranskevichus <elvis@...edb.com> To: musl@...ts.openwall.com Cc: elvis@...edb.com Subject: [RESEND PATCH] ldso/dynlink: Protect LD_ env vars from getting clobbered by apps (sorry, the previous patch is obviously wrong, this is a better version) 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. --- ldso/dynlink.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index cc677952..2b816ce0 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -1757,7 +1757,23 @@ 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"); + if (env_path != NULL) { + /* Prevent value from getting clobbered by the application */ + env_path = strdup(env_path); + if (!env_path) { + dprintf(2, "%s: out of memory\n", argv[0]); + _exit(127); + } + } env_preload = getenv("LD_PRELOAD"); + if (env_preload != NULL) { + /* Prevent value from getting clobbered by the application */ + env_preload = strdup(env_preload); + if (!env_preload) { + dprintf(2, "%s: out of memory\n", argv[0]); + _exit(127); + } + } } /* Activate error handler function */ -- 2.35.1
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.