Page MenuHomeFreeBSD

D59945.1794321416.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D59945.1794321416.diff

diff --git a/sys/kern/subr_msan.c b/sys/kern/subr_msan.c
--- a/sys/kern/subr_msan.c
+++ b/sys/kern/subr_msan.c
@@ -166,12 +166,40 @@
}
}
+/*
+ * A KMSAN_TYPE_STACK origin points at the string that the compiler passed to
+ * __msan_poison_alloca() to describe the variable, but the format of that
+ * string has changed over time: older versions of clang emitted
+ * "----var@function", current versions emit just the variable name. Rather
+ * than assume a format, copy out whatever printable string is there. Returns
+ * false if it does not look like a string, e.g. if the origin holds a code
+ * address instead of a description.
+ */
+static bool
+kmsan_orig_descr(uintptr_t ptr, char *buf, size_t bufsz)
+{
+ const char *s;
+ size_t i;
+
+ s = (const char *)ptr;
+ for (i = 0; i < bufsz - 1; i++) {
+ if (s[i] == '\0')
+ break;
+ if (s[i] < 0x20 || s[i] > 0x7e)
+ return (false);
+ }
+ if (i < 4)
+ return (false);
+ __builtin_memcpy(buf, s, i);
+ buf[i] = '\0';
+ return (true);
+}
+
static void
kmsan_report_hook(const void *addr, msan_orig_t *orig, size_t size, size_t off,
const char *hook)
{
const char *typename;
- char *var, *fn;
uintptr_t ptr;
long foff;
char buf[128];
@@ -187,31 +215,33 @@
__compiler_membar();
if (*orig == 0) {
- REPORT("MSan: Uninitialized memory in %s, offset %zu",
- hook, off);
+ /*
+ * No origin was recorded for this byte. Report the size and
+ * address anyway; they are often enough to identify what the
+ * memory is, which is all the information available here.
+ */
+ REPORT("MSan: Uninitialized memory in %s, offset %zu/%zu, "
+ "addr %p", hook, off, size, addr);
goto out;
}
kmsan_md_orig_decode(*orig, &type, &ptr);
typename = kmsan_orig_name(type);
- if (linker_ddb_search_symbol_name((caddr_t)ptr, buf,
+ /*
+ * Check for a variable description before searching for a symbol: the
+ * description is a string in .rodata, so a symbol search will "succeed"
+ * by finding whatever unrelated symbol precedes it.
+ */
+ if (type == KMSAN_TYPE_STACK &&
+ kmsan_orig_descr(ptr, buf, sizeof(buf))) {
+ REPORT("MSan: Uninitialized %s memory in %s, offset %zu/%zu, "
+ "addr %p, from '%s'", typename, hook, off, size, addr, buf);
+ } else if (linker_ddb_search_symbol_name((caddr_t)ptr, buf,
sizeof(buf), &foff) == 0) {
REPORT("MSan: Uninitialized %s memory in %s, "
"offset %zu/%zu, addr %p, from %s+%#lx",
typename, hook, off, size, addr, buf, foff);
- } else if (__builtin_memcmp((void *)ptr, "----", 4) == 0) {
- /*
- * The format of the string is: "----var@function". Parse it to
- * display a nice warning.
- */
- var = (char *)ptr + 4;
- strlcpy(buf, var, sizeof(buf));
- var = buf;
- fn = strchr(buf, '@');
- *fn++ = '\0';
- REPORT("MSan: Uninitialized %s memory in %s, offset %zu, "
- "variable '%s' from %s", typename, hook, off, var, fn);
} else {
REPORT("MSan: Uninitialized %s memory in %s, "
"offset %zu/%zu, addr %p, PC %p",
@@ -227,7 +257,6 @@
kmsan_report_inline(msan_orig_t orig, unsigned long pc)
{
const char *typename;
- char *var, *fn;
uintptr_t ptr;
char buf[128];
long foff;
@@ -250,21 +279,14 @@
kmsan_md_orig_decode(orig, &type, &ptr);
typename = kmsan_orig_name(type);
- if (linker_ddb_search_symbol_name((caddr_t)ptr, buf,
+ /* See the comment about the description check in kmsan_report_hook(). */
+ if (type == KMSAN_TYPE_STACK &&
+ kmsan_orig_descr(ptr, buf, sizeof(buf))) {
+ REPORT("MSan: Uninitialized memory from '%s'", buf);
+ } else if (linker_ddb_search_symbol_name((caddr_t)ptr, buf,
sizeof(buf), &foff) == 0) {
REPORT("MSan: Uninitialized %s memory from %s+%#lx",
typename, buf, foff);
- } else if (__builtin_memcmp((void *)ptr, "----", 4) == 0) {
- /*
- * The format of the string is: "----var@function". Parse it to
- * display a nice warning.
- */
- var = (char *)ptr + 4;
- strlcpy(buf, var, sizeof(buf));
- var = buf;
- fn = strchr(buf, '@');
- *fn++ = '\0';
- REPORT("MSan: Uninitialized variable '%s' from %s", var, fn);
} else {
REPORT("MSan: Uninitialized %s memory, origin %x",
typename, orig);

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 10, 2:36 PM (5 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39560819
Default Alt Text
D59945.1794321416.diff (4 KB)

Event Timeline