Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-93189

libmagic is not thread-safe when ~/.magic is used

Linking RHIVOS CVEs to...Migration: Automation ...SWIFT: POC ConversionSync from "Extern...XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • rhel-9.6, rhel-9.7
    • file
    • None
    • No
    • Important
    • rhel-plumbers
    • ssg_core_services
    • 5
    • False
    • False
    • Hide

      None

      Show
      None
    • None
    • Red Hat Enterprise Linux
    • None
    • None
    • None
    • Unspecified
    • Unspecified
    • Unspecified
    • All
    • None

      This is reopened bugzilla Bug 1942064 "libmagic is not thread-safe when ~/.magic is used"
      see https://bugzilla.redhat.com/show_bug.cgi?id=1942064

      The issue is still present, see e.g.
      https://artifacts.osci.redhat.com/testing-farm/df7a1b9e-1807-4131-a3bf-9bc973565827/,
      namely
      https://artifacts.osci.redhat.com/testing-farm/df7a1b9e-1807-4131-a3bf-9bc973565827/work-CI-Tier-1x7xqhxkw/plans/internal/CI-Tier-1/execute/data/guest/default-0/Sanity/rpmbuild-dependency-generators-sanity-test-56/output.txt

      Processing files: dummy-pkg-1.0-1.noarch
      unknown, 0: Warning: using regular magic file `/root/.magic'
      unknown, 0: Warning: using regular magic file `�p��'
      unknown, 0: Warning: using regular magic file `/root/.magic'
      error: magic_load failed: could not find any valid magic files!
      unknown, 0: Warning: using regular magic file `/root/.magic'
      error: Recognition of file "/root/rpmbuild/BUILDROOT/dummy-pkg-1.0-1.x86_64/usr/bin/dummy_execpattern_fileB.sh" failed: mode 100755 could not find any valid magic files!
      warning: Recognition of file "/root/rpmbuild/BUILDROOT/dummy-pkg-1.0-1.x86_64/usr/lib64/dummy-pkg/dummy_path_fileB" failed: mode 100644 could not find any valid magic files!
      

      It's not easy to reproduce the issue. It sometimes occurs when running this test:
      http://pkgs.devel.redhat.com/cgit/tests/rpm/tree/Sanity/rpmbuild-dependency-generators-sanity-test

      In the bugzilla Comment 4, there's a hint for a fix provided by Panu Matilainen:

      > get_default_magic(void)
      > {
      >        static const char hmagic[] = "/.magic/magic.mgc";
      >        static char *default_magic;
      >        char *home, *hmagicpath;
      >
      > #ifndef WIN32
      >        struct stat st;
      >
      >        if (default_magic) {
      >                free(default_magic);
      >                default_magic = NULL;
      >        }
      

      That's not going to work in a multi-threaded program. default_magic would have to be moved to the magic_open()'ed context, but that might not be entirely trivial as it's exposed via libmagic API in a way that doesn't include the context.

              vmihalko Vincent Mihalkovic
              emrakova@redhat.com Eva Mrakova
              Vincent Mihalkovic Vincent Mihalkovic
              RHEL CS Plumbers QE Bot RHEL CS Plumbers QE Bot
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated: