-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing CVE-2021-42279: Chakra Scripting Engine Memory Corruption Vulnerability #6996
Closed
+138
−19
Commits on Jul 1, 2024
-
========= CVE-2021-42279: Chakra Scripting Engine Memory Corruption Vulnerability CVE-2021-42279 is a high-severity memory corruption vulnerability affecting the Chakra Scripting Engine and ChakraCore. The vulnerability stems from an out-of-bounds write, which can potentially be exploited to achieve remote code execution (RCE). An attacker could exploit this by convincing a user to perform certain actions, leading to memory corruption and potentially allowing the attacker to execute arbitrary code on the affected system. Vulnerability Type: ============= Memory Violation, resulting in Remote Code Execution (RCE) Affected Versions: ============ All versions of ChakraCore up to and including 1.11.24. Severity: ====== CVSS Score: 7.5 (HIGH) Root Cause: ========= # An out-of-bounds array write occurs when a program writes data to a memory location outside the bounds of the allocated memory for an array. # In the context of ChakraCore, an out-of-bounds write can lead to memory corruption. When data is written outside the bounds of an array, it can overwrite adjacent memory regions that may be used for other variables, objects, or control structures. This unintended overwrite can corrupt data, causing unpredictable behavior or program crashes. # Consider a simplified scenario where ChakraCore mishandles the bounds of an array: // JavaScript code that might trigger out-of-bounds write let arr = new Array(1); arr[100] = 42; // This could lead to out-of-bounds write if not properly handled # If ChakraCore does not correctly check the bounds before writing to the ‘arr[100]’ position, it could write the value ‘42’ to a memory location outside the allocated space for ‘arr’. This could overwrite important data or control structures, leading to memory corruption. Fix: === # To address this issue, fix is added to allow setting elements only if the index falls within the bounds of the array. # This fix is added such that, it takes effect only if additional command line switch “--ValidateArrayBounds” is passed to ChakraCore. With this, we ensure that the existing functionalities of ChakraCore continues to work as before. # Users of ChakraCore can take advantage of the newly added switch “--ValidateArrayBounds", which helps in making sure, any injection of elements to an array is restricted only within the bounds of the array. With this, we ensure that the out-of-bound write issue is not seen, there by preventing write operation to sensitive memory locations. # By default, “--ValidateArrayBounds" will be false. Unit Testing: ========== All unit test cases are executed and there is no failure due to these new changes. In fact, this fix takes effect only when the switch “--ValidateArrayBounds" is passed to the ChakraCore engine, so there is no impact to existing testcases/functionalities. Sample Output: =========== Consider Script "test.js" below: let arr = new Array(2); console.log("arr.length is " + arr.length) arr[0] = 0; console.log("arr[0] is " + arr[0]) arr[1] = 1; console.log("arr[1] is " + arr[1]) arr[100] = 100; console.log("arr[100] is " + arr[100]) Output without the newly added switch, C:\temp>ch.exe test.js arr.length is 2 arr[0] is 0 arr[1] is 1 arr[100] is 100 Output with the newly added switch, C:\temp>ch.exe --ValidateArrayBounds test.js arr.length is 2 arr[0] is 0 arr[1] is 1 RangeError: Memory index is out of range at Global code (C:\temp\test.js:11:1) References: ======== https://nvd.nist.gov/vuln/detail/CVE-2021-42279 https://www.cve.org/CVERecord?id=CVE-2021-42279 https://github.com/chakra-core/ChakraCore
Configuration menu - View commit details
-
Copy full SHA for 20df1ea - Browse repository at this point
Copy the full SHA 20df1eaView commit details -
Configuration menu - View commit details
-
Copy full SHA for dfa5a16 - Browse repository at this point
Copy the full SHA dfa5a16View commit details
Commits on Jul 2, 2024
-
Avoid using MSVC-internal _STRINGIZE chakra-core#6970 Below is the comment from Stephan T. Lavavej in the above mentioned pull request: "I work on Microsoft's C++ Standard Library implementation, where we recently merged microsoft/STL#4405 to remove our internal _STRINGIZE macro. Our "Real World Code" test suite, which builds popular open-source projects like yours, found that you were using this MSVC-internal macro and therefore our change broke your code. The C++ Standard's rule is that _Leading_underscore_capital identifiers (including _LEADING_UNDERSCORE_ALL_CAPS) are reserved for the compiler and Standard Library, so other libraries and applications should avoid using such reserved identifiers. This is N4971 5.10 [lex.name]/3: In addition, some identifiers appearing as a token or preprocessing-token are reserved for use by C++ implementations and shall not be used otherwise; no diagnostic is required. — Each identifier that contains a double underscore __ or begins with an underscore followed by an uppercase letter is reserved to the implementation for any use. This PR introduces non-reserved names that will work on all platforms."
Configuration menu - View commit details
-
Copy full SHA for d7c3d57 - Browse repository at this point
Copy the full SHA d7c3d57View commit details -
Updating the copyright info to follow the format of pal_copyright_lin…
…es as defined in tools/StyleChecks/check_copyright.py.
Configuration menu - View commit details
-
Copy full SHA for 1da48f1 - Browse repository at this point
Copy the full SHA 1da48f1View commit details
Commits on Jul 8, 2024
-
1. I have added two new tests as part of the unit test framework within ChakraCore (one test to verify out-of-bounds access behavior without my fix, and other test with my fix). In both the cases, I have verified that the tests are PASSED. 2. In addition to my earlier commits for handling out-of-bounds write with javascript arrays, I have added a change here to address out-of-bounds read scenario.
Configuration menu - View commit details
-
Copy full SHA for 4053e07 - Browse repository at this point
Copy the full SHA 4053e07View commit details -
Configuration menu - View commit details
-
Copy full SHA for 402d98b - Browse repository at this point
Copy the full SHA 402d98bView commit details -
This change is in continuation to my earlier commit for adding unit t…
…ests... Added a change here to summarize the unit test results, so that the unit test framewokr can capture and report the test results.
Configuration menu - View commit details
-
Copy full SHA for 8a67147 - Browse repository at this point
Copy the full SHA 8a67147View commit details -
Configuration menu - View commit details
-
Copy full SHA for a72f9f9 - Browse repository at this point
Copy the full SHA a72f9f9View commit details
Commits on Jul 9, 2024
-
Deleting one of the unit test code, that was written without followin…
…g UnitTestFramework... This will be replaced with new unit test soon, that adheres to ChakraCore's unit test framework.
Configuration menu - View commit details
-
Copy full SHA for ea32270 - Browse repository at this point
Copy the full SHA ea32270View commit details -
Configuration menu - View commit details
-
Copy full SHA for db3294f - Browse repository at this point
Copy the full SHA db3294fView commit details
Commits on Aug 12, 2024
-
Configuration menu - View commit details
-
Copy full SHA for dfe539a - Browse repository at this point
Copy the full SHA dfe539aView commit details -
Merging PR: chakra-core#6531. This is the change that was added by Microsoft as part of their December 2020 Security Update, which addresses the CVE-2020-17131. This CVE is to address Out-of-bounds Write in ChakraCore, and there by fixing memory corruption vulnerability. This change is unfortunately missed in the latest ChakraCore code base, and hence adding this for review.
Configuration menu - View commit details
-
Copy full SHA for 4800753 - Browse repository at this point
Copy the full SHA 4800753View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4726126 - Browse repository at this point
Copy the full SHA 4726126View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.