All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: yocto-patches@lists.yoctoproject.org
Cc: seebs@seebs.net, mark.hatle@kernel.crashing.org
Subject: Re: [yocto-patches] [pseudo] [PATCH 6/7] exec*: Replace bash workaround to avoid memory corruption
Date: Thu, 02 Jul 2026 07:23:44 +0100	[thread overview]
Message-ID: <7a87ea66f1db2762737f424921a38eb6ce026dfe.camel@linuxfoundation.org> (raw)
In-Reply-To: <DJNUP3YO8KUG.39DIX5U7FDR6H@gmail.com>

Hi Gaël,

On Thu, 2026-07-02 at 07:54 +0200, Gaël PORTAY via lists.yoctoproject.org wrote:
> On Wed Jul 1, 2026 at 3:13 PM CEST, Richard Purdie via lists.yoctoproject.org wrote:
> > Bash intercepts getenv/setenv/unsetenv and does magic with it internally.
> > 
> > The data pointed to by environ may not be allocated by glibc but by bash
> > and the glibc env functions have their own memory handling outside of malloc.
> > Unfortuantely bash doesn't keep environ and the result of setenv/getenv/unsetenv
> > in sync either. This means the current workaround badly corrupts memory and it
> > is just luck we're not breaking more often than the occasional opkg-build segfaults
> > we've been seeing.
> > 
> > Fixing this is tricky, the best we can probably do is to read through environ and
> > create our own copy of the it, modifying it how we need to keep the pseudo variables
> > correct.
> > 
> > We do already have a function which can copyn and modify the environment, we can
> 
> s,copyn,copy,

I'll tweak, thanks.

> > therefore swap some setupenv calls for setupenvp and switch out environ around
> > the exec calls.
> > 
> > Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> > ---
> >  ports/common/guts/execv.c  | 19 ++++++++++++++-----
> >  ports/common/guts/execvp.c | 15 ++++++++++++---
> >  ports/unix/guts/popen.c    | 16 +++++++++++++---
> >  ports/unix/guts/system.c   | 16 +++++++++++++---
> 
> Don't you need to make these changes to execve(), and posix_spawn{,p}()?
> i.e. in files:
>  - ports/common/guts/posix_spawnp.c
>  - ports/common/guts/posix_spawn.c
>  - ports/common/guts/execve.c

Those already have a environment being passed in and so they already
use setupenvp and we don't need to change that. We only need to change
the places setupenv is being used.

There are still some setupenv calls left and in theory we probably
don't need many of them but they're harmless as long as we use bash's
setenv so I just left them.

Cheers,

Richard


  reply	other threads:[~2026-07-02  6:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 13:13 [pseudo] [PATCH 1/7] pseudo.h: Avoid accessing unallocated memory Richard Purdie
2026-07-01 13:13 ` [pseudo] [PATCH 2/7] pseudo_util: Avoid accidental free calls for without_libpseudo() Richard Purdie
2026-07-01 13:13 ` [pseudo] [PATCH 3/7] pseudo_util: Ensure pseudo_setupenvp handles memory consistently Richard Purdie
2026-07-01 13:13 ` [pseudo] [PATCH 4/7] pseudo_util: Avoid a memory leak in pseudo_dropenv() Richard Purdie
2026-07-01 13:13 ` [pseudo] [PATCH 5/7] pseudo_util: Clean up memory handling for setupenvp results Richard Purdie
2026-07-01 13:13 ` [pseudo] [PATCH 6/7] exec*: Replace bash workaround to avoid memory corruption Richard Purdie
2026-07-02  5:54   ` [yocto-patches] " Gaël PORTAY
2026-07-02  6:23     ` Richard Purdie [this message]
2026-07-01 13:13 ` [pseudo] [PATCH 7/7] pseudo_util: Correctly free memory allocated by pseudo_setupenvp Richard Purdie
2026-07-01 16:40 ` [pseudo] [PATCH 1/7] pseudo.h: Avoid accessing unallocated memory Mark Hatle
2026-07-01 16:47   ` Richard Purdie
2026-07-01 18:59     ` [yocto-patches] " Mark Hatle

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=7a87ea66f1db2762737f424921a38eb6ce026dfe.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=mark.hatle@kernel.crashing.org \
    --cc=seebs@seebs.net \
    --cc=yocto-patches@lists.yoctoproject.org \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.