[PATCH] [MSan] Add __msan_unpoison_string() to the public interface.
Sergey Matveev
earthdok at google.com
Thu Mar 20 09:53:05 PDT 2014
Hi eugenis,
Using __msan_unpoison() on null-terminated strings is awkward because
strlen() can't be called on a poisoned string. This case warrants a special
interface function.
http://llvm-reviews.chandlerc.com/D3135
Files:
include/sanitizer/msan_interface.h
lib/msan/msan_interceptors.cc
lib/msan/msan_interface_internal.h
test/msan/unpoison_string.cc
Index: include/sanitizer/msan_interface.h
===================================================================
--- include/sanitizer/msan_interface.h
+++ include/sanitizer/msan_interface.h
@@ -38,6 +38,10 @@
/* Make memory region fully initialized (without changing its contents). */
void __msan_unpoison(const volatile void *a, size_t size);
+ /* Make a null-terminated string fully initialized (without changing its
+ contents). */
+ void __msan_unpoison_string(const volatile char *a);
+
/* Make memory region fully uninitialized (without changing its contents). */
void __msan_poison(const volatile void *a, size_t size);
Index: lib/msan/msan_interceptors.cc
===================================================================
--- lib/msan/msan_interceptors.cc
+++ lib/msan/msan_interceptors.cc
@@ -1372,6 +1372,11 @@
return res;
}
+void __msan_unpoison_string(const char* s) {
+ if (!MEM_IS_APP(s)) return;
+ __msan_unpoison(s, REAL(strlen)(s) + 1);
+}
+
namespace __msan {
void CopyOrigin(void *dst, const void *src, uptr size, StackTrace *stack) {
Index: lib/msan/msan_interface_internal.h
===================================================================
--- lib/msan/msan_interface_internal.h
+++ lib/msan/msan_interface_internal.h
@@ -40,6 +40,8 @@
SANITIZER_INTERFACE_ATTRIBUTE
void __msan_unpoison(const void *a, uptr size);
SANITIZER_INTERFACE_ATTRIBUTE
+void __msan_unpoison_string(const char *s);
+SANITIZER_INTERFACE_ATTRIBUTE
void __msan_clear_and_unpoison(void *a, uptr size);
SANITIZER_INTERFACE_ATTRIBUTE
void* __msan_memcpy(void *dst, const void *src, uptr size);
Index: test/msan/unpoison_string.cc
===================================================================
--- /dev/null
+++ test/msan/unpoison_string.cc
@@ -0,0 +1,15 @@
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -o %t
+// RUN: %t
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O3 %s -o %t
+// RUN: %t
+
+#include <assert.h>
+#include <string.h>
+#include <sanitizer/msan_interface.h>
+
+int main(int argc, char **argv) {
+ char s[20] = "string";
+ __msan_poison(s, 20 * sizeof(char));
+ __msan_unpoison_string(s);
+ assert(__msan_test_shadow(s, 20 * sizeof(char)) == strlen("string") + 1);
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3135.1.patch
Type: text/x-patch
Size: 2260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140320/34ceef75/attachment.bin>
More information about the llvm-commits
mailing list