<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 - UBSAN: split object-size into real accesses and casts"
href="https://bugs.llvm.org/show_bug.cgi?id=48726">48726</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>UBSAN: split object-size into real accesses and casts
</td>
</tr>
<tr>
<th>Product</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</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>ubsan
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dvyukov@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>This come up while testing the Linux kernel:
<a href="https://groups.google.com/g/syzkaller-bugs/c/b_y3xw0wvOI/m/L074F0v3BQAJ">https://groups.google.com/g/syzkaller-bugs/c/b_y3xw0wvOI/m/L074F0v3BQAJ</a>
A minimal repro is:
#include <stdio.h>
#include <stdlib.h>
struct X {
unsigned x;
};
struct Y {
unsigned x;
unsigned y;
};
void foo(struct Y* y, unsigned x)
{
y->x += x;
}
void bar(struct X* x)
{
if (x->x % 3)
printf("%d\n", x->x);
}
int main() {
struct X x;
x.x = 0;
foo((struct Y*)&x, rand());
foo((struct Y*)&x, rand());
bar(&x);
return 0;
}
$ clang -v
clang version 11.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
ca2dcbd030eadbf0aa9b660efe864ff08af6e18b)
$ clang test.c -fsanitize=undefined -O2 -g
$ ./a.out
test.c:15:5: runtime error: member access within address 0x7ffc3ebe41e0 with
insufficient space for an object of type 'struct Y'
Here X and Y has the same "prefix" and we don't _access_ data outside of the
allocated object, but we cast smaller object to larger object. I assume this is
still undefined behavior, but how feasible is it to split this check into
actually accessing non-allocated memory and doing casts/calling functions with
wrong types? Does it make sense? This would help with incremental deployment.</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>