<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - libprofile: allocateOneNode() can overflow CurrentVNode"
   href="https://llvm.org/bugs/show_bug.cgi?id=27882">27882</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>libprofile: allocateOneNode() can overflow CurrentVNode
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vsk@apple.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In allocateOneNode(), we increment CurrentVNode without first checking if it's
greater than EndVnode. This could eventually cause CurrentVNode to overflow and
return a bad vnode:

106   Node = COMPILER_RT_PTR_FETCH_ADD(ValueProfNode, CurrentVNode, 1);         
107   if (Node >= EndVNode) {                                                   
108     if (OutOfNodesWarnings++ < MAX_VP_WARNS) {                              
109       PROF_WARN("Unable to track new values: %s. "                          
110                 " Consider using option -mllvm -vp-counters-per-site=<n> to
allocate more"
111                 " value profile counters at compile time. \n",              
112                 "Running out of static counters");                          
113     }                                                                       
114     return 0;                                                               
115   }                                                                         
116   return Node;

Sean suggested limiting increments of CurrentVNode to #threads past EndVNode.

Another option is to attempt to CmpExchange CurrentVnode to its next value
while (CurrentVNode + 1 < EndVNode). We'd return if the CmpExchange succeeds.
If the loop exits we'd return NULL.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>