Changeset 241300 in webkit


Ignore:
Timestamp:
Feb 12, 2019, 10:21:45 AM (6 years ago)
Author:
mark.lam@apple.com
Message:

Add some null checks in JSNodeCustom.h's root() and generated isReachableFromOpaqueRoots() functions.
https://bugs.webkit.org/show_bug.cgi?id=194530
<rdar://problem/47973274>

Reviewed by Chris Dumez.

This is needed to fix a null pointer dereference that arises from the following scenario:

  1. a Document detaches from its StyleSheetList.
  2. the JSStyleSheetList that is associated with the detached StyleSheetList has yet to be scanned and collected by the GC.
  3. the GC eventually looks for the opaque root of the StyleSheetList's owner, and discovers a null owner pointer.

This patch fixes this issue by applying the following null checks:

  1. Add a null check in JSNodeCustom.h's root().

root() is called from a isReachableFromOpaqueRoots() generated by CodeGeneratorJS.pm.
isReachableFromOpaqueRoots() calls a ownerNode() method and passes its result
to root(). However, depending on which class the ownerNode() method belongs to,
it can either return a pointer or a reference. The null check only makes sense
in the pointer case.

To accommodate the 2 forms, root() itself is has an overload that takes a
reference instead of a pointer.

Since CodeGeneratorJS.pm can't tell what the generated class' ownerNode()
returns, it can't discern when the result is a pointer and apply the null check.
Instead, we just add the null check to the version of root() that takes a
pointer. If the node pointer is null, we'll return a null opaque root.

  1. Fix CodeGeneratorJS.pm to null check the opaque root before using it.
  • bindings/js/JSNodeCustom.h:

(WebCore::root):

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateImplementation):

  • bindings/scripts/test/JS/JSTestGenerateIsReachable.cpp:

(WebCore::JSTestGenerateIsReachableOwner::isReachableFromOpaqueRoots):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r241299 r241300  
     12019-02-12  Mark Lam  <mark.lam@apple.com>
     2
     3        Add some null checks in JSNodeCustom.h's root() and generated isReachableFromOpaqueRoots() functions.
     4        https://bugs.webkit.org/show_bug.cgi?id=194530
     5        <rdar://problem/47973274>
     6
     7        Reviewed by Chris Dumez.
     8
     9        This is needed to fix a null pointer dereference that arises from the following scenario:
     10        1. a Document detaches from its StyleSheetList.
     11        2. the JSStyleSheetList that is associated with the detached StyleSheetList has yet
     12           to be scanned and collected by the GC.
     13        3. the GC eventually looks for the opaque root of the StyleSheetList's owner, and
     14           discovers a null owner pointer.
     15
     16        This patch fixes this issue by applying the following null checks:
     17
     18        1. Add a null check in JSNodeCustom.h's root().
     19
     20           root() is called from a isReachableFromOpaqueRoots() generated by CodeGeneratorJS.pm.
     21           isReachableFromOpaqueRoots() calls a ownerNode() method and passes its result
     22           to root().  However, depending on which class the ownerNode() method belongs to,
     23           it can either return a pointer or a reference.  The null check only makes sense
     24           in the pointer case.
     25
     26           To accommodate the 2 forms, root() itself is has an overload that takes a
     27           reference instead of a pointer.
     28
     29           Since CodeGeneratorJS.pm can't tell what the generated class' ownerNode()
     30           returns, it can't discern when the result is a pointer and apply the null check.
     31           Instead, we just add the null check to the version of root() that takes a
     32           pointer.  If the node pointer is null, we'll return a null opaque root.
     33
     34        2. Fix CodeGeneratorJS.pm to null check the opaque root before using it.
     35
     36        * bindings/js/JSNodeCustom.h:
     37        (WebCore::root):
     38        * bindings/scripts/CodeGeneratorJS.pm:
     39        (GenerateImplementation):
     40        * bindings/scripts/test/JS/JSTestGenerateIsReachable.cpp:
     41        (WebCore::JSTestGenerateIsReachableOwner::isReachableFromOpaqueRoots):
     42
    1432019-02-12  Andy Estes  <aestes@apple.com>
    244
  • trunk/Source/WebCore/bindings/js/JSNodeCustom.h

    r229416 r241300  
    11/*
    2  * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2007-2019 Apple Inc. All rights reserved.
    33 * Copyright (C) 2018 Yusuke Suzuki <utatane.tea@gmail.com>.
    44 *
     
    8181inline void* root(Node* node)
    8282{
    83     return node->opaqueRoot();
     83    return node ? node->opaqueRoot() : nullptr;
    8484}
    8585
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r240965 r241300  
    44# Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
    55# Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
    6 # Copyright (C) 2006-2018 Apple Inc. All rights reserved.
     6# Copyright (C) 2006-2019 Apple Inc. All rights reserved.
    77# Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
    88# Copyright (C) Research In Motion Limited 2010. All rights reserved.
     
    46804680
    46814681            push(@implContent, $rootString);
    4682             push(@implContent, "    return visitor.containsOpaqueRoot(root);\n");
     4682            push(@implContent, "    return root && visitor.containsOpaqueRoot(root);\n");
    46834683        } else {
    46844684            if (!$emittedJSCast) {
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestGenerateIsReachable.cpp

    r240557 r241300  
    205205    if (UNLIKELY(reason))
    206206        *reason = "Reachable from TestGenerateIsReachable";
    207     return visitor.containsOpaqueRoot(root);
     207    return root && visitor.containsOpaqueRoot(root);
    208208}
    209209
Note: See TracChangeset for help on using the changeset viewer.