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

msan fails on FreeBSD with ASLR enabled #53256

Open
emaste opened this issue Jan 17, 2022 · 6 comments
Open

msan fails on FreeBSD with ASLR enabled #53256

emaste opened this issue Jan 17, 2022 · 6 comments

Comments

@emaste
Copy link
Member

emaste commented Jan 17, 2022

Disabling ASLR should not be a requirement for using msan on FreeBSD.

Right now it fails with

This sanitizer is not compatible with enabled ASLR and binaries compiled with PIE

The check was added in e2ed800.

If I downgrade the error to a warning locally I see:

$ ./a.out
This sanitizer is not compatible with enabled ASLR and binaries compiled with PIE
Running anyway
FATAL: Code 0x3dd1ab38d9b0 is out of application range. Non-PIE build?
FATAL: MemorySanitizer can not mmap the shadow memory.
FATAL: Make sure to compile with -fPIE and to link with -pie.
FATAL: Disabling ASLR is known to cause this error.
FATAL: If running under GDB, try 'set disable-randomization off'.
==81625==Process memory map follows:
        0x3dd1ab35b000-0x3dd1ab38c000   /usr/home/emaste/src/samples/llvm/msan/a.out
        0x3dd1ab38c000-0x3dd1ab3eb000   /usr/home/emaste/src/samples/llvm/msan/a.out
        0x3dd1ab3eb000-0x3dd1ab3ec000   /usr/home/emaste/src/samples/llvm/msan/a.out
        0x3dd1ab3ec000-0x3dd1ab3ef000   /usr/home/emaste/src/samples/llvm/msan/a.out
...

The "Code" address 0x3dd1ab38d9b0 is within the second address range 0x3dd1ab38c000-0x3dd1ab3eb000 for a.out.

@emaste
Copy link
Member Author

emaste commented Jan 17, 2022

Perhaps relevant comment about ASLR on Linux and PIE binaries: #21032 (comment)

@emaste
Copy link
Member Author

emaste commented Jan 17, 2022

I see CheckASLR calls in:

  • compiler-rt/lib/dfsan/dfsan.cpp
  • compiler-rt/lib/msan/msan.cpp
  • compiler-rt/lib/memprof/memprof_rtl.cpp
  • compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
  • compiler-rt/lib/tsan/rtl-old/tsan_rtl.cpp
  • compiler-rt/lib/asan/asan_rtl.cpp

so this is not limited to msan; I haven't yet investigated how other sanitizers behave with ASLR on (and the check disabled).

In general it can be preferable to debug or run diagnostics with ASLR disabled (so that results are reproducible), although it should also be possible to override if desired. lldb for example has settings set target.disable-aslr false to run with ASLR enabled.

There are a couple of issues with CheckASLR for FreeBSD:

  • it checks the kern.elf64.aslr.pie_enable sysctl (and kern.elf32.aslr.pie_enable) but these indicate the default ASLR on/off state for PIE binaries only; the default for "regular" ET_EXEC binaries is set by kern.elf64.aslr.enable and kern.elf32.aslr.enable.
  • the sysctls indicate default settings, but ASLR can be enabled/disabled on a per-process basis
  • we could improve user-friendliness by taking the same approach as Linux PPC, and re-execing the target with ASLR disabled, if necessary.

@emaste
Copy link
Member Author

emaste commented Jan 18, 2022

Review for first two bullets above: https://reviews.llvm.org/D117521

emaste added a commit to emaste/freebsd that referenced this issue Jan 20, 2022
Some sanitizers (at least msan) currently require ASLR to be disabled.
When we detect that ASLR is enabled, re-exec with it disabled rather
than exiting with an error.

LLVM GitHub issue llvm/llvm-project#53256

MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33934
emaste added a commit to emaste/freebsd that referenced this issue Jan 24, 2022
Some sanitizers (at least msan) currently require ASLR to be disabled.
When we detect that ASLR is enabled, re-exec with it disabled rather
than exiting with an error.

LLVM GitHub issue llvm/llvm-project#53256

XXX References:

https://twitter.com/ed_maste/status/1482789085454422018
https://twitter.com/ed_maste/status/1482793934862569480

MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33934
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this issue Feb 4, 2022
Some sanitizers (at least msan) currently require ASLR to be disabled.
When we detect that ASLR is enabled, re-exec with it disabled rather
than exiting with an error.  See LLVM GitHub issue 53256 for more
detail: llvm/llvm-project#53256

No objection:	dim
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33934
@emaste
Copy link
Member Author

emaste commented Feb 4, 2022

I have committed a change implementing bullet 3 above, in emaste/freebsd@96fe7c8 and emaste/freebsd@930a7c2. This will need more work for upstream as I believe we still support (in LLVM) FreeBSD versions without elf_aux_info / AT_EXEC_PATH. (See llvm/lib/Support/Unix/Path.inc std::string getMainExecutable())

emaste added a commit to emaste/freebsd that referenced this issue Feb 18, 2022
Some sanitizers (at least msan) currently require ASLR to be disabled.
When we detect that ASLR is enabled, re-exec with it disabled rather
than exiting with an error.  See LLVM GitHub issue 53256 for more
detail: llvm/llvm-project#53256

No objection:	dim
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33934

(cherry picked from commit 930a7c2)
dyeske pushed a commit to dyeske/mysrc that referenced this issue Feb 23, 2022
Some sanitizers (at least msan) currently require ASLR to be disabled.
When we detect that ASLR is enabled, re-exec with it disabled rather
than exiting with an error.  See LLVM GitHub issue 53256 for more
detail: llvm/llvm-project#53256

No objection:	dim
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33934

(cherry picked from commit 930a7c2)
bsdjhb pushed a commit to bsdjhb/cheribsd that referenced this issue Mar 2, 2022
Some sanitizers (at least msan) currently require ASLR to be disabled.
When we detect that ASLR is enabled, re-exec with it disabled rather
than exiting with an error.  See LLVM GitHub issue 53256 for more
detail: llvm/llvm-project#53256

No objection:	dim
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33934
zxombie pushed a commit to CTSRD-CHERI/freebsd-morello that referenced this issue Mar 11, 2022
Some sanitizers (at least msan) currently require ASLR to be disabled.
When we detect that ASLR is enabled, re-exec with it disabled rather
than exiting with an error.  See LLVM GitHub issue 53256 for more
detail: llvm/llvm-project#53256

No objection:	dim
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33934
@emaste
Copy link
Member Author

emaste commented Nov 22, 2023

elf_aux_info / AT_EXEC_PATH is (now) available in all supported FreeBSD releases

@DimitryAndric
Copy link
Collaborator

See also #73439.

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

3 participants