<div dir="ltr">Hello!<div><br></div><div style>I'm new to LLVM and am trying to build a checker for clang. In a program like </div><div style><br></div><div style>void foo()</div><div style>{</div><div style>int a;</div>
<div style>int b;</div><div style>int c;</div><div style>int d;</div><div style>doSomeThingWith(c);</div><div style>doSomeThingWith(a);</div><div style>}</div><div style><br></div><div style>If doSomeThingWith(c) detects a problem with the value c, I want to taint variables beyond c (aka c, b and a) so that when calling doSomeThingWith(a), the function says "hey, this value is tainted but it shouldn't". </div>
<div style><br></div><div style>I did something like : </div><div style><br></div><div style><div>const StackLocalsSpaceRegion *stackFrame = R->getMemRegionManager()->getStackLocalsRegion(C.getStackFrame());</div><div>
<br></div><div>state->addTaint(dyn_cast<MemRegion>(stackFrame));</div><div>state->addTaint(stackFrame);</div><div><br></div><div style>in checkLocation to say "hey, I want to taint the entire stack frame". And then, I do the check in checkPreCall with : </div>
</div><div style><br></div><div style>if (State->isTainted(dyn_cast<MemRegion>(stackFrame)))</div><div style> // bad</div><div style><br></div><div style>or </div><div style><br></div><div style><div><span style="white-space:pre">i</span>f (R && State->isTainted(dyn_cast<MemRegion>(R)))</div>
<div><span class="" style="white-space:pre">    </span>std::cout << "Corrupted stack" << std::endl;</div><div><br></div><div style>or</div><div style><br></div><div style>State->isTainted(R->getMemRegionManager()->getStackLocalsRegion(C.getStackFrame()))<br>
</div><div style><br></div><div style><br></div><div style>But when I test my checker on a buggy program, the taint checking doesn't work. Stack frames are note the same. If I only taint MemRegions, I actually only taint a chunk of a variable. (like a byte of a buffer) I can't taint adjacent data. I can't say for example "I can overflow a buffer from up to 12 bytes so I will taint the 12 bytes that follow that buffer aka the 3 4-bytes integers that are above the buffer in the code". </div>
<div style><br></div><div style>Could you please give me some help doing that? What is the proper way to taint / checker the taint of the stack frame? How can I find adjacent variables? (didn't find anything that fits in the doxygene doc) </div>
<div style><br></div><div style>Thank you in advance! </div><div style><br></div></div></div>