<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64539>64539</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
koteswararao18
</td>
</tr>
</table>
<pre>
Hi,
passed -fsanitize=address to clang-14 compiler for below simple c program. but noticed failure in execution of program with error given below.
prog.c
{{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[]) {
char *s = malloc(15);
strcpy(s, "Hello world!");
printf("string is: %s\n", s);
free(s);
return 0;
}
}}
#clang-14 prog.c -o prog -fsanitize=address -O1 -fno-omit-frame-pointer -g
:/# ./prog
==3819930==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
==3819930==Process memory map follows:
0x000000400000-0x00000041f000 /prog
0x00000041f000-0x000000513000 /prog
0x000000513000-0x000000546000 /prog
0x000000547000-0x000000548000 /prog
0x000000548000-0x00000054b000 /prog
0x00000054b000-0x000000e9f000
0x00007fff7000-0x00008fff7000
0x00008fff7000-0x02008fff7000
0x02008fff7000-0x10007fff8000
0x7f7e86d00000-0x7f7e86e00000
0x7f7e86f00000-0x7f7e87000000
0x7f7e87100000-0x7f7e87200000
0x7f7e87300000-0x7f7e87400000
0x7f7e874c1000-0x7f7e8786b000
0x7f7e8786b000-0x7f7e87890000 /lib/x86_64-linux-gnu/libc-2.31.so
0x7f7e87890000-0x7f7e879db000 /lib/x86_64-linux-gnu/libc-2.31.so
0x7f7e879db000-0x7f7e87a25000 /lib/x86_64-linux-gnu/libc-2.31.so
0x7f7e87a25000-0x7f7e87a26000 /lib/x86_64-linux-gnu/libc-2.31.so
0x7f7e87a26000-0x7f7e87a29000 /lib/x86_64-linux-gnu/libc-2.31.so
0x7f7e87a29000-0x7f7e87a2c000 /lib/x86_64-linux-gnu/libc-2.31.so
0x7f7e87a2c000-0x7f7e87a30000
0x7f7e87a30000-0x7f7e87a33000 /lib/x86_64-linux-gnu/libgcc_s.so.1
0x7f7e87a33000-0x7f7e87a44000 /lib/x86_64-linux-gnu/libgcc_s.so.1
0x7f7e87a44000-0x7f7e87a48000 /lib/x86_64-linux-gnu/libgcc_s.so.1
0x7f7e87a48000-0x7f7e87a49000 /lib/x86_64-linux-gnu/libgcc_s.so.1
0x7f7e87a49000-0x7f7e87a4a000 /lib/x86_64-linux-gnu/libgcc_s.so.1
0x7f7e87a4a000-0x7f7e87a4b000 /lib/x86_64-linux-gnu/libdl-2.31.so
0x7f7e87a4b000-0x7f7e87a4d000 /lib/x86_64-linux-gnu/libdl-2.31.so
0x7f7e87a4d000-0x7f7e87a4e000 /lib/x86_64-linux-gnu/libdl-2.31.so
0x7f7e87a4e000-0x7f7e87a4f000 /lib/x86_64-linux-gnu/libdl-2.31.so
0x7f7e87a4f000-0x7f7e87a50000 /lib/x86_64-linux-gnu/libdl-2.31.so
0x7f7e87a50000-0x7f7e87a5f000 /lib/x86_64-linux-gnu/libm-2.31.so
0x7f7e87a5f000-0x7f7e87af9000 /lib/x86_64-linux-gnu/libm-2.31.so
0x7f7e87af9000-0x7f7e87b92000 /lib/x86_64-linux-gnu/libm-2.31.so
0x7f7e87b92000-0x7f7e87b93000 /lib/x86_64-linux-gnu/libm-2.31.so
0x7f7e87b93000-0x7f7e87b94000 /lib/x86_64-linux-gnu/libm-2.31.so
0x7f7e87b94000-0x7f7e87b97000 /lib/x86_64-linux-gnu/librt-2.31.so
0x7f7e87b97000-0x7f7e87b9b000 /lib/x86_64-linux-gnu/librt-2.31.so
0x7f7e87b9b000-0x7f7e87b9c000 /lib/x86_64-linux-gnu/librt-2.31.so
0x7f7e87b9c000-0x7f7e87b9d000 /lib/x86_64-linux-gnu/librt-2.31.so
0x7f7e87b9d000-0x7f7e87b9e000 /lib/x86_64-linux-gnu/librt-2.31.so
0x7f7e87b9e000-0x7f7e87b9f000 /lib/x86_64-linux-gnu/librt-2.31.so
0x7f7e87b9f000-0x7f7e87ba6000 /lib/x86_64-linux-gnu/libpthread-2.31.so
0x7f7e87ba6000-0x7f7e87bb6000 /lib/x86_64-linux-gnu/libpthread-2.31.so
0x7f7e87bb6000-0x7f7e87bbb000 /lib/x86_64-linux-gnu/libpthread-2.31.so
0x7f7e87bbb000-0x7f7e87bbc000 /lib/x86_64-linux-gnu/libpthread-2.31.so
0x7f7e87bbc000-0x7f7e87bbd000 /lib/x86_64-linux-gnu/libpthread-2.31.so
0x7f7e87bbd000-0x7f7e87bc5000
0x7f7e87bc5000-0x7f7e87bc9000
0x7f7e87bc9000-0x7f7e87bca000 /lib/x86_64-linux-gnu/ld-2.31.so
0x7f7e87bca000-0x7f7e87bea000 /lib/x86_64-linux-gnu/ld-2.31.so
0x7f7e87bea000-0x7f7e87bf2000 /lib/x86_64-linux-gnu/ld-2.31.so
0x7f7e87bf2000-0x7f7e87bf3000
0x7f7e87bf3000-0x7f7e87bf4000 /lib/x86_64-linux-gnu/ld-2.31.so
0x7f7e87bf4000-0x7f7e87bf5000 /lib/x86_64-linux-gnu/ld-2.31.so
0x7f7e87bf5000-0x7f7e87bf6000
0x7fff609b3000-0x7fff609d4000 [stack]
0x7fff609e8000-0x7fff609ec000 [vvar]
0x7fff609ec000-0x7fff609ee000 [vdso]
0xffffffffff600000-0xffffffffff601000 [vsyscall]
==3819930==End of process memory map.
AddressSanitizer: CHECK failed: sanitizer_common.cpp:53 "((0 && "unable to mmap")) != (0)" (0x0, 0x0) (tid=3819930)
<empty stack>
}}
earlier proposed below patch as fix for above issue but it seems not working as clang-14 compiler-rt package includes below commit .
{{
commit 82150606fb11d28813ae6da1101f5bda638165fe
Author: Vitaly Buka <[vitalybuka@google.com](mailto:vitalybuka@google.com)>
Date: Fri Apr 16 09:50:24 2021 -0700
Sanitizer built against glibc 2.34 doesn’t work
As mentioned in [100114 – libasan built against latest glibc doesn't work](https://gcc.gnu.org/PR100114) , glibc starting with the
https://sourceware.org/git/?p=glibc.git;a=commit;h=6c57d320484988e87e446e2e60ce42816bf51d53
change doesn’t define SIGSTKSZ and MINSIGSTKSZ macros to constants, but to sysconf function call.
sanitizer_posix_libcdep.cpp has
static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
which is generally fine, just means that when SIGSTKSZ is not a compile time constant will be initialized later.
The problem is that kAltStackSize is used in SetAlternateSignalStack which is called very early, from .preinit_array
initialization, i.e. far before file scope variables are constructed, which means it is not initialized and
mmapping 0 will fail:
==145==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
Here is one possible fix, another one could be to make kAltStackSize a preprocessor macro if _SG_SIGSTKSZ is defined
(but perhaps with having an automatic const variable initialized to it so that sysconf isn’t at least called twice
during SetAlternateSignalStack.
Reviewed By: vitalybuka
Differential Revision: [⚙ D100645 Sanitizer built against glibc 2.34 doesn't work](https://reviews.llvm.org/D100645)
}}
Any insights in to the issue please let me know.
}}
rgds
koti
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWUtv4zjy_zTMpWBDoh6WDjk4cWd6MPj_Z9AZ7GEvAUUVZU4kUiCpPPrTLyjZjphOYh2MXSNwRLHqx3qXXGLWykYhXpPshmS7Kza4vTbXj9qhfWaGGabj4qrS9ev1d0noLYl2JNpO3z2zFmtYCcuUdPInkmTH6tqgteA08JapZhWnwHXXyxYNCG2gwlY_g5Vd3yJw6I1uDOvWANXgQGknOdYgmGwHgyAV4AvywUmtQIsjNTxLtwc0Rhto5BOqCXU9iTVSrflB0s2N_5uuaSIVb4cagSS31tVSr_ck-fbJbiurL7aNVM18e_yWykHHpCK08JfMNJzQW-BaWQd8zwwQumWmeZqsTWgJJ-kA4ERigSQ76Fjbak5oEWeEliSZEVpneP9KaGE9PqH0O7athmdt2prQmFD6nqM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