Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler-rt/sanitizers/aarch64: CHECK failed: sanitizer_allocator_primary64.h:133 #65144

Open
real-or-random opened this issue Aug 31, 2023 · 5 comments

Comments

@real-or-random
Copy link

real-or-random commented Aug 31, 2023

Symptoms

MSan fails to init with

MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0xe00000000000, 0xfffffffffffffff4) (tid=23879)

Environment

This is when running an MSan-instrumented aarch64 binary via qemu-aarch64. I'm using a clang snapshot:

Debian clang version 18.0.0 (++20230829112257+96e83d3705c7-1~exp1~20230829112313.180) 

People report similar issues on Raspberry Pi 4, with ASan, and with Clang 16 and Clang 17, while Clang 15 works:

So this seems to be a regression between 15 and 16.

Possible causes and fix

I have a strong suspicion that the reason for this is the commit a588cfe, but I haven't tested recompiling with -DSANITIZER_CAN_USE_ALLOCATOR64=0.

When I use qemu's strace functionality, I get this just before the crash:

mmap(0x0000e00000000000,8192,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE,-1,0) = -1 errno=12 (Cannot allocate memory)

And note that the value 0xfffffffffffffff4 from the assertion is equal to -12. Here, 0x0000e00000000000 is a 48-bit address, but perhaps QEMU's emulation supports only smaller (39 bits)? [1] I suspect that the Raspberry Pi 4 also has a virtual address space smaller than 48 bits. When I try this with Clang 14, I see only mmap calls up to address 0x0000006000000000 (which is a 39-bit address).

The AArch64 memory layout on Linux can vary a lot (https://www.kernel.org/doc/html/v5.8/arm64/memory.html). Possible virtual address sizes are 39 bits, 42 bits, 48 bits, and 52 bits. Perhaps it's a good idea to detect this at runtime in the 64-bit allocator?

(note: Not sure if this is the right place to report. It seems to me that this is a compiler-rt issue, which seems to be tracked here? But please close if the existing google/sanitizers#1674 is a better place to track this.)

edit:
[1] After some more experimentation, I am not convinced that's true. I see QEMU placing the code 47-bit addresses. So I don't know why it doesn't like 0x0000e00000000000. Its emulation of the Linux memory layout may not be perfect. I might reach out to them. But this does not change much about the validity of this bug, which still seems to occur on Raspberry Pi (without any emulation layer).

@happyme531
Copy link

Seems I'm encountering the same issue on rockchip RK3588.
The clang+llvm is obtained via latest github release.

firefly@firefly ~> clang -fsanitize=memory  ./hello.c  -o hello
firefly@firefly ~> ./hello
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0xe00000000000, 0xfffffffffffffff4) (tid=51745)
    <empty stack>

firefly@firefly ~ [1]> clang --version
clang version 17.0.1 (http://git.linaro.org/toolchain/jenkins-scripts.git 09f505cadfbe9987730e641398ab9a2ca0cdb67f)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/firefly/clang+llvm-17.0.1-aarch64-linux-gnu/bin
firefly@firefly ~> uname -a
Linux firefly 5.10.160 #111 SMP Tue Jul 4 11:41:59 CST 2023 aarch64 GNU/Linux

@happyme531
Copy link

firefly@firefly ~> lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye

@pmatos
Copy link
Contributor

pmatos commented Oct 9, 2024

Same problem here with clang 19.1.1, ARM64, where VA size is 48bits crashing before program even starts.

AddressSanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0x500000000000, 0xfffffffffffffff4) (tid=1060037)

@HailToThee
Copy link

Same problem with my g++ 13.2.0
AddressSanitizer: CHECK failed: sanitizer_allocator_primary64.h:131 "((kSpaceBeg)) == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))" (0x500000000000, 0xfffffffffffffff4) (tid=11456)

@thomas-roos
Copy link

thomas-roos commented Jan 21, 2025

Can confirm that the issue does not occur with Yocto
Compiling with setting -DSANITIZER_CAN_USE_ALLOCATOR64=0

halstead pushed a commit to yoctoproject/poky that referenced this issue Jan 22, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 95a5357d8093c5c52205b9f78a4f906b41bf4caa)

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to openembedded/openembedded-core that referenced this issue Jan 22, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to yoctoproject/poky that referenced this issue Jan 22, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 95a5357d8093c5c52205b9f78a4f906b41bf4caa)

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
brainhoard-github pushed a commit to distro-core-curated-mirrors/poky-contrib that referenced this issue Jan 22, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: da4b97eb982c6202d308578499527445db6055d4)

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
halstead pushed a commit to yoctoproject/poky that referenced this issue Jan 22, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 868981e0fccfe7c87b79c07e4e49a503da6f91cd)

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to openembedded/openembedded-core that referenced this issue Jan 22, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to yoctoproject/poky that referenced this issue Jan 22, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 1ef4ba40b792597490d2ff973453084a192f0545)

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to openembedded/openembedded-core that referenced this issue Jan 22, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
halstead pushed a commit to yoctoproject/poky that referenced this issue Jan 23, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 1ef4ba40b792597490d2ff973453084a192f0545)

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
brainhoard-github pushed a commit to distro-core-curated-mirrors/poky-contrib that referenced this issue Jan 23, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: da4b97eb982c6202d308578499527445db6055d4)

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
halstead pushed a commit to openembedded/openembedded-core that referenced this issue Jan 23, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Ross Burton <ross.burton@arm.com>
halstead pushed a commit to yoctoproject/poky that referenced this issue Jan 23, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 12442b9b6df06317174066854935b1d6a4f1865d)

Signed-off-by: Thomas Roos <throos@amazon.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Ross Burton <ross.burton@arm.com>
daregit pushed a commit to daregit/yocto-combined that referenced this issue Jan 23, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 12442b9b6df06317174066854935b1d6a4f1865d)

Signed-off-by: Thomas Roos <throosamazon.de>
Signed-off-by: Richard Purdie <richard.purdielinuxfoundation.org>
Signed-off-by: Ross Burton <ross.burtonarm.com>
daregit pushed a commit to daregit/yocto-combined that referenced this issue Jan 25, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 12442b9b6df06317174066854935b1d6a4f1865d)

Signed-off-by: Thomas Roos <throosamazon.de>
Signed-off-by: Richard Purdie <richard.purdielinuxfoundation.org>
Signed-off-by: Ross Burton <ross.burtonarm.com>
daregit pushed a commit to daregit/yocto-combined that referenced this issue Feb 5, 2025
When using the -fsanitize=address  CXX_FLAG for a program compiled for
aarch64 / arm64

This is happing:
MemorySanitizer: CHECK failed: sanitizer_allocator_primary64.h:133 "((kSpaceBeg))
 == ((address_range.Init(TotalSpaceSize, PrimaryAllocatorName, kSpaceBeg)))"
 (0xe00000000000, 0xfffffffffffffff4) (tid=51745)

With -DSANITIZER_CAN_USE_ALLOCATOR64=0 this is not happening and
potenial bugs are detected.

ARM32 does not require this patch.

More info about the issue in this thread:
llvm/llvm-project#65144

(From OE-Core rev: 12442b9b6df06317174066854935b1d6a4f1865d)

Signed-off-by: Thomas Roos <throosamazon.de>
Signed-off-by: Richard Purdie <richard.purdielinuxfoundation.org>
Signed-off-by: Ross Burton <ross.burtonarm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants