Re: [RFC] building postgres with meson - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: [RFC] building postgres with meson
Date
Msg-id CA+hUKGKaB5UvE2rVk2adYNWKkahvX5AK+9CJ8x5_34kJXJ9+dw@mail.gmail.com
Whole thread Raw
In response to Re: [RFC] building postgres with meson  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [RFC] building postgres with meson
List pgsql-hackers
On Fri, Oct 15, 2021 at 12:04 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> [tgl@pro ~]$ cat checkenv.c
> #include <stdio.h>
> #include <stdlib.h>
>
> int
> main(int argc, char **argv)
> {
>   char *pth = getenv("DYLD_LIBRARY_PATH");
>
>   if (pth)
>     printf("DYLD_LIBRARY_PATH = %s\n", pth);
>   else
>     printf("DYLD_LIBRARY_PATH is unset\n");
>
>   return 0;
> }
> [tgl@pro ~]$ gcc checkenv.c
> [tgl@pro ~]$ ./a.out
> DYLD_LIBRARY_PATH is unset
> [tgl@pro ~]$ export DYLD_LIBRARY_PATH=/Users/tgl/pginstall/lib
> [tgl@pro ~]$ ./a.out
> DYLD_LIBRARY_PATH = /Users/tgl/pginstall/lib
> [tgl@pro ~]$ sh -c ./a.out
> DYLD_LIBRARY_PATH is unset
> [tgl@pro ~]$ ./a.out
> DYLD_LIBRARY_PATH = /Users/tgl/pginstall/lib
> [tgl@pro ~]$ bash -c ./a.out
> DYLD_LIBRARY_PATH is unset
>
> You have to check the environment using an "unprivileged" program.
> If you try to examine the environment using, say, "env", you will get
> very misleading results.  AFAICT, /usr/bin/env is *also* considered
> security-critical, because I cannot get it to ever report that
> DYLD_LIBRARY_PATH is set.
>
> Hmm ... /usr/bin/perl seems to act the same way.  It can see
> ENV{'PATH'} but not ENV{'DYLD_LIBRARY_PATH'}.
>
> This may indicate that they've applied this policy on a blanket
> basis to everything in /bin and /usr/bin (and other system
> directories, maybe), rather than singling out the shell.

Looks like it.  If I've found the right code here, it looks like where
any common-or-garden Unix runtime linker would ignore LD_LIBRARY_PATH
for a setuid binary, they've trained theirs to whack DYLD_*, and also
for code-signed and __RESTRICT-marked executables.

https://github.com/opensource-apple/dyld/blob/master/src/dyld.cpp#L1681

I suppose you could point SHELL at an unsigned copy of sh (codesign
--remove-signature, or something from brew/ports/x) so that GNU make
should respect, but I don't know how many other exec("/bin/sh") calls
might be hiding around the place (I guess perl calls system()?) and
might require some kind of LD_PRELOAD hackery... not much fun.



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: [RFC] building postgres with meson
Next
From: Greg Nancarrow
Date:
Subject: Re: Added schema level support for publication.