[PATCH] PR20721: Don't let UBSan print inaccessible memory
Alexander Potapenko
glider at google.com
Tue Sep 9 00:06:41 PDT 2014
I've checked that IsAccessibleMemoryRange works on Linux and OSX on the following examples:
char *mem = (char*)mmap(0, 4096 * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
mprotect(mem + 4096, 4096, PROT_NONE);
printf("mem: %p\n", mem);
IsAccessibleMemoryRange(mem, 4095); // 1
IsAccessibleMemoryRange(mem, 4096); // 1
IsAccessibleMemoryRange(mem, 4097); // 0
IsAccessibleMemoryRange(mem + 4095, 1); // 1
IsAccessibleMemoryRange(mem + 4095, 2); // 0
IsAccessibleMemoryRange(0, 2); // 0
Care to add a unittest?
================
Comment at: lib/sanitizer_common/sanitizer_posix_libcdep.cc:169
@@ -168,1 +168,3 @@
+bool IsAccessibleMemoryRange(uptr beg, uptr size) {
+ int sock_pair[2];
----------------
Any limits on |size|?
I think it must be an sptr greater than -1 (you're going to compare bytes_written to it) and less than kPageSize (otherwise it'll take too much time to check chunks of too big size)
================
Comment at: lib/sanitizer_common/sanitizer_posix_libcdep.cc:173
@@ +172,3 @@
+ return false;
+ uptr bytes_written =
+ internal_write(sock_pair[1], reinterpret_cast<void *>(beg), size);
----------------
internal_write() returns sptr, not uptr (at least it must).
Also, when bytes_written == size (assuming size != -1), internal_iserror() is always false.
http://reviews.llvm.org/D5253
More information about the llvm-commits
mailing list