Description
The product invokes code that is believed to be reentrant, but the code performs a call that unintentionally produces a nested invocation of the non-reentrant code.
In a complex product, a single function call may lead to many different possible code paths, some of which may involve deeply nested calls. It may be difficult to foresee all possible code paths that could emanate from a given function call, even if that call is assumed to be reentrant. In some systems, an external actor can manipulate inputs to the system and thereby achieve a wide range of possible control flows. This is frequently a concern in products that execute scripts from untrusted sources. Examples of such products are web browsers and PDF readers. A weakness is present when one of the possible code paths resulting from a function call alters program state that the original caller assumes to be unchanged during the call.
Potential Impact
Integrity
Unexpected State
Demonstrative Examples
class Widget{private:Image* backgroundImage;public:void click(){if (backgroundImage){backgroundImage->click();}}void changeBackgroundImage(Image* newImage){if (backgroundImage){delete backgroundImage;}backgroundImage = newImage;}}class Image{public:void click(){scriptEngine->fireOnImageClick();/* perform some operations using "this" pointer */}}class Request{private:std::string uri;/* ... */public:void setup(ScriptObject* _uri){this->uri = scriptEngine->coerceToString(_uri);/* ... */}void send(ScriptObject* _data){Credentials credentials = GetCredentials(uri);std::string data = scriptEngine->coerceToString(_data);doSend(uri, credentials, data);}}Mitigations & Prevention
When architecting a system that will execute untrusted code in response to events, consider executing the untrusted event handlers asynchronously (asynchronous message passing) as opposed to executing them synchronously at the time each event fires. The untrusted code should execute at the start of the next iteration of the thread's message loop. In this way, calls into non-reentrant code are strictly serialized, so that each operation completes fully before the next operation begins. Special at
Make sure the code (e.g., function or class) in question is reentrant by not leveraging non-local data, not modifying its own code, and not calling other non-reentrant code.
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2014-1772 | In this vulnerability, by registering a malicious onerror handler, an adversary can produce unexpected re-entrance of a CDOMRange object. [REF-1098] |
| CVE-2018-8174 | This CVE covers several vulnerable scenarios enabled by abuse of the Class_Terminate feature in Microsoft VBScript. In one scenario, Class_Terminate is used to produce an undesirable re-entrance of Sc |
Related Weaknesses
Frequently Asked Questions
What is CWE-1265?
CWE-1265 (Unintended Reentrant Invocation of Non-reentrant Code Via Nested Calls) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product invokes code that is believed to be reentrant, but the code performs a call that unintentionally produces a nested invocation of the non-reentrant code.
How can CWE-1265 be exploited?
Attackers can exploit CWE-1265 (Unintended Reentrant Invocation of Non-reentrant Code Via Nested Calls) to unexpected state. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-1265?
Key mitigations include: When architecting a system that will execute untrusted code in response to events, consider executing the untrusted event handlers asynchronously (asynchronous message passing) as opposed to executing
What is the severity of CWE-1265?
CWE-1265 is classified as a Base-level weakness (Medium abstraction). It has been observed in 2 real-world CVEs.