mailing list of musl libc
 help / color / mirror / code / Atom feed
From: James Y Knight <jyknight@google.com>
To: musl@lists.openwall.com
Cc: elvis@edgedb.com
Subject: Re: [musl] [PATCH] ldso/dynlink: Protect LD_ env vars from getting clobbered by apps
Date: Wed, 17 Aug 2022 12:10:48 -0400	[thread overview]
Message-ID: <CAA2zVHrrjf4dPhOi10MyNV_0QPLe-HGFaw=aYj1czxpU=v85yg@mail.gmail.com> (raw)
In-Reply-To: <3818608.tdWV9SEqCh@vulcan.edgedb.net>

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

Sidenote: Linux does support a less awful way to change the kernel's view
of argv these days, using prctl(PR_SET_MM, PR_SET_MM_ARG_START (or _END),
addr, 0, 0). Sadly, it only allows root (CAP_SYS_RESOURCE) to use it. I'm
not sure why, perhaps that restriction could be relaxed for future
kernels...

See
https://github.com/systemd/systemd/blob/87305b0fbfc0e40a948cf0a683bcf9d47b8a41a3/src/basic/process-util.c#L256
for an example of use (including ugly workaround for the API being silly
and setting START/END with separate syscalls, but requiring START <= END at
all times)

On Wed, Aug 17, 2022 at 6:05 AM Elvis Pranskevichus <elvis@edgedb.com>
wrote:

> 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 */
>
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 2551 bytes --]

  parent reply	other threads:[~2022-08-17 16:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17  5:45 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 [this message]
2022-08-17 19:28   ` Rich Felker
2022-08-17 21:30     ` James Y Knight

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='CAA2zVHrrjf4dPhOi10MyNV_0QPLe-HGFaw=aYj1czxpU=v85yg@mail.gmail.com' \
    --to=jyknight@google.com \
    --cc=elvis@edgedb.com \
    --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).