Fix: tracepoint.h: Disable address sanitizer on pointer array section variables
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 18 Feb 2020 00:25:01 +0000 (19:25 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 18 Feb 2020 01:19:49 +0000 (20:19 -0500)
The tracepoint header declares pointer global variables meant to be
placed contiguously within the __tracepoints_ptrs section, and then used
as an array of pointers when loading an executable or shared object.

Clang Address Sanitizer adds redzones around each variable, thus leading to
detection of a global buffer overflow.

Those redzones should not be placed within this section, because it
defeats its purpose. Therefore, teach asan not to add redzones
around those variables with an attribute.

Note that there does not appear to be any issue with gcc (tested with
gcc-8 with address sanitization enabled), and gcc ignores the
no_sanitize_address attribute when applied to a global variable.

Fixes: #1238
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/tracepoint.h
include/lttng/ust-compiler.h

index a91faa42c475bc0c34a16fcc5f65eb22bb401f7b..7cfae3e4c10cd65c557a525fdbee063cd6d23c53 100644 (file)
@@ -441,7 +441,8 @@ extern struct lttng_ust_tracepoint * const __stop___tracepoints_ptrs[]
                };                                                              \
        static struct lttng_ust_tracepoint *                                    \
                __tracepoint_ptr_##_provider##___##_name                        \
-               __attribute__((used, section("__tracepoints_ptrs"))) =          \
+               __attribute__((section("__tracepoints_ptrs"), used))            \
+               __lttng_ust_variable_attribute_no_sanitize_address =            \
                        &__tracepoint_##_provider##___##_name;
 
 static void lttng_ust_notrace __attribute__((constructor))
index 1d04da1ac39857a6d35533794e7341fefb99ce4d..31eaf73c0139026b9adbb8c87ca7076c0df77125 100644 (file)
 #define lttng_ust_notrace __attribute__((no_instrument_function))
 #define LTTNG_PACKED   __attribute__((__packed__))
 
+/*
+ * Clang supports the no_sanitize variable attribute on global variables.
+ * GCC only supports the no_sanitize_address function attribute, which is
+ * not what we need.
+ */
+#if defined(__clang__)
+# if __has_feature(address_sanitizer)
+#  define __lttng_ust_variable_attribute_no_sanitize_address \
+       __attribute__((no_sanitize("address")))
+# else
+#  define __lttng_ust_variable_attribute_no_sanitize_address
+# endif
+#else
+#  define __lttng_ust_variable_attribute_no_sanitize_address
+#endif
+
 #endif /* _LTTNG_UST_COMPILER_H */
This page took 0.034986 seconds and 4 git commands to generate.