{"@ID": "1038", "@Name": "Insecure Automated Optimizations", "@Abstraction": "Class", "@Structure": "Simple", "@Status": "Draft", "Description": "The product uses a mechanism that automatically optimizes code, e.g. to improve a characteristic such as performance, but the optimizations can have an unintended side effect that might violate an intended security assumption.", "Related_Weaknesses": {"Related_Weakness": [{"@Nature": "ChildOf", "@CWE_ID": "435", "@View_ID": "1000", "@Ordinal": "Primary"}, {"@Nature": "ChildOf", "@CWE_ID": "758", "@View_ID": "1000"}]}, "Weakness_Ordinalities": {"Weakness_Ordinality": {"Ordinality": "Primary", "Description": "This weakness does not depend on other weaknesses and is the result of choices made during optimization."}}, "Applicable_Platforms": {"Language": {"@Class": "Not Language-Specific", "@Prevalence": "Undetermined"}}, "Modes_Of_Introduction": {"Introduction": {"Phase": "Architecture and Design", "Note": "Optimizations built into the design of a product can have unintended consequences during execution."}}, "Likelihood_Of_Exploit": "Low", "Common_Consequences": {"Consequence": {"Scope": "Integrity", "Impact": "Alter Execution Logic", "Note": "The optimizations alter the order of execution resulting in side effects that were not intended by the original developer."}}, "Demonstrative_Examples": {"Demonstrative_Example": {"@Demonstrative_Example_ID": "DX-200", "Intro_Text": "The following code reads a password from the\n              user, uses the password to connect to a back-end\n              mainframe, and then attempts to scrub the password from\n              memory using memset().", "Example_Code": {"@Nature": "Bad", "@Language": "C", "xhtml:div": {"@style": "margin-left:1em;", "xhtml:br": [null, null], "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"@style": "margin-left:1em;", "xhtml:i": "// Interaction with mainframe"}, "#text": "if (ConnectToMainframe(MFAddr, pwd)) {\n\t\t\t\t\t \n\t\t\t\t\t }"}, "#text": "char pwd[64];\n\t\t\t\t   if (GetPasswordFromUser(pwd, sizeof(pwd))) {\n\t\t\t\t   \n\t\t\t\t   }\n\t\t\t\t   memset(pwd, 0, sizeof(pwd));"}, "#text": "void GetData(char *MFAddr) {\n\t\t\t\t \n\t\t\t\t }"}, "Body_Text": ["The code in the example will behave\n               correctly if it is executed verbatim, but if the code\n               is compiled using an optimizing compiler, then the call to\n               memset() might be removed as a dead store, because the\n               buffer pwd is not used after its value is overwritten.\n               Because the buffer pwd contains a sensitive\n               value, the application may be vulnerable to attack if\n               the data are left memory resident. If attackers are\n               able to access the correct region of memory, they may\n               use the recovered password to gain control of the\n               system.", "It is common practice to overwrite sensitive\n               data manipulated in memory, such as passwords or\n               cryptographic keys, in order to prevent attackers from\n               learning system secrets. However, with the advent of\n               optimizing compilers, programs do not always behave as\n               their source code alone would suggest. In the example,\n               the compiler interprets the call to memset() as dead\n               code because the memory being written to is not\n               subsequently used, despite the fact that there is\n               clearly a security motivation for the operation to\n               occur. The problem here is that many compilers, and in\n               fact many programming languages, do not take this and\n               other security concerns into consideration in their\n               efforts to improve efficiency.", "Attackers typically exploit this type of\n               vulnerability by using a core dump or runtime mechanism\n               to access the memory used by a particular application\n               and recover the secret information. Once an attacker\n               has access to the secret information, it is relatively\n               straightforward to further exploit the system and\n               possibly compromise other resources with which the\n               application interacts."]}}, "Observed_Examples": {"Observed_Example": [{"Reference": "CVE-2017-5715", "Description": "Intel, ARM, and AMD processor optimizations related to speculative execution and branch prediction cause access control checks to be bypassed when placing data into the cache. Often known as \"Spectre\".", "Link": "https://www.cve.org/CVERecord?id=CVE-2017-5715"}, {"Reference": "CVE-2008-1685", "Description": "C compiler optimization, as allowed by specifications, removes code that is used to perform checks to detect integer overflows.", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-1685"}]}, "Mapping_Notes": {"Usage": "Allowed-with-Review", "Rationale": "This CWE entry is a Class and might have Base-level children that would be more appropriate", "Comments": "Examine children of this entry to see if there is a better fit", "Reasons": {"Reason": {"@Type": "Abstraction"}}}, "Content_History": {"Submission": {"Submission_Name": "CWE Content Team", "Submission_Organization": "MITRE", "Submission_Date": "2018-03-07", "Submission_Version": "3.1", "Submission_ReleaseDate": "2018-03-29"}, "Modification": [{"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-02-24", "Modification_Version": "4.0", "Modification_ReleaseDate": "2020-02-24", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-04-27", "Modification_Version": "4.11", "Modification_ReleaseDate": "2023-04-27", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-06-29", "Modification_Version": "4.12", "Modification_ReleaseDate": "2023-06-29", "Modification_Comment": "updated Mapping_Notes"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-10-26", "Modification_Version": "4.13", "Modification_ReleaseDate": "2023-10-26", "Modification_Comment": "updated Observed_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-12-11", "Modification_Version": "4.19", "Modification_ReleaseDate": "2025-12-11", "Modification_Comment": "updated Demonstrative_Examples"}]}}
