Skip to content

Commit

Permalink
[trace] Avoid UB passing stack garbage
Browse files Browse the repository at this point in the history
```
../../zircon/system/utest/trace/event_tests_common.h:105:3: runtime error: load of value 170, which is not a valid value for type 'bool'
   #0    0x00004010760a3204 in event_tests_c_test_enabled_fn() ../../zircon/system/utest/trace/event_tests_common.h:105 <<application>>+0xdc204
   #1.2  0x000041717c6473c0 in ubsan_GetStackTrace() compiler-rt/lib/ubsan/ubsan_diag.cpp:43 <libclang_rt.asan.so>+0x363c0
   #1.1  0x000041717c6473c0 in MaybePrintStackTrace() compiler-rt/lib/ubsan/ubsan_diag.cpp:53 <libclang_rt.asan.so>+0x363c0
   #1    0x000041717c6473c0 in ~ScopedReport() compiler-rt/lib/ubsan/ubsan_diag.cpp:389 <libclang_rt.asan.so>+0x363c0
   #2    0x000041717c6497c0 in handleLoadInvalidValue() compiler-rt/lib/ubsan/ubsan_handlers.cpp:540 <libclang_rt.asan.so>+0x387c0
   #3    0x000041717c649680 in compiler-rt/lib/ubsan/ubsan_handlers.cpp:545 <libclang_rt.asan.so>+0x38680
   #4    0x00004010760a3204 in event_tests_c_test_enabled_fn() ../../zircon/system/utest/trace/event_tests_common.h:105 <<application>>+0xdc204
```

Fixed: 41900
Change-Id: I09582b4139b866fc56aefede4c4553f3bbb6fcc2
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/574301
Commit-Queue: Auto-Submit <[email protected]>
Fuchsia-Auto-Submit: Tamir Duberstein <[email protected]>
Reviewed-by: Fadi Meawad <[email protected]>
  • Loading branch information
tamird authored and CQ Bot committed Aug 27, 2021
1 parent 679c851 commit 19e9738
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/lib/trace/rust/test/fixture_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#pragma once
#ifndef SRC_LIB_TRACE_RUST_TEST_FIXTURE_MACROS_H_
#define SRC_LIB_TRACE_RUST_TEST_FIXTURE_MACROS_H_

#include <trace-test-utils/fixture.h>
#include <zxtest/zxtest.h>
Expand All @@ -17,13 +18,14 @@
#define DEFAULT_BUFFER_SIZE_BYTES (1024u * 1024u)

// This isn't a do-while because of the cleanup.
#define BEGIN_TRACE_TEST_ETC(attach_to_thread, mode, buffer_size) \
__attribute__((cleanup(fixture_scope_cleanup))) bool __scope; \
(void)__scope; \
#define BEGIN_TRACE_TEST_ETC(attach_to_thread, mode, buffer_size) \
__attribute__((cleanup(fixture_scope_cleanup))) bool __scope = 0; \
(void)__scope; \
fixture_set_up((attach_to_thread), (mode), (buffer_size))

#define BEGIN_TRACE_TEST \
BEGIN_TRACE_TEST_ETC(kAttachToThread, TRACE_BUFFERING_MODE_ONESHOT, DEFAULT_BUFFER_SIZE_BYTES)

#define ASSERT_RECORDS(expected) \
ASSERT_TRUE(fixture_compare_records(expected), "record mismatch")
#define ASSERT_RECORDS(expected) ASSERT_TRUE(fixture_compare_records(expected), "record mismatch")

#endif // SRC_LIB_TRACE_RUST_TEST_FIXTURE_MACROS_H_
4 changes: 0 additions & 4 deletions zircon/system/utest/trace/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ source_set("common") {
# Otherwise they silently fail (output is dropped).
"//sdk/lib/fdio",
]

# TODO(fxbug.dev/41900): UBSan has found an instance of undefined behavior in this target.
# Disable UBSan for this target temporarily until it is migrated into CI/CQ.
configs += [ "//build/config:temporarily_disable_ubsan_do_not_use" ]
}

# Version of test that uses libtrace-engine.so.
Expand Down
11 changes: 7 additions & 4 deletions zircon/system/utest/trace/fixture_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#pragma once
#ifndef ZIRCON_SYSTEM_UTEST_TRACE_FIXTURE_MACROS_H_
#define ZIRCON_SYSTEM_UTEST_TRACE_FIXTURE_MACROS_H_

#include <trace-test-utils/fixture.h>
#include <zxtest/zxtest.h>

#define DEFAULT_BUFFER_SIZE_BYTES (1024u * 1024u)

// This isn't a do-while because of the cleanup.
#define BEGIN_TRACE_TEST_ETC(attach_to_thread, mode, buffer_size) \
__attribute__((cleanup(fixture_scope_cleanup))) bool __scope; \
(void)__scope; \
#define BEGIN_TRACE_TEST_ETC(attach_to_thread, mode, buffer_size) \
__attribute__((cleanup(fixture_scope_cleanup))) bool __scope = 0; \
(void)__scope; \
fixture_set_up((attach_to_thread), (mode), (buffer_size))

#define BEGIN_TRACE_TEST \
Expand Down Expand Up @@ -45,3 +46,5 @@
#endif

#endif // NTRACE

#endif // ZIRCON_SYSTEM_UTEST_TRACE_FIXTURE_MACROS_H_

0 comments on commit 19e9738

Please sign in to comment.