From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22755 invoked from network); 17 Aug 2022 21:31:41 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 17 Aug 2022 21:31:41 -0000 Received: (qmail 11493 invoked by uid 550); 17 Aug 2022 21:31:38 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 11457 invoked from network); 17 Aug 2022 21:31:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=2iI87aNoBMGyq0vToC6Kw5i54o5tijPApgKafyebWVs=; b=QVrzhFXQE30c1g2y/4l+n9DxbyshI5umoms39AXK65qkKR8glx4+/ZHVo4iN/GOFWb Yg4el4fbPiGnur57++4ymbjHie02V3aIvrvvlVadgdHuJ9zlE8qXN8ncDPlq4DdJq62k GeD3nI1f9aqbcl0WCrlLZbikcv/sg1AHBUtP93xwNX/r1pK2hGnxJwJ7T9gjRLn4mkJ4 wKn4xYAIwolfxejsox8R+4gGcmoPwhCAO5arDPypKhcy7tFGKloddqstFxultDMYussQ 7rzQaHWuCIH3qRLc6JjlQ2taYydtfi+VUz7v2s0V3E6D8c+fKjvKWmlLNpMR0nUe5/q6 FL+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=2iI87aNoBMGyq0vToC6Kw5i54o5tijPApgKafyebWVs=; b=PUEE+WE5UtnaPsvuifpryNTHqlmqYdWMtiTJxSdjYvty4krI8tRybVioDG1SJ4tYet z9z/81Spx8VYPkfB20jrkVRKJBf2feZgiQaSaVqFpvCKLgroRhUmfMVDt+g5nQs+ABif sqEHQJSgHMSmlnFVj37e8h8qOTcu/+G02vEGlBOiw2nualeZ1e/Wv92Xx4mzKW51iekI FAOapQT/7tOg2hCFCXWmC5LqVaaGrnNpLswqUZDyKAC1YTW5nFXlU1p1zsI2NGbAi5tZ 3w6PbfX+Bos+5MpbvK/5G5IFf5hAs5He6DMEHF6QS1BxtzxWc+PUXUoTU4TzQYQtGVHe XSCA== X-Gm-Message-State: ACgBeo3mmhwg2QqwoSnk2M0OcdGfV7OFEKXL53PpBXGrCadWsP2FvprQ oTFeR7vCq1+bKIvkDRKhhejoqATcOggDqMF5xSMNAQ== X-Google-Smtp-Source: AA6agR7mP1PI83TlQE7Z2yEuLJ2awwPZ8pUWK8QfpA4SqWG5hMpni0B+3J+Mje79z1OHjXgdxVFdHHtMi13Omu2Nuk4= X-Received: by 2002:a05:6902:114d:b0:66d:9fa6:4bd4 with SMTP id p13-20020a056902114d00b0066d9fa64bd4mr178377ybu.362.1660771885113; Wed, 17 Aug 2022 14:31:25 -0700 (PDT) MIME-Version: 1.0 References: <3818608.tdWV9SEqCh@vulcan.edgedb.net> <20220817192855.GD7074@brightrain.aerifal.cx> In-Reply-To: <20220817192855.GD7074@brightrain.aerifal.cx> From: James Y Knight Date: Wed, 17 Aug 2022 17:30:58 -0400 Message-ID: To: Rich Felker Cc: musl@lists.openwall.com, elvis@edgedb.com Content-Type: multipart/alternative; boundary="0000000000004469ad05e67696cc" Subject: Re: [musl] [PATCH] ldso/dynlink: Protect LD_ env vars from getting clobbered by apps --0000000000004469ad05e67696cc Content-Type: text/plain; charset="UTF-8" That issue was already fixed in 3.10. Currently, only PR_SET_MM_MAP and PR_SET_MM_MAP_SIZE operations require CRIU support enabled, the others do not. If anyone sufficiently motivated would like to propose a patch to the kernel to allow {ARG,ENV}_{START_END} operations by non-root users, that'd be pretty awesome. Then maybe in another couple decades, programs can stop using these awful hacks. On Wed, Aug 17, 2022 at 3:28 PM Rich Felker wrote: > On Wed, Aug 17, 2022 at 12:10:48PM -0400, James Y Knight wrote: > > 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) > > Yes, unfortunately (at least last I checked) it's also only available > if CRIU support was enabled in the kernel since that's the only thing > its creators envisioned it being used for... *sigh* > > > > > On Wed, Aug 17, 2022 at 6:05 AM Elvis Pranskevichus > > 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 */ > > > > > > > > > > > > > > > > --0000000000004469ad05e67696cc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
That issue was already fixed in 3.10. Currently, only PR_S= ET_MM_MAP and PR_SET_MM_MAP_SIZE operations require CRIU support enabled, t= he others do not.=C2=A0

If anyone sufficiently motivated= would like to propose a patch to the kernel to allow {ARG,ENV}_{START_END}= operations by non-root users, that'd be pretty awesome. Then maybe in = another=C2=A0couple decades, programs can stop using these awful hacks.

On Wed, Aug 17, 2022 at 3:28 PM Rich Felker <dalias@libc.org> wrote:
On Wed, Aug 17, 2022 at 12:10:48PM -0400, James Y = Knight wrote:
> 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 _EN= D),
> 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/87305b0fbfc0e40a948c= f0a683bcf9d47b8a41a3/src/basic/process-util.c#L256
> for an example of use (including ugly workaround for the API being sil= ly
> and setting START/END with separate syscalls, but requiring START <= =3D END at
> all times)

Yes, unfortunately (at least last I checked) it's also only available if CRIU support was enabled in the kernel since that's the only thing its creators envisioned it being used for... *sigh*

>
> 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 inta= ct.
> > For example, PostgreSQL clobbers argv/environ area to implement i= ts
> > "setproctitle" emulation on non-BSD [1], and there is a= popular Python
> > library inspired by it [2].=C2=A0 As a result, setting `LD_LIBRAR= Y_PATH`
> > or `LD_PRELOAD` has no effect on Postgres subprocesses when linki= ng
> > 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)
> >
> > ---
> >=C2=A0 ldso/dynlink.c | 4 ++--
> >=C2=A0 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)
> >
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Only trust user/env if kernel= says we're not suid/sgid */
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!libc.secure) {
> > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0env_path = =3D getenv("LD_LIBRARY_PATH");
> > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0env_prelo= ad =3D getenv("LD_PRELOAD");
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0env_path = =3D strdup(getenv("LD_LIBRARY_PATH"));
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0env_prelo= ad =3D strdup(getenv("LD_PRELOAD"));
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> >
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Activate error handler functi= on */
> >
> >
> >
> >
> >
--0000000000004469ad05e67696cc--