MsMpEng’s JS engine Garbage Collection Vulnerability
MsMpEng's JS engine uses garbage collection to manage the lifetime of Javascript objects. During mark and sweep, the GC roots the vectors representing the JS stack as well as a few other hardcoded objects, traversing reachable objects from those roots then frees any unreachable objects. The native stack is not marked, meaning that any native code which is using JsObject pointers needs to take care to ensure that either the objects will remain reachable or that a GC cannot occur. The vulnerability arises when a script callback is implemented by calling JsTree::run, which takes two arguments, the JS state and a flag which determines whether GC is blocked. If another JsTree is run inside the callback which passes 0 for the gc disable flag, then the script running under that JsTree::run will be able to cause a global GC. This can be done by eval'ing a string which will cause a GC when executed. The vulnerability is further compounded by the fact that native code has a JsObject pointer on the stack that is not being kept alive by other references reachable from GC roots.