CWE-125: Out-of-bounds Read (Base)

Description: The product reads data past the end, or before the beginning, of the intended buffer.

Extended Description: Typically, this can allow attackers to read sensitive information from other memory locations or cause a crash. A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read operation, such as a NUL in a string. The expected sentinel might not be located in the out-of-bounds memory, causing excessive data to be read, leading to a segmentation fault or a buffer overflow. The product may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent read operation then produces undefined or unexpected results.



Applicable Platforms: ::LANGUAGE NAME:C:LANGUAGE PREVALENCE:Undetermined::LANGUAGE NAME:C++:LANGUAGE PREVALENCE:Undetermined::TECHNOLOGY CLASS:ICS/OT:TECHNOLOGY PREVALENCE:Often::

Modes of Introduction: ::PHASE:Implementation::



Common Consequences: ::SCOPE:Confidentiality:IMPACT:Read Memory::SCOPE:Confidentiality:IMPACT:Bypass Protection Mechanism:NOTE:By reading out-of-bounds memory, an attacker might be able to get secret values, such as memory addresses, which can be bypass protection mechanisms such as ASLR in order to improve the reliability and likelihood of exploiting a separate weakness to achieve code execution instead of just denial of service.::

Detection Methods: ::METHOD:Fuzzing:DESCRIPTION:Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.:EFFECTIVENESS:High::METHOD:Automated Static Analysis:DESCRIPTION:Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect sources (origins of input) with sinks (destinations where the data interacts with external components, a lower layer such as the OS, etc.):EFFECTIVENESS:High::

Potential Mitigations: ::PHASE:Implementation:STRATEGY:Input Validation:DESCRIPTION: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 introducing an out-of-bounds read, ensure that you validate and ensure correct calculations for any length argument, buffer size calculation, or offset. Be especially careful of relying on a sentinel (i.e. special character such as NUL) in untrusted inputs.::PHASE:Architecture and Design:STRATEGY:Language Selection:DESCRIPTION:Use a language that provides appropriate memory abstractions.::

Observed Examples: ::REFERENCE:CVE-2020-11899:DESCRIPTION:Out-of-bounds read in IP stack used in embedded systems, as exploited in the wild per CISA KEV.:LINK:https://www.cve.org/CVERecord?id=CVE-2020-11899::REFERENCE:CVE-2014-0160:DESCRIPTION:Chain: Heartbleed bug receives an inconsistent length parameter (CWE-130) enabling an out-of-bounds read (CWE-126), returning memory that could include private cryptographic keys and other sensitive data.:LINK:https://www.cve.org/CVERecord?id=CVE-2014-0160::REFERENCE:CVE-2021-40985:DESCRIPTION:HTML conversion package has a buffer under-read, allowing a crash:LINK:https://www.cve.org/CVERecord?id=CVE-2021-40985::REFERENCE:CVE-2018-10887:DESCRIPTION:Chain: unexpected sign extension (CWE-194) leads to integer overflow (CWE-190), causing an out-of-bounds read (CWE-125):LINK:https://www.cve.org/CVERecord?id=CVE-2018-10887::REFERENCE:CVE-2009-2523:DESCRIPTION:Chain: product does not handle when an input string is not NULL terminated (CWE-170), leading to buffer over-read (CWE-125) or heap-based buffer overflow (CWE-122).:LINK:https://www.cve.org/CVERecord?id=CVE-2009-2523::REFERENCE:CVE-2018-16069:DESCRIPTION:Chain: series of floating-point precision errors (CWE-1339) in a web browser rendering engine causes out-of-bounds read (CWE-125), giving access to cross-origin data:LINK:https://www.cve.org/CVERecord?id=CVE-2018-16069::REFERENCE:CVE-2004-0112:DESCRIPTION:out-of-bounds read due to improper length check:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0112::REFERENCE:CVE-2004-0183:DESCRIPTION:packet with large number of specified elements cause out-of-bounds read.:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0183::REFERENCE:CVE-2004-0221:DESCRIPTION:packet with large number of specified elements cause out-of-bounds read.:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0221::REFERENCE:CVE-2004-0184:DESCRIPTION:out-of-bounds read, resultant from integer underflow:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0184::REFERENCE:CVE-2004-1940:DESCRIPTION:large length value causes out-of-bounds read:LINK:https://www.cve.org/CVERecord?id=CVE-2004-1940::REFERENCE:CVE-2004-0421:DESCRIPTION:malformed image causes out-of-bounds read:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0421::REFERENCE:CVE-2008-4113:DESCRIPTION:OS kernel trusts userland-supplied length value, allowing reading of sensitive information:LINK:https://www.cve.org/CVERecord?id=CVE-2008-4113::