[MDEV-15030] Add ASAN instrumentation Created: 2018-01-22 Updated: 2018-09-21 Resolved: 2018-04-24 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Debug |
| Fix Version/s: | 10.2.15, 10.3.7 |
| Type: | Task | Priority: | Major |
| Reporter: | Sergey Vojtovich | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | contribution, foundation | ||
| Attachments: |
|
||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||
| Description |
|
Instrument MEM_ROOT and mem_heap_t. Safe malloc disabled for WITH_ASAN=ON. With this patch ASAN is able to catch eg this bug Also remove unneeded header inclusions. |
| Comments |
| Comment by Sergei Golubchik [ 2018-01-22 ] | |||||||||
|
Mostly already implemented with these commits:
Works with safemalloc just fine. | |||||||||
| Comment by Marko Mäkelä [ 2018-01-22 ] | |||||||||
|
MDEV-15030-Pool.patch I hope kevg can submit a revised pull request to instrument mem_heap_t in 5.5. | |||||||||
| Comment by Eugene Kosov (Inactive) [ 2018-01-22 ] | |||||||||
|
As I can see from source code safemalloc does the following: 1) is a standard requirement for malloc(), ASAN catches it ASAN is superior to safemalloc. I suggest to disable safemalloc in ASAN build because it only brings slowdown which is not good if one want's to run the whole test suite. | |||||||||
| Comment by Eugene Kosov (Inactive) [ 2018-01-22 ] | |||||||||
|
For ASAN TRASH_ALLOC() should be something like this
Here we make memory region accessible and fill it with constant date for gdb user. But for valgrind it is
Filling data and make it write-only. For ASAN TRASH_FREE() should be something like this:
No need to fill it with some data because every access will be caught regardless of this. Also, current code unpoisons, fills and poisons memory region. And this prevent ASAN from catching double free. MEM_UNDEFINED unpoisons memory, i.e. makes it correct. This is counter-intuitive, IMO. And that's why TRASH_ALLOC, TRASH_FREE macros ideally should be different for valgrind and ASAN. | |||||||||
| Comment by Eugene Kosov (Inactive) [ 2018-01-22 ] | |||||||||
|
Btw, the most efficient way for catching memory bugs would be disabling memory arenas completely. That would result in the best instrumentation out of the box. But sadly it's not possible with current code which never calls dummy free()/delete for arena allocations. | |||||||||
| Comment by Sergei Golubchik [ 2018-01-22 ] | |||||||||
|
features must be auto-disabled, if they don't work together. ASAN and safemalloc do. If you want ASAN without safemalloc, you do -DWITH_ASAN=ON -DWITH_SAFEMALLOC=OFF. TRASH_FILL() starts from MEM_UNDEFINED(), so TRASH_ALLOC is Same for TRASH_FREE. And if you want it to be just MEM_NOACCESS, you compile without debugging but with ASAN. | |||||||||
| Comment by Eugene Kosov (Inactive) [ 2018-01-22 ] | |||||||||
|
Well, it's a bit coarse-grained. Here is the PR https://github.com/MariaDB/server/pull/569 | |||||||||
| Comment by Marko Mäkelä [ 2018-01-23 ] | |||||||||
|
kevg, sorry, I did not realize that you had updated your contribution last night. What remains to be done (once the code has been merged from 5.5 up to 10.2) is to add the address range poisoning to the transaction Pool. I believe that it should work with both ASAN and Valgrind. | |||||||||
| Comment by Marko Mäkelä [ 2018-04-24 ] | |||||||||
|
I added poisoning to the Pool of trx_t, which was introduced via MySQL 5.7 to MariaDB 10.2.2. This revealed that innodb_monitor is accessing trx_t::mutex and trx_t::undo_mutex even for freed trx_t objects. |