]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Set the start of the stack right away to avoid an ASAN issue 10036/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 1 Feb 2021 11:51:44 +0000 (12:51 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 1 Feb 2021 11:51:44 +0000 (12:51 +0100)
We used to wait until the first invocation of a MTask to set the
start of the stack, but that sometimes resulted in passing the nullptr
address to ASAN when calling a task for the first time.
It resulted in ASAN skipping the stack switch, logging something like:
```
WARNING: ASan is ignoring requested __asan_handle_no_return: stack top: 0x000000020000; bottom 0x7f18f174a000; size: 0xffff80e70e8d6000 (-139745106763776)
False positive error reports may follow
```
Then almost right away complaining about a stack-use-after-scope,
or a stack-based overflow.

This changes sets the end of the memory allocation before the first
invocation, so that we always notify a valid value. A closer
approximation is still set during the first invocation, as before.

pdns/mtasker.cc

index 7afc7d4012b2d7f01aeda2dc432061766624bcf1..a2c3a2fba2679a692aeefa4dee242e521c2b882e 100644 (file)
@@ -277,6 +277,9 @@ template<class Key, class Val>void MTasker<Key,Val>::makeThread(tfunc_t *start,
   ++d_threadsCount;
   auto& thread = d_threads[d_maxtid];
   auto mt = this;
+  // we will get a better approximation when the task is executed, but that prevents notifying a stack at nullptr
+  // on the first invocation
+  d_threads[d_maxtid].startOfStack = &uc->uc_stack[uc->uc_stack.size()-1];
   thread.start = [start, val, mt]() {
       char dummy;
       mt->d_threads[mt->d_tid].startOfStack = mt->d_threads[mt->d_tid].highestStackSeen = &dummy;