This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Improve FreeBSD ASLR detection
ClosedPublic

Authored by emaste on Jan 17 2022, 4:09 PM.

Details

Summary

The kern.elf64.aslr.pie_enable and kern.elf32.aslr.pie_enable sysctls control the default setting for PIE binary address randomization, but it is possible to enable or disable ASLR on a per-process basis. Use procctl(2) to query whether ASLR is enabled.

(Note that with ASLR enabled but sysctl kern.elf64.aslr.pie_enable=0 a PIE binary will in effect have randomization disabled, and be functional with msan. This is not intended as as a user-facing control though. The user can use proccontrol(1) to disable aslr for the process.)

Diff Detail

Event Timeline

emaste requested review of this revision.Jan 17 2022, 4:09 PM
emaste created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2022, 4:09 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

As a subsequent change I'll propose using PROC_ASLR_CTL to turn ASLR off and ReExec().

emaste added inline comments.Jan 17 2022, 5:50 PM
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
2190

this should be 0 instead of getpid()

emaste updated this revision to Diff 400683.Jan 17 2022, 5:50 PM

0 is an alias for curproc

emaste updated this revision to Diff 400687.Jan 17 2022, 6:17 PM

procctl was added as of FreeBSD 10.0, and both 10.x and 11.x are now EOL, so I don't think we need to support for cases where it is not available.

devnexen accepted this revision.Jan 17 2022, 9:43 PM
devnexen added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
2192

Wonder if this comment is valid in this context, freebsd 11 being EOL now.

This revision is now accepted and ready to land.Jan 17 2022, 9:43 PM
devnexen added inline comments.Jan 17 2022, 10:05 PM
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
2192

forget it I misread your sentence :)

This revision was landed with ongoing or failed builds.Jan 18 2022, 2:07 PM
This revision was automatically updated to reflect the committed changes.