Commit 9b139cb4 authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot 6

`detail::Futex` wants 4 bytes but MicroLock only gives you one

Summary: ^^^ this is a stack overflow in the test, and a possible stack or heap overflow.

Reviewed By: dcolascione

Differential Revision: D3151717

fb-gh-sync-id: b4f0660ebbb89139dff003870e132c312068d9a8
fbshipit-source-id: b4f0660ebbb89139dff003870e132c312068d9a8
parent 1fb83fbc
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
#include <folly/detail/Futex.h> #include <folly/detail/Futex.h>
#include <folly/Portability.h> #include <folly/Portability.h>
#if defined(__clang__)
#define NO_SANITIZE_ADDRESS __attribute__((__no_sanitize__("address")))
#else
#define NO_SANITIZE_ADDRESS
#endif
namespace folly { namespace folly {
/** /**
...@@ -88,7 +94,12 @@ namespace folly { ...@@ -88,7 +94,12 @@ namespace folly {
class MicroLockCore { class MicroLockCore {
protected: protected:
#if defined(__SANITIZE_ADDRESS__) && !defined(__clang__) && \
(defined(__GNUC__) || defined(__GNUG__))
uint32_t lock_;
#else
uint8_t lock_; uint8_t lock_;
#endif
inline detail::Futex<>* word() const; inline detail::Futex<>* word() const;
inline uint32_t baseShift(unsigned slot) const; inline uint32_t baseShift(unsigned slot) const;
inline uint32_t heldBit(unsigned slot) const; inline uint32_t heldBit(unsigned slot) const;
...@@ -100,7 +111,7 @@ class MicroLockCore { ...@@ -100,7 +111,7 @@ class MicroLockCore {
unsigned maxYields); unsigned maxYields);
public: public:
inline void unlock(unsigned slot); inline void unlock(unsigned slot) NO_SANITIZE_ADDRESS;
inline void unlock() { unlock(0); } inline void unlock() { unlock(0); }
// Initializes all the slots. // Initializes all the slots.
inline void init() { lock_ = 0; } inline void init() { lock_ = 0; }
...@@ -151,9 +162,9 @@ void MicroLockCore::unlock(unsigned slot) { ...@@ -151,9 +162,9 @@ void MicroLockCore::unlock(unsigned slot) {
template <unsigned MaxSpins = 1000, unsigned MaxYields = 0> template <unsigned MaxSpins = 1000, unsigned MaxYields = 0>
class MicroLockBase : public MicroLockCore { class MicroLockBase : public MicroLockCore {
public: public:
inline void lock(unsigned slot); inline void lock(unsigned slot) NO_SANITIZE_ADDRESS;
inline void lock() { lock(0); } inline void lock() { lock(0); }
inline bool try_lock(unsigned slot); inline bool try_lock(unsigned slot) NO_SANITIZE_ADDRESS;
inline bool try_lock() { return try_lock(0); } inline bool try_lock() { return try_lock(0); }
}; };
......
...@@ -181,7 +181,12 @@ TEST(SmallLocks, RegClobber) { ...@@ -181,7 +181,12 @@ TEST(SmallLocks, RegClobber) {
} }
FOLLY_PACK_PUSH FOLLY_PACK_PUSH
#if defined(__SANITIZE_ADDRESS__) && !defined(__clang__) && \
(defined(__GNUC__) || defined(__GNUG__))
static_assert(sizeof(MicroLock) == 4, "Size check failed");
#else
static_assert(sizeof(MicroLock) == 1, "Size check failed"); static_assert(sizeof(MicroLock) == 1, "Size check failed");
#endif
FOLLY_PACK_POP FOLLY_PACK_POP
namespace { namespace {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment