MDEV-36962 innodb.log_file_overwrite fails with ASAN

Problem:
=======
- InnoDB unpoisons the freed page memory to make sure that
no other thread uses this freed page. In buf_pool_t::close(),
InnoDB unmap() the buffer pool memory during shutdown or it
encountered during startup. Later at some point, server
re-uses the same virtual address using mmap() and writes into
memory region. This leads to use_after_poison error.

This issue doesn't happen in latest clang and gcc version.
Older version of clang and gcc can still fail with this error.
ASAN should unpoison the memory while reusing the same virtual
address. This issue was already raised in
https://github.com/google/sanitizers/issues/1705

Fix:
===
In order to avoid this failure, let's unpoison the buffer
pool memory explictly during buf_pool_t::close() for
lesser than gcc-14 and clang-18 version.
This commit is contained in:
Thirunarayanan Balathandayuthapani 2025-06-17 14:36:30 +05:30 committed by Daniel Black
commit 4be442ec35

View file

@ -1514,6 +1514,27 @@ void buf_pool_t::close() noexcept
{
const size_t size{size_in_bytes};
#ifdef __SANITIZE_ADDRESS__
/* Sequence of operation which leads to use_after_poison error:
mmap();
__asan_poison_memory_region();
munmap();
mmap() reuses the same virtual address
Write into the memory region throws the error.
Recent clang-18, gcc-13.3 doesn't detect this error.
Older like clang-14..clang-16 and gcc-10, gcc-11, gcc-12 detects
this error. Please check the reported bug
(https://github.com/google/sanitizers/issues/1705)
Unpoison the whole buffer pool memory to avoid this error */
#if (defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 14)) ||\
(defined(__clang__) && (__clang_major__ < 18))
MEM_MAKE_ADDRESSABLE(memory, size);
#endif /* __GNUC__ __clang */
#endif /* __SANITIZE_ADDRESS__ */
for (char *extent= memory,
*end= memory + block_descriptors_in_bytes(n_blocks);
extent < end; extent+= innodb_buffer_pool_extent_size)