Bug 2207692
| Summary: | [RHEL9] python3-samba: Python tarfile extraction needs change to avoid a warning (CVE-2007-4559 mitigation) | |||
|---|---|---|---|---|
| Product: | Red Hat Enterprise Linux 9 | Reporter: | Petr Viktorin (pviktori) <pviktori> | |
| Component: | samba | Assignee: | Andreas Schneider <asn> | |
| Status: | CLOSED ERRATA | QA Contact: | Denis Karpelevich <dkarpele> | |
| Severity: | unspecified | Docs Contact: | ||
| Priority: | unspecified | |||
| Version: | 9.3 | CC: | aboscatt, asn, dkarpele, pfilipen | |
| Target Milestone: | rc | Keywords: | Triaged | |
| Target Release: | --- | Flags: | pm-rhel:
mirror+
|
|
| Hardware: | Unspecified | |||
| OS: | Unspecified | |||
| Whiteboard: | ||||
| Fixed In Version: | samba-4.18.4-101.el9 | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | ||
| Clone Of: | ||||
| : | 2218237 (view as bug list) | Environment: | ||
| Last Closed: | 2023-11-07 08:55:23 UTC | Type: | Bug | |
| Regression: | --- | Mount Type: | --- | |
| Documentation: | --- | CRM: | ||
| Verified Versions: | Category: | --- | ||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | ||
| Cloudforms Team: | --- | Target Upstream Version: | ||
| Embargoed: | ||||
| Bug Depends On: | ||||
| Bug Blocks: | 263261 | |||
|
Description
Petr Viktorin (pviktori)
2023-05-16 14:38:25 UTC
Samba has a python/samba/safe_tarfile.py [1] which is used by netcmd/domain_backup.py and others. However it doesn't overwrite extractall() only extract(). But looking at the test at [2] extratall seems to be covered as well.
So if we pass filter='data'
I think if we just pass filter='data' always to tarfile extract() we are fine? Or do we need to also add extractall() as it will print the warning otherwise, then we need to also implement extractall() in python/samba/safe_tarfile.py
python/samba/safe_tarfile.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/python/samba/safe_tarfile.py b/python/samba/safe_tarfile.py
index cc19770d73f..489ccb1a65b 100644
--- a/python/samba/safe_tarfile.py
+++ b/python/samba/safe_tarfile.py
@@ -24,7 +24,8 @@ class TarFile(UnsafeTarFile):
using '../../'.
"""
- def extract(self, member, path="", set_attrs=True, *, numeric_owner=False):
+ def extract(self, member, path="", set_attrs=True, *, numeric_owner=False,
+ filter="data"):
if isinstance(member, TarInfo):
name = member.name
else:
@@ -37,7 +38,7 @@ class TarFile(UnsafeTarFile):
raise ExtractError(f"path '{name}' should not start with '/'")
super().extract(member, path, set_attrs=set_attrs,
- numeric_owner=numeric_owner)
+ numeric_owner=numeric_owner, filter=filter)
open = TarFile.open
[1] https://gitlab.com/samba-team/samba/-/blob/master/python/samba/safe_tarfile.py
[2] https://gitlab.com/samba-team/samba/-/blob/master/python/samba/tests/safe_tarfile.py
For passing the filter, you'd also need to provide `extractall`. Beware that `extractall` does *not* call `extract`, they're speparate "frontends" for the internals.
Also, the filter argument isn't available on older/unpatched versions of Python, so you probably can't add it unconditionally.
But since you have a subclass, things are easier: you can just add an attribute to it:
import tarfile
class TarFile(UnsafeTarFile):
try:
extraction_filter = staticmethod(tarfile.data_filter)
except AttributeError:
... # override extract/extractall for earlier/unpatched versions
See the docs: https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extraction_filter
(Please let me know if anything is unclear/missing, Samba would be the first project I know doing it this way.)
Note that the errors raised are subclasses of TarError, but *not* ExtractError like your existing safe TarFile.
Upstream Merge Request: https://gitlab.com/samba-team/samba/-/merge_requests/3114 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 (Moderate: samba security, 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/RHSA-2023:6667 |