[compiler-rt] r243610 - [sanitizer] add a weak hook for strncmp interceptor, both to dfsan and other sanitizers. Hide the declaration and the calls in better macros
Kostya Serebryany
kcc at google.com
Thu Jul 30 18:07:57 PDT 2015
Thanks!
Should be fixed as part of r243721.
On Thu, Jul 30, 2015 at 5:52 PM, Alexey Samsonov <vonosmas at gmail.com> wrote:
>
> On Wed, Jul 29, 2015 at 7:32 PM, Kostya Serebryany <kcc at google.com> wrote:
>
>> Author: kcc
>> Date: Wed Jul 29 21:32:51 2015
>> New Revision: 243610
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=243610&view=rev
>> Log:
>> [sanitizer] add a weak hook for strncmp interceptor, both to dfsan and
>> other sanitizers. Hide the declaration and the calls in better macros
>>
>> Modified:
>> compiler-rt/trunk/include/sanitizer/common_interface_defs.h
>> compiler-rt/trunk/include/sanitizer/dfsan_interface.h
>> compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
>>
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
>>
>> Modified: compiler-rt/trunk/include/sanitizer/common_interface_defs.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/common_interface_defs.h?rev=243610&r1=243609&r2=243610&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/include/sanitizer/common_interface_defs.h (original)
>> +++ compiler-rt/trunk/include/sanitizer/common_interface_defs.h Wed Jul
>> 29 21:32:51 2015
>> @@ -120,6 +120,8 @@ extern "C" {
>> // FIXME: implement more hooks.
>> void __sanitizer_weak_hook_memcmp(void *called_pc, const void *s1,
>> const void *s2, size_t n);
>> + void __sanitizer_weak_hook_strncmp(void *called_pc, const char *s1,
>> + const char *s2, size_t n);
>> #ifdef __cplusplus
>> } // extern "C"
>> #endif
>>
>> Modified: compiler-rt/trunk/include/sanitizer/dfsan_interface.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/dfsan_interface.h?rev=243610&r1=243609&r2=243610&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/include/sanitizer/dfsan_interface.h (original)
>> +++ compiler-rt/trunk/include/sanitizer/dfsan_interface.h Wed Jul 29
>> 21:32:51 2015
>> @@ -91,16 +91,18 @@ void dfsan_set_write_callback(dfsan_writ
>> /// <label> <parent label 1> <parent label 2> <label description if any>
>> void dfsan_dump_labels(int fd);
>>
>> +/// Interceptor hooks.
>> /// Whenever a dfsan's custom function is called the corresponding
>> /// hook is called it non-zero. The hooks should be defined by the user.
>> /// The primary use case is taint-guided fuzzing, where the fuzzer
>> /// needs to see the parameters of the function and the labels.
>> /// FIXME: implement more hooks.
>> -
>> -/// memcmp hook.
>> void dfsan_weak_hook_memcmp(void *caller_pc, const void *s1, const void
>> *s2,
>> size_t n, dfsan_label s1_label,
>> dfsan_label s2_label, dfsan_label n_label);
>> +void dfsan_weak_hook_strncmp(void *caller_pc, const char *s1, const char
>> *s2,
>> + size_t n, dfsan_label s1_label,
>> + dfsan_label s2_label, dfsan_label n_label);
>> #ifdef __cplusplus
>> } // extern "C"
>>
>>
>> Modified: compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_custom.cc?rev=243610&r1=243609&r2=243610&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/dfsan/dfsan_custom.cc (original)
>> +++ compiler-rt/trunk/lib/dfsan/dfsan_custom.cc Wed Jul 29 21:32:51 2015
>> @@ -43,6 +43,14 @@
>>
>> using namespace __dfsan;
>>
>> +#define CALL_WEAK_INTERCEPTOR_HOOK(f, ...)
>> \
>> + do {
>> \
>> + if (f)
>> \
>> + f(__VA_ARGS__);
>> \
>> + } while (false)
>> +#define DECLARE_WEAK_INTERCEPTOR_HOOK(f, ...) \
>> +SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void
>> f(__VA_ARGS__);
>> +
>> extern "C" {
>> SANITIZER_INTERFACE_ATTRIBUTE int
>> __dfsw_stat(const char *path, struct stat *buf, dfsan_label path_label,
>> @@ -82,20 +90,18 @@ SANITIZER_INTERFACE_ATTRIBUTE char *__df
>> }
>> }
>>
>> -SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
>> -void
>> -dfsan_weak_hook_memcmp(uptr caller_pc, const void *s1, const void *s2,
>> size_t n,
>> - dfsan_label s1_label, dfsan_label s2_label,
>> - dfsan_label n_label);
>> +DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_memcmp, uptr caller_pc,
>> + const void *s1, const void *s2, size_t n,
>> + dfsan_label s1_label, dfsan_label s2_label,
>> + dfsan_label n_label);
>>
>> SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_memcmp(const void *s1, const
>> void *s2,
>> size_t n, dfsan_label
>> s1_label,
>> dfsan_label s2_label,
>> dfsan_label n_label,
>> dfsan_label *ret_label) {
>> - if (dfsan_weak_hook_memcmp)
>> - dfsan_weak_hook_memcmp(GET_CALLER_PC(), s1, s2, n, s1_label,
>> s2_label,
>> - n_label);
>> + CALL_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_memcmp, GET_CALLER_PC(),
>> s1, s2, n,
>> + s1_label, s2_label, n_label);
>> const char *cs1 = (const char *) s1, *cs2 = (const char *) s2;
>> for (size_t i = 0; i != n; ++i) {
>> if (cs1[i] != cs2[i]) {
>> @@ -153,6 +159,11 @@ __dfsw_strcasecmp(const char *s1, const
>> return 0;
>> }
>>
>> +DECLARE_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_strncmp, uptr caller_pc,
>> + const char *s1, const char *s2, size_t n,
>> + dfsan_label s1_label, dfsan_label s2_label,
>> + dfsan_label n_label);
>> +
>> SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_strncmp(const char *s1, const
>> char *s2,
>> size_t n, dfsan_label
>> s1_label,
>> dfsan_label s2_label,
>> @@ -163,6 +174,9 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw
>> return 0;
>> }
>>
>> + CALL_WEAK_INTERCEPTOR_HOOK(dfsan_weak_hook_strncmp, GET_CALLER_PC(),
>> s1, s2,
>> + n, s1_label, s2_label, n_label);
>> +
>> for (size_t i = 0;; ++i) {
>> if (s1[i] != s2[i] || s1[i] == 0 || s2[i] == 0 || i == n - 1) {
>> if (flags().strict_data_dependencies) {
>>
>> Modified:
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=243610&r1=243609&r2=243610&view=diff
>>
>> ==============================================================================
>> ---
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
>> (original)
>> +++
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
>> Wed Jul 29 21:32:51 2015
>> @@ -40,13 +40,19 @@
>> #include <stdarg.h>
>>
>> #if SANITIZER_INTERCEPTOR_HOOKS
>> -#define CALL_WEAK_INTERCEPTOR_HOOK4(f, ...)
>> \
>> +#define CALL_WEAK_INTERCEPTOR_HOOK(f, ...)
>> \
>> do {
>> \
>> if (f)
>> \
>> f(__VA_ARGS__);
>> \
>> } while (false);
>> +#define DECLARE_WEAK_INTERCEPTOR_HOOK(f, ...)
>> \
>> + extern "C" {
>> \
>> + SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void
>> f(__VA_ARGS__); \
>> + } // extern "C"
>> #else
>> -#define CALL_WEAK_INTERCEPTOR_HOOK4(f, a1, a2, a3, a4)
>> +#define DECLARE_WEAK_INTERCEPTOR_HOOK(f, ...)
>> +#define CALL_WEAK_INTERCEPTOR_HOOK(f, a1, a2, a3, a4)
>> +
>> #endif // SANITIZER_INTERCEPTOR_HOOKS
>>
>> #if SANITIZER_WINDOWS && !defined(va_copy)
>> @@ -213,11 +219,16 @@ INTERCEPTOR(int, strcmp, const char *s1,
>> return CharCmpX(c1, c2);
>> }
>>
>> +DECLARE_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strncmp, uptr
>> called_pc,
>> + const char *s1, const char *s2, uptr n);
>>
>
> ^^
> You don't need a semicolon after DECLARE_WEAK_INTERCEPTOR_HOOK (here and
> in another places)
> (found by -Wpedantic).
>
>
>
>> +
>> INTERCEPTOR(int, strncmp, const char *s1, const char *s2, uptr size) {
>> if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
>> return internal_strncmp(s1, s2, size);
>> void *ctx;
>> COMMON_INTERCEPTOR_ENTER(ctx, strncmp, s1, s2, size);
>> + CALL_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strncmp,
>> GET_CALLER_PC(), s1,
>> + s2, size);
>> unsigned char c1 = 0, c2 = 0;
>> uptr i;
>> for (i = 0; i < size; i++) {
>> @@ -374,19 +385,16 @@ INTERCEPTOR(char *, strpbrk, const char
>>
>> #if SANITIZER_INTERCEPT_MEMCMP
>>
>> -extern "C" {
>> -SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
>> -void __sanitizer_weak_hook_memcmp(uptr called_pc, const void *s1,
>> - const void *s2, uptr n);
>> -} // extern "C"
>> +DECLARE_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_memcmp, uptr
>> called_pc,
>> + const void *s1, const void *s2, uptr n);
>>
>> INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {
>> void *ctx;
>> COMMON_INTERCEPTOR_ENTER(ctx, memcmp, a1, a2, size);
>> if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
>> return internal_memcmp(a1, a2, size);
>> - CALL_WEAK_INTERCEPTOR_HOOK4(__sanitizer_weak_hook_memcmp,
>> GET_CALLER_PC(), a1,
>> - a2, size);
>> + CALL_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_memcmp,
>> GET_CALLER_PC(), a1,
>> + a2, size);
>> if (common_flags()->intercept_memcmp) {
>> if (common_flags()->strict_memcmp) {
>> // Check the entire regions even if the first bytes of the buffers
>> are
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
>
> --
> Alexey Samsonov
> vonosmas at gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150730/6a78ea88/attachment.html>
More information about the llvm-commits
mailing list