The plugin header declares pointer global variables in plugins meant to
be placed contiguously within their own sections, and then used as an
array of pointers when loading the plugin.
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: #1231
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I5488d61a7d714e6525a3a623d303c5fd30b76bc2
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3102
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
}; \
static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_component_class_id##_##_attr_name##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_component_class_id##_##_attr_name
}; \
static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_component_class_id##_##_attr_name##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_component_class_id##_##_attr_name
+/*
+ * 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. This is fine because, as far as we have seen, gcc
+ * does not insert red zones around global variables.
+ */
+#if defined(__clang__)
+# if __has_feature(address_sanitizer)
+# define __bt_plugin_variable_attribute_no_sanitize_address \
+ __attribute__((no_sanitize("address")))
+# else
+# define __bt_plugin_variable_attribute_no_sanitize_address
+# endif
+#else
+# define __bt_plugin_variable_attribute_no_sanitize_address
+#endif
+
/*
* Variable attributes for a plugin descriptor pointer to be added to
* the plugin descriptor section (internal use).
*/
#ifdef __APPLE__
#define __BT_PLUGIN_DESCRIPTOR_ATTRS \
/*
* Variable attributes for a plugin descriptor pointer to be added to
* the plugin descriptor section (internal use).
*/
#ifdef __APPLE__
#define __BT_PLUGIN_DESCRIPTOR_ATTRS \
- __attribute__((section("__DATA,btp_desc"), used))
+ __attribute__((section("__DATA,btp_desc"), used)) \
+ __bt_plugin_variable_attribute_no_sanitize_address
#define __BT_PLUGIN_DESCRIPTOR_BEGIN_SYMBOL \
__start___bt_plugin_descriptors
#define __BT_PLUGIN_DESCRIPTOR_BEGIN_SYMBOL \
__start___bt_plugin_descriptors
#else
#define __BT_PLUGIN_DESCRIPTOR_ATTRS \
#else
#define __BT_PLUGIN_DESCRIPTOR_ATTRS \
- __attribute__((section("__bt_plugin_descriptors"), used))
+ __attribute__((section("__bt_plugin_descriptors"), used)) \
+ __bt_plugin_variable_attribute_no_sanitize_address
#define __BT_PLUGIN_DESCRIPTOR_BEGIN_SYMBOL \
__start___bt_plugin_descriptors
#define __BT_PLUGIN_DESCRIPTOR_BEGIN_SYMBOL \
__start___bt_plugin_descriptors
*/
#ifdef __APPLE__
#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS \
*/
#ifdef __APPLE__
#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS \
- __attribute__((section("__DATA,btp_desc_att"), used))
+ __attribute__((section("__DATA,btp_desc_att"), used)) \
+ __bt_plugin_variable_attribute_no_sanitize_address
#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \
__start___bt_plugin_descriptor_attributes
#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \
__start___bt_plugin_descriptor_attributes
#else
#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS \
#else
#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_ATTRS \
- __attribute__((section("__bt_plugin_descriptor_attributes"), used))
+ __attribute__((section("__bt_plugin_descriptor_attributes"), used)) \
+ __bt_plugin_variable_attribute_no_sanitize_address
#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \
__start___bt_plugin_descriptor_attributes
#define __BT_PLUGIN_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \
__start___bt_plugin_descriptor_attributes
*/
#ifdef __APPLE__
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS \
*/
#ifdef __APPLE__
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS \
- __attribute__((section("__DATA,btp_cc_desc"), used))
+ __attribute__((section("__DATA,btp_cc_desc"), used)) \
+ __bt_plugin_variable_attribute_no_sanitize_address
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_SYMBOL \
__start___bt_plugin_component_class_descriptors
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_SYMBOL \
__start___bt_plugin_component_class_descriptors
#else
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS \
#else
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS \
- __attribute__((section("__bt_plugin_component_class_descriptors"), used))
+ __attribute__((section("__bt_plugin_component_class_descriptors"), used)) \
+ __bt_plugin_variable_attribute_no_sanitize_address
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_SYMBOL \
__start___bt_plugin_component_class_descriptors
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_BEGIN_SYMBOL \
__start___bt_plugin_component_class_descriptors
*/
#ifdef __APPLE__
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS \
*/
#ifdef __APPLE__
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS \
- __attribute__((section("__DATA,btp_cc_desc_att"), used))
+ __attribute__((section("__DATA,btp_cc_desc_att"), used)) \
+ __bt_plugin_variable_attribute_no_sanitize_address
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \
__start___bt_plugin_component_class_descriptor_attributes
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \
__start___bt_plugin_component_class_descriptor_attributes
#else
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS \
#else
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS \
- __attribute__((section("__bt_plugin_component_class_descriptor_attributes"), used))
+ __attribute__((section("__bt_plugin_component_class_descriptor_attributes"), used)) \
+ __bt_plugin_variable_attribute_no_sanitize_address
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \
__start___bt_plugin_component_class_descriptor_attributes
#define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_BEGIN_SYMBOL \
__start___bt_plugin_component_class_descriptor_attributes