TL;DR
Address Space Layout Randomisation (ASLR) is a key cyber security feature that makes it harder for attackers to exploit vulnerabilities. If it’s not working, your system is significantly less secure. This guide explains how to check if ASLR is enabled and what to do if it isn’t.
Checking if ASLR is Enabled
- Check Kernel Configuration: The first step is to verify that the kernel has ASLR enabled.
- Open a terminal.
- Run this command:
cat /proc/sys/kernel/randomize_va_space - If the output is 2, ASLR is fully enabled. 1 means it’s partially enabled (less secure), and 0 means it’s disabled.
- Check Executable Support: Even if the kernel has ASLR enabled, individual programs need to be compiled with support for it.
- Use the
readelftool to inspect an executable file (e.g., /bin/ls).readelf -h /bin/ls | grep 'Type:' - Look for the line starting with “Type:”. If it includes ‘EXEC’, proceed to the next step.
- Use the
- Check PIE (Position Independent Executable): ASLR relies on executables being compiled as Position Independent Executables (PIE).
- Run this command:
readelf -h /bin/ls | grep 'Flags:' - If the “Flags:” line contains ‘EXEC_P’, it’s likely PIE is enabled.
- Run this command:
Fixing ASLR Issues
- Recompile Programs: If a program doesn’t support ASLR (PIE isn’t enabled), you need to recompile it with the correct flags.
- When compiling, use the
-fpieand-pieflags. For example:gcc -fpie -pie myprogram.c -o myprogram
- When compiling, use the
- Kernel Module Issues: Sometimes a kernel module can interfere with ASLR.
- Identify any recently installed or updated kernel modules that might be causing problems.
- Try unloading the module to see if it resolves the issue (use
modprobe -r modulename). Be careful when doing this, as removing essential modules can crash your system!
- Systemd Hardening: Systemd configurations can sometimes disable ASLR for specific services.
- Check the service unit file (e.g., /etc/systemd/system/myservice.service).
- Look for lines like
ASLR=noor similar. Remove or comment out these lines. - Reload systemd:
sudo systemctl daemon-reload - Restart the service:
sudo systemctl restart myservice
- Check for Conflicting Security Settings: Other security features (like AppArmor or SELinux) might be interfering with ASLR.
- Temporarily disable these features to see if it resolves the issue. If so, you’ll need to adjust their configurations to allow ASLR to function correctly.
- Update Your System: Ensure your kernel and other system components are up-to-date.
- Use your distribution’s package manager (e.g.,
sudo apt update && sudo apt upgradeon Debian/Ubuntu).
- Use your distribution’s package manager (e.g.,
Important Notes
- Disabling ASLR is strongly discouraged unless absolutely necessary for compatibility reasons, and even then, it should be done with extreme caution.
- Always test any changes in a non-production environment first.

