Blame SOURCES/CVE-2023-23529.patch

ea0db6
From d44ded97d14cdb5ac2eb011203e5f4c45dfd94b9 Mon Sep 17 00:00:00 2001
ea0db6
From: Yusuke Suzuki <ysuzuki@apple.com>
ea0db6
Date: Wed, 8 Feb 2023 15:32:00 -0800
ea0db6
Subject: [PATCH] Cherry-pick 1b2eb138ef92. rdar://problem/105236768
ea0db6
ea0db6
    [JSC] ToThis object folding should check if AbstractValue is always an object
ea0db6
    https://bugs.webkit.org/show_bug.cgi?id=251944
ea0db6
    rdar://105175786
ea0db6
ea0db6
    Reviewed by Geoffrey Garen and Mark Lam.
ea0db6
ea0db6
    ToThis can become Identity for strict mode if it is just primitive values or its object does not have toThis function overriding.
ea0db6
    This is correct, but folding ToThis to Undefined etc. (not Identity) needs to check that an input only contains objects.
ea0db6
    This patch adds appropriate checks to prevent from converting ToThis(GlobalObject | Int32) to Undefined for example.
ea0db6
ea0db6
    * Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:
ea0db6
    (JSC::DFG::isToThisAnIdentity):
ea0db6
ea0db6
    Canonical link: https://commits.webkit.org/259548.63@safari-7615-branch
ea0db6
---
ea0db6
 .../JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h   | 9 +++++++--
ea0db6
 1 file changed, 7 insertions(+), 2 deletions(-)
ea0db6
ea0db6
diff --git a/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h b/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h
ea0db6
index ea7bcd6b7b31..ef3f6bbe376e 100644
ea0db6
--- a/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h
ea0db6
+++ b/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h
ea0db6
@@ -209,7 +209,8 @@ inline ToThisResult isToThisAnIdentity(VM& vm, ECMAMode ecmaMode, AbstractValue&
ea0db6
         }
ea0db6
     }
ea0db6
 
ea0db6
-    if ((ecmaMode.isStrict() || (valueForNode.m_type && !(valueForNode.m_type & ~SpecObject))) && valueForNode.m_structure.isFinite()) {
ea0db6
+    bool onlyObjects = valueForNode.m_type && !(valueForNode.m_type & ~SpecObject);
ea0db6
+    if ((ecmaMode.isStrict() || onlyObjects) && valueForNode.m_structure.isFinite()) {
ea0db6
         bool allStructuresAreJSScope = !valueForNode.m_structure.isClear();
ea0db6
         bool overridesToThis = false;
ea0db6
         valueForNode.m_structure.forEach([&](RegisteredStructure structure) {
ea0db6
@@ -226,9 +227,13 @@ inline ToThisResult isToThisAnIdentity(VM& vm, ECMAMode ecmaMode, AbstractValue&
ea0db6
             // If all the structures are JSScope's ones, we know the details of JSScope::toThis() operation.
ea0db6
             allStructuresAreJSScope &= structure->classInfo()->methodTable.toThis == JSScope::info()->methodTable.toThis;
ea0db6
         });
ea0db6
+
ea0db6
+        // This is correct for strict mode even if this can have non objects, since the right semantics is Identity.
ea0db6
         if (!overridesToThis)
ea0db6
             return ToThisResult::Identity;
ea0db6
-        if (allStructuresAreJSScope) {
ea0db6
+
ea0db6
+        // But this folding is available only if input is always an object.
ea0db6
+        if (onlyObjects && allStructuresAreJSScope) {
ea0db6
             if (ecmaMode.isStrict())
ea0db6
                 return ToThisResult::Undefined;
ea0db6
             return ToThisResult::GlobalThis;
ea0db6
-- 
ea0db6
2.39.1
ea0db6