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

Changeset 242964 in webkit


Ignore:
Timestamp:
Mar 14, 2019, 2:09:46 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

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):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r242963 r242964  
     12019-03-14  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Storing a Node in Ref/RefPtr inside its destructor results in double delete
     4        https://bugs.webkit.org/show_bug.cgi?id=195661
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Set Node::m_refCount to 1 before calling its virtual destructor.
     9
     10        This is a security mitigation to prevent any code which ends up storing the node to Ref / RefPtr
     11        inside the destructor, which is a programming error caught by debug assertions, from triggering
     12        a double-delete on the same Node.
     13
     14        Such a code would hit the debug assertions in Node::deref() because m_inRemovedLastRefFunction
     15        had been set to true by then.
     16
     17        * dom/Document.cpp:
     18        (WebCore::Document::removedLastRef):
     19        * dom/Document.h:
     20        (WebCore::Document::decrementReferencingNodeCount):
     21        * dom/Node.cpp:
     22        (WebCore::Node::~Node):
     23        (WebCore::Node::removedLastRef):
     24
    1252019-03-14  Brent Fulgham  <bfulgham@apple.com>
    226
  • trunk/Source/WebCore/dom/Document.cpp

    r242899 r242964  
    721721        m_deletionHasBegun = true;
    722722#endif
     723        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.)
    723724        delete this;
    724725    }
  • trunk/Source/WebCore/dom/Document.h

    r242759 r242964  
    377377            m_deletionHasBegun = true;
    378378#endif
     379            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.)
    379380            delete this;
    380381        }
  • trunk/Source/WebCore/dom/Node.cpp

    r241932 r242964  
    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);
     
    25332535    m_deletionHasBegun = true;
    25342536#endif
     2537    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.)
    25352538    delete this;
    25362539}
Note: See TracChangeset for help on using the changeset viewer.