diff --git a/0001-fix-f-string-syntax-error-in-code-generation.patch b/0001-fix-f-string-syntax-error-in-code-generation.patch new file mode 100644 index 0000000000000000000000000000000000000000..d982e8189703eeecaf49ee00513ee3ca8b8f5cbc --- /dev/null +++ b/0001-fix-f-string-syntax-error-in-code-generation.patch @@ -0,0 +1,53 @@ +diff --git a/Jinja2-3.1.3/src/jinja2/compiler.py b/Jinja2-3.1.3/src/jinja2/compiler.py +index ff95c80..1ebdcd9 100644 +--- a/Jinja2-3.1.3/src/jinja2/compiler.py ++++ b/Jinja2-3.1.3/src/jinja2/compiler.py +@@ -1121,9 +1121,14 @@ class CodeGenerator(NodeVisitor): + ) + self.writeline(f"if {frame.symbols.ref(alias)} is missing:") + self.indent() ++ # The position will contain the template name, and will be formatted ++ # into a string that will be compiled into an f-string. Curly braces ++ # in the name must be replaced with escapes so that they will not be ++ # executed as part of the f-string. ++ position = self.position(node).replace("{", "{{").replace("}", "}}") + message = ( + "the template {included_template.__name__!r}" +- f" (imported on {self.position(node)})" ++ f" (imported on {position})" + f" does not export the requested name {name!r}" + ) + self.writeline( +diff --git a/Jinja2-3.1.3/tests/test_compile.py b/Jinja2-3.1.3/tests/test_compile.py +index 42a773f..19df4db 100644 +--- a/Jinja2-3.1.3/tests/test_compile.py ++++ b/Jinja2-3.1.3/tests/test_compile.py +@@ -1,6 +1,9 @@ + import os + import re + ++import pytest ++ ++from jinja2 import UndefinedError + from jinja2.environment import Environment + from jinja2.loaders import DictLoader + +@@ -26,3 +29,18 @@ def test_import_as_with_context_deterministic(tmp_path): + expect = [f"'bar{i}': " for i in range(10)] + found = re.findall(r"'bar\d': ", content)[:10] + assert found == expect ++ ++def test_undefined_import_curly_name(): ++ env = Environment( ++ loader=DictLoader( ++ { ++ "{bad}": "{% from 'macro' import m %}{{ m() }}", ++ "macro": "", ++ } ++ ) ++ ) ++ ++ # Must not raise `NameError: 'bad' is not defined`, as that would indicate ++ # that `{bad}` is being interpreted as an f-string. It must be escaped. ++ with pytest.raises(UndefinedError): ++ env.get_template("{bad}").render() diff --git a/0001-sandbox-indirect-calls-to-str.format.patch b/0001-sandbox-indirect-calls-to-str.format.patch new file mode 100644 index 0000000000000000000000000000000000000000..83bf43750af9f00d60cc5ae44c513f8df4bd12ec --- /dev/null +++ b/0001-sandbox-indirect-calls-to-str.format.patch @@ -0,0 +1,150 @@ +diff --git a/Jinja2-3.1.3/src/jinja2/sandbox.py b/Jinja2-3.1.3/src/jinja2/sandbox.py +index 06d7414..7d90951 100644 +--- a/Jinja2-3.1.3/src/jinja2/sandbox.py ++++ b/Jinja2-3.1.3/src/jinja2/sandbox.py +@@ -80,20 +80,6 @@ _mutable_spec: t.Tuple[t.Tuple[t.Type, t.FrozenSet[str]], ...] = ( + ) + + +-def inspect_format_method(callable: t.Callable) -> t.Optional[str]: +- if not isinstance( +- callable, (types.MethodType, types.BuiltinMethodType) +- ) or callable.__name__ not in ("format", "format_map"): +- return None +- +- obj = callable.__self__ +- +- if isinstance(obj, str): +- return obj +- +- return None +- +- + def safe_range(*args: int) -> range: + """A range that can't generate ranges with a length of more than + MAX_RANGE items. +@@ -313,6 +299,9 @@ class SandboxedEnvironment(Environment): + except AttributeError: + pass + else: ++ fmt = self.wrap_str_format(value) ++ if fmt is not None: ++ return fmt + if self.is_safe_attribute(obj, argument, value): + return value + return self.unsafe_undefined(obj, argument) +@@ -330,6 +319,9 @@ class SandboxedEnvironment(Environment): + except (TypeError, LookupError): + pass + else: ++ fmt = self.wrap_str_format(value) ++ if fmt is not None: ++ return fmt + if self.is_safe_attribute(obj, attribute, value): + return value + return self.unsafe_undefined(obj, attribute) +@@ -345,34 +337,48 @@ class SandboxedEnvironment(Environment): + exc=SecurityError, + ) + +- def format_string( +- self, +- s: str, +- args: t.Tuple[t.Any, ...], +- kwargs: t.Dict[str, t.Any], +- format_func: t.Optional[t.Callable] = None, +- ) -> str: +- """If a format call is detected, then this is routed through this +- method so that our safety sandbox can be used for it. ++ def wrap_str_format(self, value: t.Any) -> t.Optional[t.Callable[..., str]]: ++ """If the given value is a ``str.format`` or ``str.format_map`` method, ++ return a new function than handles sandboxing. This is done at access ++ rather than in :meth:`call`, so that calls made without ``call`` are ++ also sandboxed. + """ ++ if not isinstance( ++ value, (types.MethodType, types.BuiltinMethodType) ++ ) or value.__name__ not in ("format", "format_map"): ++ return None ++ ++ f_self: t.Any = value.__self__ ++ ++ if not isinstance(f_self, str): ++ return None ++ ++ str_type: t.Type[str] = type(f_self) ++ is_format_map = value.__name__ == "format_map" + formatter: SandboxedFormatter +- if isinstance(s, Markup): +- formatter = SandboxedEscapeFormatter(self, escape=s.escape) ++ ++ ++ if isinstance(f_self, Markup): ++ formatter = SandboxedEscapeFormatter(self, escape=f_self.escape) + else: + formatter = SandboxedFormatter(self) + +- if format_func is not None and format_func.__name__ == "format_map": +- if len(args) != 1 or kwargs: +- raise TypeError( +- "format_map() takes exactly one argument" +- f" {len(args) + (kwargs is not None)} given" +- ) ++ vformat = formatter.vformat ++ ++ def wrapper(*args: t.Any, **kwargs: t.Any) -> str: ++ if is_format_map: ++ if kwargs: ++ raise TypeError("format_map() takes no keyword arguments") ++ ++ if len(args) != 1: ++ raise TypeError( ++ f"format_map() takes exactly one argument ({len(args)} given)" ++ ) + +- kwargs = args[0] +- args = () ++ kwargs = args[0] ++ args = () + +- rv = formatter.vformat(s, args, kwargs) +- return type(s)(rv) ++ return update_wrapper(wrapper, value) + + def call( + __self, # noqa: B902 +@@ -382,9 +388,6 @@ class SandboxedEnvironment(Environment): + **kwargs: t.Any, + ) -> t.Any: + """Call an object from sandboxed code.""" +- fmt = inspect_format_method(__obj) +- if fmt is not None: +- return __self.format_string(fmt, args, kwargs, __obj) + + # the double prefixes are to avoid double keyword argument + # errors when proxying the call. +diff --git a/Jinja2-3.1.3/tests/test_security.py b/Jinja2-3.1.3/tests/test_security.py +index 0e8dc5c..81a32ae 100644 +--- a/Jinja2-3.1.3/tests/test_security.py ++++ b/Jinja2-3.1.3/tests/test_security.py +@@ -171,3 +171,20 @@ class TestStringFormatMap: + '{{ ("a{x.foo}b{y}"|safe).format_map({"x":{"foo": 42}, "y":""}) }}' + ) + assert t.render() == "a42b<foo>" ++ ++ def test_indirect_call(self): ++ def run(value, arg): ++ return value.run(arg) ++ ++ env = SandboxedEnvironment() ++ env.filters["run"] = run ++ t = env.from_string( ++ """{% set ++ ns = namespace(run="{0.__call__.__builtins__[__import__]}".format) ++ %} ++ {{ ns | run(not_here) }} ++ """ ++ ) ++ ++ with pytest.raises(SecurityError): ++ t.render() diff --git a/fence-agents.spec b/fence-agents.spec index 24ddb706ac3be75a4632a184ecb7b8a591cbfd02..6ff5afd4cf78ea0fca8ca0ec405dd1f895df9c1b 100644 --- a/fence-agents.spec +++ b/fence-agents.spec @@ -60,7 +60,7 @@ Name: fence-agents Summary: Set of unified programs capable of host isolation ("fencing") Version: 4.10.0 -Release: 76%{?alphatag:.%{alphatag}}%{anolis_release}%{?dist}.1 +Release: 76%{?alphatag:.%{alphatag}}%{anolis_release}%{?dist}.4 License: GPLv2+ and LGPLv2+ URL: https://github.com/ClusterLabs/fence-agents Source0: https://fedorahosted.org/releases/f/e/fence-agents/%{name}-%{version}.tar.gz @@ -280,6 +280,11 @@ Patch2001: RHEL-43562-fix-bundled-urllib3-CVE-2024-37891.patch # https://github.com/pypa/setuptools/pull/4332 Patch2002: setuptools-fix-CVE-2024-6345.patch +# https://github.com/pallets/jinja/commit/767b23617628419ae3709ccfb02f9602ae9fe51f +Patch2003: 0001-fix-f-string-syntax-error-in-code-generation.patch +# https://github.com/pallets/jinja/commit/48b0687e05a5466a91cd5812d604fa37ad0943b4 +Patch2004: 0001-sandbox-indirect-calls-to-str.format.patch + %global supportedagents amt_ws apc apc_snmp bladecenter brocade cisco_mds cisco_ucs compute drac5 eaton_snmp emerson eps evacuate hpblade ibmblade ibm_powervs ibm_vpc ifmib ilo ilo_moonshot ilo_mp ilo_ssh intelmodular ipdu ipmilan kdump kubevirt lpar mpath redfish rhevm rsa rsb sbd scsi vmware_rest vmware_soap wti %ifarch x86_64 %global testagents virsh heuristics_ping aliyun aws azure_arm gce openstack virt @@ -462,6 +467,13 @@ tar -xf %{setuptools}-%{setuptools_version}.tar.gz tar -zcvf %{setuptools}-%{setuptools_version}.tar.gz %{setuptools}-%{setuptools_version}/ popd +pushd %{_sourcedir} +tar -xf %{SOURCE1082} +%patch -p1 -P2003 +%patch -p1 -P2004 +tar -czvf %{SOURCE1082} %{jinja2}-%{jinja2_version}/ +popd + %build %if 0%{?fedora} || 0%{?centos} > 7 || 0%{?rhel} > 7 || 0%{?suse_version} export PYTHON="%{__python3}" @@ -1556,6 +1568,9 @@ are located on corosync cluster nodes. %endif %changelog +* Fri Jan 17 2025 Zhao Hang - 4.10.0-76.0.1.4 +- fix CVE-2024-56201 CVE-2024-56326 + * Wed Dec 04 2024 Chang Gao - 4.10.0-76.0.1.1 - Replace some packages with build env - Update CVE-2007-4559 patches