From: Remi Gacogne Date: Mon, 1 Feb 2021 11:51:44 +0000 (+0100) Subject: rec: Set the start of the stack right away to avoid an ASAN issue X-Git-Tag: dnsdist-1.6.0-alpha2~60^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10036%2Fhead;p=thirdparty%2Fpdns.git 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. --- 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;