<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>196472</bug_id>
          
          <creation_ts>2019-04-01 17:07:09 -0700</creation_ts>
          <short_desc>CFI base-to-derived cast error in SentinelLinkedList.h</short_desc>
          <delta_ts>2019-05-15 12:19:05 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>196533</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Christopher Reid">chris.reid</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>don.olmstead</cc>
    
    <cc>fpizlo</cc>
    
    <cc>fujii</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>saam</cc>
    
    <cc>stephan.szabo</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1523143</commentid>
    <comment_count>0</comment_count>
    <who name="Christopher Reid">chris.reid</who>
    <bug_when>2019-04-01 17:07:09 -0700</bug_when>
    <thetext>We&apos;re trying to get CFI running with JSC and one of the errors we&apos;re seeing is:
`SentinelLinkedList.h:63:24: runtime error: control flow integrity check for type &apos;JSC::Watchpoint&apos; failed during base-to-derived cast (vtable address 0x000000000000)`

(lldb) bt
* thread #6, name = &apos; via C++ thread&apos;, stop reason = Cfi bad type
    frame #0: 0x0000000000877810 testapi`__ubsan_on_report at ubsan_monitor.cc:39:40
    frame #1: 0x0000000000871d54 testapi`::~Diag() at ubsan_diag.cc:354:29
    frame #2: 0x00000000008789b4 testapi`::__ubsan_handle_cfi_bad_type() at ubsan_handlers_cxx.cc:133:3
    frame #3: 0x00000000008771b2 testapi`__ubsan_handle_cfi_check_fail at ubsan_handlers.cc:846:5
  * frame #4: 0x00000000009339a1 testapi`WTF::BasicRawSentinelNode&lt;JSC::Watchpoint&gt;::next(this=0x00007ffff0df93a0) at SentinelLinkedList.h:63:24
    frame #5: 0x0000000000a34bc5 testapi`WTF::SentinelLinkedList&lt;JSC::Watchpoint, WTF::BasicRawSentinelNode&lt;JSC::Watchpoint&gt; &gt;::begin(this=0x00007ffff0df93a0) at SentinelLinkedList.h:151:43
    frame #6: 0x0000000000a34b8b testapi`WTF::SentinelLinkedList&lt;JSC::Watchpoint, WTF::BasicRawSentinelNode&lt;JSC::Watchpoint&gt; &gt;::isEmpty(this=0x00007ffff0df93a0) at SentinelLinkedList.h:102:29
    frame #7: 0x0000000000a34b3d testapi`JSC::WatchpointSet::~WatchpointSet(this=0x00007ffff0df9398) at Watchpoint.cpp:70:19
    ...

This looks like a valid base-to-derived error because the SentinelLinkedList head and tail nodes are constructed as the base class BasicRawSentinelNode&lt;JSC::Watchpoint&gt;. m_headSentinel.next() tries to cast the object constructed as BasicRawSentinelNode&lt;JSC::Watchpoint&gt;* to a JSC::Watchpoint*. Those two objects are also different sizes. It doesn&apos;t seem like the head and tail nodes are dereferenced after a prev/next call, but it will probably be unsafe if they do end up being dereferenced.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1523798</commentid>
    <comment_count>1</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2019-04-03 11:12:22 -0700</bug_when>
    <thetext>This looks like it’s not a bug at all.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1523943</commentid>
    <comment_count>2</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2019-04-03 14:37:59 -0700</bug_when>
    <thetext>I think this use case exists everywhere in WebKit, and introducing some annotation / blacklisting this is not worth doing for this case.
The best way here would be just disabling this check in CFI side.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1536521</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2019-05-15 11:54:33 -0700</bug_when>
    <thetext>How is this OK? Why would you do this intentionally?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1536537</commentid>
    <comment_count>4</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2019-05-15 12:19:05 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #3)
&gt; How is this OK? Why would you do this intentionally?

Because it&apos;s valid C.  We&apos;re only accessing fields that exist.  We&apos;re just using the wrong enclosing type to do it.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>