From 818c97d8cea0aec27f719ff883a62831f72d709e Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 1 Feb 2021 12:51:44 +0100 Subject: [PATCH] rec: Set the start of the stack right away to avoid an ASAN issue 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pdns/mtasker.cc b/pdns/mtasker.cc index 7afc7d4012..a2c3a2fba2 100644 --- a/pdns/mtasker.cc +++ b/pdns/mtasker.cc @@ -277,6 +277,9 @@ templatevoid MTasker::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; -- 2.47.2