<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - -fstack-protector-strong doesn't catch direct out-of-bounds via non-array"
href="https://bugs.llvm.org/show_bug.cgi?id=43478">43478</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-fstack-protector-strong doesn't catch direct out-of-bounds via non-array
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>john.brawn@arm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>If the following is compiled with -O0 -fstack-protector-strong
int n = 4;
int fn() {
long x = 0;
(&x)[n] = 1; // out-of-bounds write
return x;
}
then we generate an out-of-bounds write to the stack, but don't insert stack
protector code (with -O1 the write is optimised to a write to x under the
assumption that n must be 0, so there's no out-of-bounds write).
What's going on here is that for -fstack-protector-strong we insert the stack
protection if StackProtector::HasAddressTaken sees that the address of x is
stored somewhere (or rather we will once PR43308 is done, currently it's
PointerMayBeCaptured doing this check). If the address is directly used in a
gep which is used as the address operand of a store then this isn't detected.
As to what to do about this, counting all uses of the address in a store as
requiring stack protection is too much as that would catch all simple stores
(i.e. x = n). Probably instead we want to catch the case when the address is
used in a gep that possibly is out-of-bounds, and that gep value is then the
address operand of a store (or something store-like such as cmpxchg).</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>