All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve Sakoman <steve@sakoman.com>
To: openembedded-core@lists.openembedded.org
Subject: [OE-core][langdale 17/20] runqemu: Do not perturb script environment
Date: Tue,  1 Nov 2022 16:42:07 -1000	[thread overview]
Message-ID: <91c2449d4e873b2cec8777d71e218a12f899669d.1667356805.git.steve@sakoman.com> (raw)
In-Reply-To: <cover.1667356805.git.steve@sakoman.com>

From: Joshua Watt <JPEWhacker@gmail.com>

Instead of changing the script environment to affect the child
processes, make a copy of the environment with modifications and pass
that to subprocess.

Specifically, when dri rendering is enabled, LD_PRELOAD was being passed
to all processes created by the script which resulted in other commands
(e.g. stty) exiting with a failure like:

 /bin/sh: symbol lookup error: sysroots-uninative/x86_64-linux/lib/librt.so.1: undefined symbol: __libc_unwind_link_get, version GLIBC_PRIVATE

Making a copy of the environment fixes this because the LD_PRELOAD is
now only passed to qemu itself.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
(cherry picked from commit 2232599d330bd5f2a9e206b490196569ad855de8)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
---
 scripts/runqemu | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/scripts/runqemu b/scripts/runqemu
index 983f7514c7..5daf492bac 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -210,6 +210,7 @@ class BaseConfig(object):
         self.mac_tap = "52:54:00:12:34:"
         self.mac_slirp = "52:54:00:12:35:"
         # pid of the actual qemu process
+        self.qemu_environ = os.environ.copy()
         self.qemupid = None
         # avoid cleanup twice
         self.cleaned = False
@@ -449,18 +450,19 @@ class BaseConfig(object):
         # As runqemu can be run within bitbake (when using testimage, for example),
         # we need to ensure that we run host pkg-config, and that it does not
         # get mis-directed to native build paths set by bitbake.
+        env = os.environ.copy()
         try:
-            del os.environ['PKG_CONFIG_PATH']
-            del os.environ['PKG_CONFIG_DIR']
-            del os.environ['PKG_CONFIG_LIBDIR']
-            del os.environ['PKG_CONFIG_SYSROOT_DIR']
+            del env['PKG_CONFIG_PATH']
+            del env['PKG_CONFIG_DIR']
+            del env['PKG_CONFIG_LIBDIR']
+            del env['PKG_CONFIG_SYSROOT_DIR']
         except KeyError:
             pass
         try:
-            dripath = subprocess.check_output("PATH=/bin:/usr/bin:$PATH pkg-config --variable=dridriverdir dri", shell=True)
+            dripath = subprocess.check_output("PATH=/bin:/usr/bin:$PATH pkg-config --variable=dridriverdir dri", shell=True, env=env)
         except subprocess.CalledProcessError as e:
             raise RunQemuError("Could not determine the path to dri drivers on the host via pkg-config.\nPlease install Mesa development files (particularly, dri.pc) on the host machine.")
-        os.environ['LIBGL_DRIVERS_PATH'] = dripath.decode('utf-8').strip()
+        self.qemu_environ['LIBGL_DRIVERS_PATH'] = dripath.decode('utf-8').strip()
 
         # This preloads uninative libc pieces and therefore ensures that RPATH/RUNPATH
         # in host mesa drivers doesn't trick uninative into loading host libc.
@@ -468,7 +470,7 @@ class BaseConfig(object):
         uninative_path = os.path.dirname(self.get("UNINATIVE_LOADER"))
         if os.path.exists(uninative_path):
             preload_paths = [os.path.join(uninative_path, i) for i in preload_items]
-            os.environ['LD_PRELOAD'] = " ".join(preload_paths)
+            self.qemu_environ['LD_PRELOAD'] = " ".join(preload_paths)
 
     def check_args(self):
         for debug in ("-d", "--debug"):
@@ -482,8 +484,8 @@ class BaseConfig(object):
                 sys.argv.remove(quiet)
 
         if 'gl' not in sys.argv[1:] and 'gl-es' not in sys.argv[1:]:
-            os.environ['SDL_RENDER_DRIVER'] = 'software'
-            os.environ['SDL_FRAMEBUFFER_ACCELERATION'] = 'false'
+            self.qemu_environ['SDL_RENDER_DRIVER'] = 'software'
+            self.qemu_environ['SDL_FRAMEBUFFER_ACCELERATION'] = 'false'
 
         unknown_arg = ""
         for arg in sys.argv[1:]:
@@ -1369,7 +1371,7 @@ class BaseConfig(object):
         # need our font setup and show-cusor below so we need to see what qemu --help says
         # is supported so we can pass our correct config in.
         if not self.nographic and not self.sdl and not self.gtk and not self.publicvnc and not self.egl_headless == True:
-            output = subprocess.check_output([self.qemu_bin, "--help"], universal_newlines=True)
+            output = subprocess.check_output([self.qemu_bin, "--help"], universal_newlines=True, env=self.qemu_environ)
             if "-display gtk" in output:
                 self.gtk = True
             elif "-display sdl" in output:
@@ -1393,7 +1395,7 @@ class BaseConfig(object):
                 if self.sdl == True:
                     self.qemu_opt += 'sdl,'
                 elif self.gtk == True:
-                    os.environ['FONTCONFIG_PATH'] = '/etc/fonts'
+                    self.qemu_environ['FONTCONFIG_PATH'] = '/etc/fonts'
                     self.qemu_opt += 'gtk,'
 
                 if self.gl == True:
@@ -1514,7 +1516,7 @@ class BaseConfig(object):
         if len(self.portlocks):
             for descriptor in self.portlocks.values():
                 pass_fds.append(descriptor.fileno())
-        process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds)
+        process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds, env=self.qemu_environ)
         self.qemupid = process.pid
         retcode = process.wait()
         if retcode:
-- 
2.25.1



  parent reply	other threads:[~2022-11-02  2:43 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02  2:41 [OE-core][langdale 00/20] Patch review Steve Sakoman
2022-11-02  2:41 ` [OE-core][langdale 01/20] openssl: CVE-2022-3358 Using a Custom Cipher with NID_undef may lead to NULL encryption Steve Sakoman
2022-11-03 15:54   ` Patrick Williams
2022-11-03 16:28     ` Steve Sakoman
2022-11-03 16:48       ` Patrick Williams
2022-11-02  2:41 ` [OE-core][langdale 02/20] libx11: apply the fix for CVE-2022-3554 Steve Sakoman
2022-11-02  2:41 ` [OE-core][langdale 03/20] xserver-xorg: ignore CVE-2022-3553 as it is XQuartz-specific Steve Sakoman
2022-11-02  2:41 ` [OE-core][langdale 04/20] xserver-xorg: backport fixes for CVE-2022-3550 and CVE-2022-3551 Steve Sakoman
2022-11-02  2:41 ` [OE-core][langdale 05/20] tiff: fix a number of CVEs Steve Sakoman
2022-11-02  2:41 ` [OE-core][langdale 06/20] tiff: fix a typo for CVE-2022-2953.patch Steve Sakoman
2022-11-02  2:41 ` [OE-core][langdale 07/20] qemu: backport the fix for CVE-2022-3165 Steve Sakoman
2022-11-02  2:41 ` [OE-core][langdale 08/20] meson: make wrapper options sub-command specific Steve Sakoman
2022-11-02  2:41 ` [OE-core][langdale 09/20] meson: upgrade 0.63.2 -> 0.63.3 Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 10/20] vim: Upgrade 9.0.0598 -> 9.0.0614 Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 11/20] pango: upgrade 1.50.9 -> 1.50.10 Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 12/20] mtools: upgrade 4.0.40 -> 4.0.41 Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 13/20] ifupdown: upgrade 0.8.37 -> 0.8.39 Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 14/20] mesa: only apply patch to fix ALWAYS_INLINE for native Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 15/20] buildtools-tarball: export certificates to python and curl Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 16/20] qemu-native: Add PACKAGECONFIG option for jack Steve Sakoman
2022-11-02  2:42 ` Steve Sakoman [this message]
2022-11-02  2:42 ` [OE-core][langdale 18/20] runqemu: Fix gl-es argument from causing other arguments to be ignored Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 19/20] overlayfs: Allow not used mount points Steve Sakoman
2022-11-02  2:42 ` [OE-core][langdale 20/20] gnutls: upgrade 3.7.7 -> 3.7.8 Steve Sakoman

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=91c2449d4e873b2cec8777d71e218a12f899669d.1667356805.git.steve@sakoman.com \
    --to=steve@sakoman.com \
    --cc=openembedded-core@lists.openembedded.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.