Skip to content
Snippets Groups Projects
  1. Aug 05, 2024
    • Simon McVittie's avatar
      capture-libs: Add a --level-prefix option · 9ca120f2
      Simon McVittie authored
      
      This will allow the output of capsule-capture-libs (and in principle
      other tools) to be piped to a log handler such as `logger --prio-prefix`,
      `systemd-cat --level-prefix=true` or `srt-logger --parse-level-prefix`
      which will filter or format the messages according to their severity.
      
      As currently implemented, fatal errors are emitted as LOG_ERR, warnings
      are LOG_WARNING, and all debug messages are LOG_DEBUG. A facility such
      as LOG_USER is not included: this is optional for logger(1), and not
      allowed for systemd-cat(1) and srt-logger.
      
      steamrt/tasks#444
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      9ca120f2
    • Simon McVittie's avatar
      capture-libs: Put all logging through capsule_log() wrappers · 02f9c850
      Simon McVittie authored
      
      In a couple of places this requires explicitly emitting the stringified
      value of errno, because we have equivalents of warnx() and errx(), but
      not warn() and err().
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      02f9c850
  2. Mar 05, 2024
    • Simon McVittie's avatar
    • Simon McVittie's avatar
      utils: Allocate ld_libs on the heap · 95204f4a
      Simon McVittie authored
      The ld_libs data structure is pre-allocated at maximum size instead of
      using dynamic memory allocation, in an effort to avoid use of malloc()
      during critical-path interactions with basic shared library
      infrastructure. This makes it about 1 MiB, so if users have reduced
      RLIMIT_STACK from its post-1995 default of 8 MiB for whatever reason,
      it doesn't take many levels of recursion to exceed that limit.
      
      The symptom for a stack overflow is particularly un-diagnosable (instead
      of exiting unsuccessfully with an error message, the program will just
      segfault), so allocate this data structure on the heap instead, which
      gives us the opportunity to log "libcapsule: out of memory".
      
      The equivalent data structures within libcapsule itself are still
      allocated on the stack, to avoid introducing new memory allocation
      inside a critical section.
      
      Resolves: https://github.com/ValveSoftware/steam-runtime/issues/653
      
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      95204f4a
  3. Sep 26, 2023
    • Simon McVittie's avatar
      capture-libs: Don't treat libcrypt.so.1 as part of glibc · 451b114f
      Simon McVittie authored
      
      libcrypt.so.1 is build-time optional since glibc 2.28, and is not built
      by default since 2.38. In newer distributions like Debian >= 11 and
      Ubuntu >= 20.04, it's usually replaced by libxcrypt, either compiled
      to be a drop-in replacement for glibc's libcrypt.so.1 (as in Debian,
      and therefore the Steam Runtime), or with its own SONAME libcrypt.so.2
      and optionally a secondary build as libcrypt.so.1 (as in Arch).
      
      Because libxcrypt implements a superset of the glibc libcrypt.so.1 ABI,
      adding some functions and symvers of its own, it is backward- but not
      forward-compatible: it's OK to use libxcrypt libcrypt.so.1 as a
      replacement for glibc libcrypt.so.1, but it is not OK to do the opposite.
      This means it would be incorrect for us to use a system copy of glibc
      libcrypt.so.1 (perhaps from glibc 2.32 or newer) as a replacement for a
      container's libxcrypt libcrypt.so.1, even if the system copy of glibc
      is strictly newer than the container's glibc (for example,
      Steam Runtime 3 'sniper' is based on Debian 11, so it comes with
      glibc 2.31 and libxcrypt).
      
      Unlike libpthread, libdl and librt, symbols from `libcrypt.so.1` were
      never absorbed into `libc.so.6`, so we don't have to apply the reasoning
      seen in 4c2e3e3b "capture-libs: Add a special case to support glibc 2.34+".
      
      In practice we've always got away with it in the past, but it's something
      that could cause a crash or incompatibility. I'm now looking into the
      possibility of backporting libxcrypt into Steam Runtime 1 and 2
      (steamrt/tasks#332), which makes it more important to get this right.
      
      Accordingly, exclude libcrypt.so.1 from that special treatment, and
      instead set it up to be compared separately using the same comparators
      we use for glibc: by public symvers, then by public symbols, and as a
      last resort by name.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      451b114f
    • Simon McVittie's avatar
    • Simon McVittie's avatar
      capture-libs: Add references for some more architectures · b321c0af
      Simon McVittie authored
      
      Just for completeness, we're not going to support any of these any
      time soon.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      b321c0af
  4. Aug 02, 2023
    • Simon McVittie's avatar
      capture-libs: Use warnx() instead of warn() when errno is not set · 6ff340cb
      Simon McVittie authored
      
      `warn(fmt, args)` is equivalent to (pseudocode)
      `warnx(fmt + ": %s", args, strerror(errno))`. In contexts where we do
      not have a useful value for errno, or where we are showing an error
      message that should already contain a previous result of strerror, we
      should use warnx() instead. This avoids showing a misleading errno
      which might have been set for some unrelated reason.
      
      Prompted by jupiter/tasks#887.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      6ff340cb
  5. Aug 01, 2023
  6. Oct 06, 2022
    • Ludovico de Nittis's avatar
      capture-libs: Add exact-soname option · ba2c7f3f
      Ludovico de Nittis authored
      
      Add a stricter version of `soname:`, where a library is considered to be
      a match only if its DT_SONAME is exactly what capture-libs was asked to
      look into.
      
      This can be used as a protection against misconfigured systems where two
      incompatible libraries have been symlinked.
      
      E.g. if there is an unexpected symlink `libudev.so.0 -> libudev.so.1`,
      with `soname:libudev.so.0` we will import `libudev.so.0` inside the
      container even if its DT_SONAME is `libudev.so.1`.
      
      Signed-off-by: default avatarLudovico de Nittis <ludovico.denittis@collabora.com>
      ba2c7f3f
  7. Oct 25, 2021
  8. Sep 06, 2021
  9. Jul 02, 2021
  10. Jan 18, 2021
  11. Nov 25, 2020
  12. Nov 20, 2020
  13. Oct 21, 2020
  14. Aug 27, 2020
  15. Jul 07, 2020
    • Simon McVittie's avatar
      capture-libs: Add --library-knowledge option · c0cd5a2f
      Simon McVittie authored
      
      This gives capsule-capture-libs a source of library-specific knowledge.
      For example, if we know that:
      
        * libgcc_s.so.1 is installed with an unhelpful name, but it uses
          versioned symbols the way you'd hope;
        * libdbus-1.so.3 is installed with a helpful libtool-style name,
          but has private symbols that defeat our current simplistic
          comparisons
      
      then we can express that as:
      
          [Library libgcc_s.so.1]
          CompareBy=versions;symbols;
      
          [Library libdbus-1.so.3]
          CompareBy=name;
      
      A runtime that contains a known set of libraries would be a good place
      to put library-specific knowledge about those libraries. For example,
      the maintainers of the Steam Runtime know what libraries it contains,
      and are well-placed to compare those libraries with their counterparts
      in mainstream distributions.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      c0cd5a2f
    • Simon McVittie's avatar
      utils: Move strstarts() here · e0cb1f8e
      Simon McVittie authored
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      e0cb1f8e
    • Simon McVittie's avatar
      capture-libs: Make library comparison configurable on the command-line · d20e7de2
      Simon McVittie authored
      
      This is primarily useful for testing and experimenting. Using versions
      by default in preference to filenames (--compare-by="versions,name")
      looks like it might be viable, but is a destabilising change that we
      should test more before considering a change of defaults.
      
      Meanwhile, counting symbols as a fallback (--compare-by="...,symbols")
      does not look as safe as we had hoped, because if a library maintainer
      has cleaned up their ABI by hiding private symbols without adding any
      new symbols, we will sort libraries in exactly the wrong order - and
      in reality, that seems to be what has happened in several libraries,
      for example libX11.so.6 and libXfixes.so.3.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      d20e7de2
    • Simon McVittie's avatar
      capture-libs: Expand flags into an options struct · 7d7652fa
      Simon McVittie authored
      
      We can pass other state through this, such as the comparators to be
      used to compare libraries.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      7d7652fa
    • Simon McVittie's avatar
      utils: Move library_cmp_by_name to its own translation unit · a58223c3
      Simon McVittie authored
      
      This will let us unit-test it more easily. While I'm moving it,
      re-indent it in libcapsule's coding style (4 rather than 2 space
      indents).
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      a58223c3
  16. Jun 03, 2020
  17. Nov 14, 2019
    • Simon McVittie's avatar
      Revert "capture-libs: Compare symbols and versions to determine order" · 6d9833be
      Simon McVittie authored
      
      This crashes when tests/capture-libs.pl loads libgobject-2.0.so.0 on
      Debian 10 'buster' or on Debian unstable:
      
          Stack trace of thread 87172:
          #0  0x00007f6cad431176 g_slice_free1 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6200.2)
          #1  0x00007f6cad431bc0 g_slist_remove (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6200.2)
          #2  0x00007f6cad43bf47 g_once_init_leave (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6200.2)
          #3  0x00007f6cad4f8e24 n/a (/tmp/fpzde0iMLo/host/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.6200.2)
      
      I suspect this might be because the version of GLib in /usr and the
      version in /tmp/.../host/usr both get loaded into the same address
      space?
      
      This reverts commit fff84ffb.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      6d9833be
  18. Nov 11, 2019
  19. Sep 26, 2019
    • Simon McVittie's avatar
      capture-libs: Treat unversioned libraries as in indeterminate order · d3d888c9
      Simon McVittie authored
      
      On at least Debian, Ubuntu and Manjaro, libgcc_s.so.1 is a regular
      file, not a symlink to a versioned name (libgcc_s.so.1.2.3) like most
      shared libraries.
      
      However, on Fedora 30 it is a symlink to a versioned name like
      libgcc_s-9-20190827.so.1. The name used in Fedora happens to be less
      than libgcc_s.so.1 in strverscmp() order, causing capsule-capture-libs
      to prefer the Debian/Manjaro libgcc_s.so.1, even if the container is
      older. This can cause problems if an old Debian-derived container like the
      Steam Runtime is used on a newer Fedora host, with host graphics drivers
      imported by using capsule-capture-libs: the container's libgcc_s.so.1
      does not satisfy the versioned symbol requirements of the graphics driver,
      causing loading to fail.
      
      Treat a regular file libgcc_s.so.1 as indeterminate order (or "equal"),
      so that we fall back to the default behaviour, which is currently to
      take the host version of the library in the case of a tie.
      
      This is a stopgap solution: ideally we would consider the versioned
      symbols exported by both libraries, and take whichever one has a superset
      of the version definitions exported by the other, if there is a strict
      superset in either direction (in the case of libgcc, in fact there is).
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      d3d888c9
    • Simon McVittie's avatar
      Revert "WIP: capture-libs: Treat unversioned libraries as in indeterminate order" · 702fc558
      Simon McVittie authored
      
      This reverts commit faf3daa9, which
      was merged with an outdated commit message.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      702fc558
  20. Sep 19, 2019
    • Simon McVittie's avatar
      WIP: capture-libs: Treat unversioned libraries as in indeterminate order · faf3daa9
      Simon McVittie authored
      On at least Debian, Ubuntu and Manjaro, libgcc_s.so.1 is a regular
      file, not a symlink to a versioned name (libgcc_s.so.1.2.3) like most
      shared libraries. However, on Fedora 30 it is a symlink to a versioned
      name like libgcc_s-9-20190827.so.1.
      
      This can cause problems if a Debian-derived container is used on a Fedora
      host, with host graphics drivers.
      
      TODO: it isn't clear whether this change makes any practical difference,
      because strverscmp("libgcc_s.so.1", "libgcc_s-9-20190827.so.1") == 0
      anyway.
      faf3daa9
  21. Sep 18, 2019
  22. Jul 25, 2019
  23. Jul 24, 2019
    • Simon McVittie's avatar
      capture-libs: Don't capture results of path-match if they are other ABIs · 723acab2
      Simon McVittie authored
      
      On Red Hat-derived OSs, /usr/lib/dri contains 32-bit drivers (with
      their 64-bit equivalents in /usr/lib64/dri), but on Arch Linux-derived
      OSs it contains 64-bit drivers (with their 32-bit equivalents in
      /usr/lib32/dri). As a result, we have to run both
      i386-linux-gnu-capsule-capture-libs and
      x86_64-linux-gnu-capsule-capture-libs against
      if-exists:path-match:/usr/lib/dri/*.so, ignoring anything we find that
      is of the other word-size.
      
      Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
      723acab2
  24. Apr 16, 2019
  25. Jan 30, 2019
Loading