⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243592 in webkit


Ignore:
Timestamp:
Mar 27, 2019, 4:52:44 PM (7 years ago)
Author:
Alan Coon
Message:

Cherry-pick r242964. rdar://problem/49359851

Storing a Node in Ref/RefPtr inside its destructor results in double delete
https://bugs.webkit.org/show_bug.cgi?id=195661

Reviewed by Brent Fulgham.

Set Node::m_refCount to 1 before calling its virtual destructor.

This is a security mitigation to prevent any code which ends up storing the node to Ref / RefPtr
inside the destructor, which is a programming error caught by debug assertions, from triggering
a double-delete on the same Node.

Such a code would hit the debug assertions in Node::deref() because m_inRemovedLastRefFunction
had been set to true by then.

  • dom/Document.cpp: (WebCore::Document::removedLastRef):
  • dom/Document.h: (WebCore::Document::decrementReferencingNodeCount):
  • dom/Node.cpp: (WebCore::Node::~Node): (WebCore::Node::removedLastRef):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242964 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-607-branch/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-607-branch/Source/WebCore/ChangeLog

    r243584 r243592  
     12019-03-27  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r242964. rdar://problem/49359851
     4
     5    Storing a Node in Ref/RefPtr inside its destructor results in double delete
     6    https://bugs.webkit.org/show_bug.cgi?id=195661
     7   
     8    Reviewed by Brent Fulgham.
     9   
     10    Set Node::m_refCount to 1 before calling its virtual destructor.
     11   
     12    This is a security mitigation to prevent any code which ends up storing the node to Ref / RefPtr
     13    inside the destructor, which is a programming error caught by debug assertions, from triggering
     14    a double-delete on the same Node.
     15   
     16    Such a code would hit the debug assertions in Node::deref() because m_inRemovedLastRefFunction
     17    had been set to true by then.
     18   
     19    * dom/Document.cpp:
     20    (WebCore::Document::removedLastRef):
     21    * dom/Document.h:
     22    (WebCore::Document::decrementReferencingNodeCount):
     23    * dom/Node.cpp:
     24    (WebCore::Node::~Node):
     25    (WebCore::Node::removedLastRef):
     26   
     27   
     28    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242964 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     29
     30    2019-03-14  Ryosuke Niwa  <rniwa@webkit.org>
     31
     32            Storing a Node in Ref/RefPtr inside its destructor results in double delete
     33            https://bugs.webkit.org/show_bug.cgi?id=195661
     34
     35            Reviewed by Brent Fulgham.
     36
     37            Set Node::m_refCount to 1 before calling its virtual destructor.
     38
     39            This is a security mitigation to prevent any code which ends up storing the node to Ref / RefPtr
     40            inside the destructor, which is a programming error caught by debug assertions, from triggering
     41            a double-delete on the same Node.
     42
     43            Such a code would hit the debug assertions in Node::deref() because m_inRemovedLastRefFunction
     44            had been set to true by then.
     45
     46            * dom/Document.cpp:
     47            (WebCore::Document::removedLastRef):
     48            * dom/Document.h:
     49            (WebCore::Document::decrementReferencingNodeCount):
     50            * dom/Node.cpp:
     51            (WebCore::Node::~Node):
     52            (WebCore::Node::removedLastRef):
     53
    1542019-03-27  Alan Coon  <alancoon@apple.com>
    255
  • branches/safari-607-branch/Source/WebCore/dom/Document.cpp

    r240377 r243592  
    722722        m_deletionHasBegun = true;
    723723#endif
     724        m_refCount = 1; // Avoid double destruction through use of RefPtr<T>. (This is a security mitigation in case of programmer error. It will ASSERT in debug builds.)
    724725        delete this;
    725726    }
  • branches/safari-607-branch/Source/WebCore/dom/Document.h

    r241508 r243592  
    383383            m_deletionHasBegun = true;
    384384#endif
     385            m_refCount = 1; // Avoid double destruction through use of RefPtr<T>. (This is a security mitigation in case of programmer error. It will ASSERT in debug builds.)
    385386            delete this;
    386387        }
  • branches/safari-607-branch/Source/WebCore/dom/Node.cpp

    r238771 r243592  
    333333{
    334334    ASSERT(isMainThread());
    335     ASSERT(!m_refCount);
     335    // We set m_refCount to 1 before calling delete to avoid double destruction through use of Ref<T>/RefPtr<T>.
     336    // This is a security mitigation in case of programmer errorm (caught by a debug assertion).
     337    ASSERT(m_refCount == 1);
    336338    ASSERT(m_deletionHasBegun);
    337339    ASSERT(!m_adoptionIsRequired);
     
    25382540    m_deletionHasBegun = true;
    25392541#endif
     2542    m_refCount = 1; // Avoid double destruction through use of RefPtr<T>. (This is a security mitigation in case of programmer error. It will ASSERT in debug builds.)
    25402543    delete this;
    25412544}
Note: See TracChangeset for help on using the changeset viewer.