<html>
<head>
<base href="http://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 --- - asan can not find left buffer overflow of new[]-allocated buffer, clang help needed"
href="http://llvm.org/bugs/show_bug.cgi?id=19838">19838</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>asan can not find left buffer overflow of new[]-allocated buffer, clang help needed
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kcc@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu, timurrrr@google.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>asan does not detect the following case:
TypeWithDtor *a = new TypeWithDtor[N];
a[-1] = ...
<a href="https://code.google.com/p/address-sanitizer/issues/detail?id=314">https://code.google.com/p/address-sanitizer/issues/detail?id=314</a>
That's because when we have new[] for a type with DTORs,
the actual allocated size is greater.
The code looks something like this:
extra = max(sizeof(long), alignment_of(TypeWithDtor));
ptr = malloc(N + extra);
*(long*)(ptr+extra-sizeof(long)) = N;
return ptr + extra; // must be properly aligned for TypeWithDtor
As the result, we will not detect overwrites of new[] cookie -- scary!
I don't see how we can implement this w/o help from FE.
First, we need to ensure alignment 8 even on 32-bits:
extra = max(8, alignment_of(TypeWithDtor));
Second, we need to poison the first extra bytes.
Lastly, we need to not instrument the legitimate loads/stores of the cookie
generated by the frontend.
All of this has to be done in FE</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>