Skip to content
Permalink
Browse files
MDEV-16136 Various ASAN failures after MDEV-15030
The Pool poisoning that was introduced in MDEV-15030 introduced
race conditions in AddressSanitizer builds, because concurrent
poisoning and unpoisoning were not prevented by any synchronization
primitive.

Pool::get(): Protect the unpoisoning by m_lock_strategy.

Pool::mem_free(): Protect the poisoning by m_lock_strategy.

Pool::putl(): Renamed from put(), because now the caller is
responsible for invoking m_lock_strategy.
  • Loading branch information
dr-m committed Aug 16, 2018
1 parent fa2a74e commit a0ce321
Showing 1 changed file with 10 additions and 10 deletions.
@@ -125,8 +125,7 @@ struct Pool {
elem = NULL;
}

m_lock_strategy.exit();

#if defined HAVE_valgrind || defined __SANITIZE_ADDRESS__
if (elem) {
/* Unpoison the memory for AddressSanitizer */
MEM_UNDEFINED(&elem->m_type, sizeof elem->m_type);
@@ -135,10 +134,11 @@ struct Pool {
actually initialized; we checked that by
UNIV_MEM_ASSERT_RW() in mem_free() below. */
UNIV_MEM_VALID(&elem->m_type, sizeof elem->m_type);
return &elem->m_type;
}
#endif

return NULL;
m_lock_strategy.exit();
return elem ? &elem->m_type : NULL;
}

/** Add the object to the pool.
@@ -151,8 +151,12 @@ struct Pool {
elem = reinterpret_cast<Element*>(p - sizeof(*elem));
UNIV_MEM_ASSERT_RW(&elem->m_type, sizeof elem->m_type);

elem->m_pool->put(elem);
elem->m_pool->m_lock_strategy.enter();

elem->m_pool->putl(elem);
MEM_NOACCESS(&elem->m_type, sizeof elem->m_type);

elem->m_pool->m_lock_strategy.exit();
}

protected:
@@ -170,17 +174,13 @@ struct Pool {

/** Release the object to the free pool
@param elem element to free */
void put(Element* elem)
void putl(Element* elem)
{
m_lock_strategy.enter();

ut_ad(elem >= m_start && elem < m_last);

ut_ad(Factory::debug(&elem->m_type));

m_pqueue.push(elem);

m_lock_strategy.exit();
}

/** Initialise the elements.

0 comments on commit a0ce321

Please sign in to comment.