RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2218235 - python3-lib389: Python tarfile extraction needs change to avoid a warning (CVE-2007-4559 mitigation)
Summary: python3-lib389: Python tarfile extraction needs change to avoid a warning (CV...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: 389-ds-base
Version: 8.9
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: LDAP Maintainers
QA Contact: LDAP QA Team
URL:
Whiteboard: sync-to-jira
Depends On:
Blocks: CVE-2007-4559
TreeView+ depends on / blocked
 
Reported: 2023-06-28 14:01 UTC by Charalampos Stratakis
Modified: 2023-11-14 16:50 UTC (History)
6 users (show)

Fixed In Version: 389-ds-1.4-820230816162424-17499975
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 2207691
Environment:
Last Closed: 2023-11-14 15:32:25 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github 389ds 389-ds-base issues 5867 0 None closed lib389 should use filter for tarfile as recommended by PEP 706 - 2023-08-04 07:15:48 UTC
Red Hat Issue Tracker IDMDS-3415 0 None None None 2023-07-19 13:26:40 UTC
Red Hat Issue Tracker RHELPLAN-161094 0 None None None 2023-06-28 14:04:36 UTC
Red Hat Product Errata RHBA-2023:6965 0 None None None 2023-11-14 15:33:08 UTC

Description Charalampos Stratakis 2023-06-28 14:01:56 UTC
+++ This bug was initially created as a clone of Bug #2207691 +++

Hello,
In RHEL 9.3 and 8.9, we're planning to fix the long-standing CVE-2007-4559: Python's `tarfile` module makes it too easy to extract tarballs in an unsafe way.
Unfortunately, for the CVE to be considered fixed, this needs a behavior change. (If you don't think this is the case, let's bring it up with the security team.)
Upstream, Python will emit deprecation warnings for 2 releases, but in RHEL we change the behavior now, emit warnings, and provide ways for customers to restore earlier behavior.
To avoid the warning, software shipped by Red Hat will need a change.

For more details see upstream PEP 706: https://peps.python.org/pep-0706
and the Red Hat knowledge base draft: https://access.redhat.com/articles/7004769

---

In __init__.py and tools.py in /usr/lib/python3.9/site-packages/lib389/, lib389 calls `tar.extract()`. The calls will emit a warning by default, and tar features deemed too dangerous for general use will even be blocked by default.

It seems that this is a backup recovery, and you trust the archive to not be malicious. In that case, add the following after the `tar = tarfile.open(backup_file)`:

    # The archive is fully trusted, override warnings and "safe" defaults
    # see https://docs.python.org/3.12/library/tarfile.html#supporting-older-python-versions
    tar.extraction_filter = (lambda member, path: member)

This will restore previous behaviour, and it's a no-op on earlier Python versions.

---

Let me know if you have any questions!

Comment 2 Viktor Ashirov 2023-08-21 12:54:26 UTC
Builds tested: 
389-ds-base-1.4.3.37-1.module+el8.9.0+19689+7d653af8.x86_64
python3-lib389-1.4.3.37-1.module+el8.9.0+19689+7d653af8.noarch

A filter was added:
$ grep -inr -A1  tarfile.open /usr/lib/python3.6/site-packages/lib389
/usr/lib/python3.6/site-packages/lib389/__init__.py:1368:        tar = tarfile.open(backup_file, "w:gz")
/usr/lib/python3.6/site-packages/lib389/__init__.py-1369-        tar.extraction_filter = (lambda member, path: member)
--
/usr/lib/python3.6/site-packages/lib389/__init__.py:1438:        tar = tarfile.open(backup_file)
/usr/lib/python3.6/site-packages/lib389/__init__.py-1439-        tar.extraction_filter = (lambda member, path: member)
--
/usr/lib/python3.6/site-packages/lib389/tools.py:302:        tar = tarfile.open(backup_file, "w:gz")
/usr/lib/python3.6/site-packages/lib389/tools.py-303-        tar.extraction_filter = (lambda member, path: member)
--
/usr/lib/python3.6/site-packages/lib389/tools.py:361:        tar = tarfile.open(backup_file)
/usr/lib/python3.6/site-packages/lib389/tools.py-362-        tar.extraction_filter = (lambda member, path: member)

Moreover, this code is in functions that are not used by any other code in lib389:
lib389.backupFS
lib389.restoreFS
lib389.tools.instanceBackupFS
lib389.tools.instanceRestoreFS

These were implemented to speed up testing, but since then were replaced by pytest fixtures. They will be removed in https://github.com/389ds/389-ds-base/issues/5875

Comment 6 errata-xmlrpc 2023-11-14 15:32:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (389-ds:1.4 bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:6965


Note You need to log in before you can comment on or make changes to this bug.