[MDEV-17799] Add ASAN-poisoned redzones for MEM_ROOT Created: 2018-11-22  Updated: 2023-04-27

Status: Stalled
Project: MariaDB Server
Component/s: None
Fix Version/s: 10.4

Type: Task Priority: Major
Reporter: Eugene Kosov (Inactive) Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-19471 Add ASAN-poisoned redzones for mem_he... Closed

 Description   

Redzones are poisoned memory between all allocations from memory heaps. It uses more memory but catches buffer overflow and underflow.

Actually redzones could present if requested size is not a multiply of 8, because allocations size is aligned by 8. Obviously, it's not guaranteed.

As a bonus string-like and vector-like containers could be instrumented too. See here for example https://github.com/llvm-mirror/libcxx/blob/ab883e8c3b9fb281e5fe064784951c5addd5d11c/include/vector#L846



 Comments   
Comment by Eugene Kosov (Inactive) [ 2018-11-27 ]

Consider a test case:

heap_t heap;
my_class_t *c = NULL;
{
  c = new (heap) my_class_t();
  c->use();
  c->cleanup();
  // delete (heap) c;
}
c->use();

ASAN should bark on second c->use() but in general it won't because heap memory won't freed. It's partially solved with Sql_alloc but for classes only and not for stuff like THD::make_clex_string(). And it doesn't work at all for mem_heap_t.

We may store size_t with allocation length right before allocated chunk. This will serve as a redzone too.

dealloc_root() and mem_heap_dealloc() can be added. They will read allocated size from redzone and poison freed chunk. No real memory freeing.

This is simple to add but to make it really work those functions should be added to a lot of places in code. Like manual allocation pairs malloc()/free(). But I think one goal was to not call free() on every allocated chunk. Anyway, this is a C style.

C++ style is to create (in terms of C++17) a memory resources with will actually own memory. Examples are bulk allocator, thread-safe bulk allocator, static storage + heap. And allocator is a handler (pointer) to that resource. In that case poisoning of deallocated memory will happen in allocator_t::deallocate().

Comment by Marko Mäkelä [ 2019-02-26 ]

kevg, is this still applicable after MDEV-17797 got fixed?

Comment by Eugene Kosov (Inactive) [ 2019-02-27 ]

marko, yes. I even have a PR for this: https://github.com/MariaDB/server/pull/954
One more patch is needed for InnoDB.

Generated at Thu Feb 08 08:39:12 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.