CVE Vulnerabilities

CVE-2021-42574

Improper Control of Generation of Code ('Code Injection')

Published: Nov 01, 2021 | Modified: Aug 04, 2024
CVSS 3.x
8.3
HIGH
Source:
NVD
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:H
CVSS 2.x
5.1 MEDIUM
AV:N/AC:H/Au:N/C:P/I:P/A:P
RedHat/V2
RedHat/V3
8.5 MODERATE
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:H
Ubuntu
MEDIUM

An issue was discovered in the Bidirectional Algorithm in the Unicode Specification through 14.0. It permits the visual reordering of characters via control sequences, which can be used to craft source code that renders different logic than the logical ordering of tokens ingested by compilers and interpreters. Adversaries can leverage this to encode source code for compilers accepting Unicode such that targeted vulnerabilities are introduced invisibly to human reviewers. NOTE: the Unicode Consortium offers the following alternative approach to presenting this concern. An issue is noted in the nature of international text that can affect applications that implement support for The Unicode Standard and the Unicode Bidirectional Algorithm (all versions). Due to text display behavior when text includes left-to-right and right-to-left characters, the visual order of tokens may be different from their logical order. Additionally, control characters needed to fully support the requirements of bidirectional text can further obfuscate the logical order of tokens. Unless mitigated, an adversary could craft source code such that the ordering of tokens perceived by human reviewers does not match what will be processed by a compiler/interpreter/etc. The Unicode Consortium has documented this class of vulnerability in its document, Unicode Technical Report #36, Unicode Security Considerations. The Unicode Consortium also provides guidance on mitigations for this class of issues in Unicode Technical Standard #39, Unicode Security Mechanisms, and in Unicode Standard Annex #31, Unicode Identifier and Pattern Syntax. Also, the BIDI specification allows applications to tailor the implementation in ways that can mitigate misleading visual reordering in program text; see HL4 in Unicode Standard Annex #9, Unicode Bidirectional Algorithm.

Weakness

The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.

Affected Software

Name Vendor Start Version End Version
Unicode Unicode * 14.0.0 (excluding)
Red Hat Developer Tools RedHat rust-toolset-1.54-rust-0:1.54.0-4.el7_9 *
Red Hat Enterprise Linux 7 RedHat binutils-0:2.27-44.base.el7_9.1 *
Red Hat Enterprise Linux 7.2 Advanced Update Support RedHat binutils-0:2.23.52.0.1-55.el7_2.4 *
Red Hat Enterprise Linux 7.3 Advanced Update Support RedHat binutils-0:2.25.1-22.base.el7_3.3 *
Red Hat Enterprise Linux 7.4 Advanced Update Support RedHat binutils-0:2.25.1-32.base.el7_4.5 *
Red Hat Enterprise Linux 7.6 Advanced Update Support RedHat binutils-0:2.27-34.base.el7_6.4 *
Red Hat Enterprise Linux 7.6 Telco Extended Update Support RedHat binutils-0:2.27-34.base.el7_6.4 *
Red Hat Enterprise Linux 7.6 Update Services for SAP Solutions RedHat binutils-0:2.27-34.base.el7_6.4 *
Red Hat Enterprise Linux 7.7 Advanced Update Support RedHat binutils-0:2.27-41.base.el7_7.4 *
Red Hat Enterprise Linux 7.7 Telco Extended Update Support RedHat binutils-0:2.27-41.base.el7_7.4 *
Red Hat Enterprise Linux 7.7 Update Services for SAP Solutions RedHat binutils-0:2.27-41.base.el7_7.4 *
Red Hat Enterprise Linux 8 RedHat gcc-toolset-10-gcc-0:10.3.1-1.2.el8_5 *
Red Hat Enterprise Linux 8 RedHat gcc-toolset-11-gcc-0:11.2.1-1.2.el8_5 *
Red Hat Enterprise Linux 8 RedHat gcc-0:8.5.0-4.el8_5 *
Red Hat Enterprise Linux 8 RedHat rust-toolset:rhel8-8050020211027231136.5c15747c *
Red Hat Enterprise Linux 8 RedHat gcc-toolset-11-annobin-0:9.85-1.el8_5.1 *
Red Hat Enterprise Linux 8 RedHat gcc-toolset-10-annobin-0:9.29-1.el8_5.2 *
Red Hat Enterprise Linux 8 RedHat annobin-0:9.72-1.el8_5.2 *
Red Hat Enterprise Linux 8 RedHat gcc-toolset-11-binutils-0:2.36.1-1.el8_5.1 *
Red Hat Enterprise Linux 8 RedHat binutils-0:2.30-108.el8_5.1 *
Red Hat Enterprise Linux 8 RedHat gcc-toolset-10-binutils-0:2.35-8.el8_5.6 *
Red Hat Enterprise Linux 8 RedHat llvm-toolset:rhel8-8050020211110163227.c5368500 *
Red Hat Enterprise Linux 8 RedHat gcc-0:8.5.0-4.el8_5 *
Red Hat Enterprise Linux 8 RedHat binutils-0:2.30-108.el8_5.1 *
Red Hat Enterprise Linux 8.1 Extended Update Support RedHat annobin-0:8.78-1.el8_1.1 *
Red Hat Enterprise Linux 8.1 Extended Update Support RedHat binutils-0:2.30-58.el8_1.3 *
Red Hat Enterprise Linux 8.2 Extended Update Support RedHat annobin-0:8.90-1.el8_2.1 *
Red Hat Enterprise Linux 8.2 Extended Update Support RedHat binutils-0:2.30-73.el8_2.1 *
Red Hat Enterprise Linux 8.4 Extended Update Support RedHat gcc-toolset-10-binutils-0:2.35-8.el8_4.5 *
Red Hat Enterprise Linux 8.4 Extended Update Support RedHat gcc-toolset-10-annobin-0:9.29-1.el8_4.1 *
Red Hat Enterprise Linux 8.4 Extended Update Support RedHat binutils-0:2.30-93.el8_4.2 *
Red Hat Enterprise Linux 8.4 Extended Update Support RedHat annobin-0:9.50-1.el8_4.1 *
Red Hat Software Collections for Red Hat Enterprise Linux 7 RedHat devtoolset-10-gcc-0:10.2.1-11.2.el7 *
Red Hat Software Collections for Red Hat Enterprise Linux 7 RedHat devtoolset-11-gcc-0:11.2.1-1.2.el7 *
Red Hat Software Collections for Red Hat Enterprise Linux 7 RedHat devtoolset-10-binutils-0:2.35-5.el7.3 *
Red Hat Software Collections for Red Hat Enterprise Linux 7 RedHat devtoolset-10-annobin-0:9.23-4.el7.1 *
Red Hat Software Collections for Red Hat Enterprise Linux 7 RedHat devtoolset-11-annobin-0:9.82-1.el7.1 *
Red Hat Software Collections for Red Hat Enterprise Linux 7 RedHat devtoolset-11-binutils-0:2.36.1-1.el7.1 *
Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS RedHat devtoolset-10-gcc-0:10.2.1-11.2.el7 *
Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS RedHat devtoolset-11-gcc-0:11.2.1-1.2.el7 *
Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS RedHat devtoolset-10-binutils-0:2.35-5.el7.3 *
Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS RedHat devtoolset-10-annobin-0:9.23-4.el7.1 *
Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS RedHat devtoolset-11-annobin-0:9.82-1.el7.1 *
Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS RedHat devtoolset-11-binutils-0:2.36.1-1.el7.1 *
Rustc Ubuntu bionic *
Rustc Ubuntu focal *
Rustc Ubuntu hirsute *
Rustc Ubuntu impish *
Rustc Ubuntu jammy *
Rustc Ubuntu kinetic *
Rustc Ubuntu trusty *
Rustc Ubuntu upstream *
Rustc Ubuntu xenial *

Extended Description

When a product allows a user’s input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution. Injection problems encompass a wide variety of issues – all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common – i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.

Potential Mitigations

  • Run your code in a “jail” or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which code can be executed by your product.
  • Examples include the Unix chroot jail and AppArmor. In general, managed code may provide some protection.
  • This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise.
  • Be careful to avoid CWE-243 and other weaknesses related to jails.
  • Assume all input is malicious. Use an “accept known good” input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does.
  • When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, “boat” may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as “red” or “blue.”
  • Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code’s environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
  • To reduce the likelihood of code injection, use stringent allowlists that limit which constructs are allowed. If you are dynamically constructing code that invokes a function, then verifying that the input is alphanumeric might be insufficient. An attacker might still be able to reference a dangerous function that you did not intend to allow, such as system(), exec(), or exit().

References