From 57640b83e40303ad00b696a916895a0ff59b783f Mon Sep 17 00:00:00 2001 From: Ray Essick Date: Sat, 11 Apr 2020 21:50:48 -0700 Subject: [PATCH] disable CFI on some stagefright_foundation internals The internals of AData do exactly the type casting that upsets CFI sanitizers, so disable CFI for those routines. Bug: 153739236 Test: atest sf_foundation_test Change-Id: I69ac7f064a8d3c874d7587598b450af657c4ba59 --- .../include/media/stagefright/foundation/AData.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/media/libstagefright/foundation/include/media/stagefright/foundation/AData.h b/media/libstagefright/foundation/include/media/stagefright/foundation/AData.h index c6c12ff5c2..87cf58b54a 100644 --- a/media/libstagefright/foundation/include/media/stagefright/foundation/AData.h +++ b/media/libstagefright/foundation/include/media/stagefright/foundation/AData.h @@ -28,6 +28,10 @@ #undef HIDE #define HIDE __attribute__((visibility("hidden"))) +// The internals of AUnion cause problems with CFI +#undef NO_CFI +#define NO_CFI __attribute__((no_sanitize("cfi"))) + namespace android { /** @@ -93,7 +97,7 @@ struct HIDE _AUnion_impl { * \param args arbitrary arguments for constructor */ template - inline static void emplace(size_t totalSize, T *addr, Args&&... args) { + inline static void NO_CFI emplace(size_t totalSize, T *addr, Args&&... args) { new(addr)T(std::forward(args)...); // clear slack space - this is not technically required constexpr size_t size = sizeof(T); @@ -160,7 +164,7 @@ public: template< typename T, typename ...Args, typename=typename std::enable_if::value>::type> - inline void emplace(Args&&... args) { + inline void NO_CFI emplace(Args&&... args) { _AUnion_impl::emplace( sizeof(_type), reinterpret_cast(&mValue), std::forward(args)...); }