llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

libprofile: allocateOneNode() can overflow CurrentVNode

Open vedantk opened this issue 10 years ago • 2 comments

Bugzilla Link 27882
Resolution FIXED
Resolved on May 25, 2016 16:39
Version unspecified
OS All
CC @vns-mn,@hfinkel,@silvasean,@vedantk

Extended Description

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= 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.

vedantk avatar May 25 '16 23:05 vedantk

My latest change with early checking should make the problem go away -- redundant update (once) can still happen due to racing, but that should not be an issue.

david-xl avatar May 25 '16 23:05 david-xl

Sorry, David addressed this with r270766 already.

vedantk avatar May 25 '16 23:05 vedantk