2017-04-06 14:54:45 +02:00
|
|
|
# A profile with most (vanilla) hardening options enabled by default,
|
|
|
|
# potentially at the cost of features and performance.
|
|
|
|
|
2018-07-20 22:56:59 +02:00
|
|
|
{ lib, pkgs, ... }:
|
2017-04-06 14:54:45 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
2018-10-15 00:18:33 +02:00
|
|
|
meta = {
|
|
|
|
maintainers = [ maintainers.joachifm ];
|
|
|
|
};
|
|
|
|
|
2017-04-30 01:22:32 +02:00
|
|
|
boot.kernelPackages = mkDefault pkgs.linuxPackages_hardened;
|
|
|
|
|
2018-11-24 15:13:03 +01:00
|
|
|
nix.allowedUsers = mkDefault [ "@users" ];
|
|
|
|
|
2019-04-23 22:21:40 +02:00
|
|
|
environment.memoryAllocator.provider = mkDefault "graphene-hardened";
|
|
|
|
|
2017-04-06 14:54:45 +02:00
|
|
|
security.hideProcessInformation = mkDefault true;
|
|
|
|
|
2017-04-29 22:46:20 +02:00
|
|
|
security.lockKernelModules = mkDefault true;
|
|
|
|
|
2018-10-15 00:39:26 +02:00
|
|
|
security.allowUserNamespaces = mkDefault false;
|
|
|
|
|
2018-12-16 10:37:36 +01:00
|
|
|
security.protectKernelImage = mkDefault true;
|
|
|
|
|
2018-12-26 22:24:04 +01:00
|
|
|
security.allowSimultaneousMultithreading = mkDefault false;
|
|
|
|
|
2018-12-26 22:22:55 +01:00
|
|
|
security.virtualization.flushL1DataCache = mkDefault "always";
|
|
|
|
|
2017-04-06 14:54:45 +02:00
|
|
|
security.apparmor.enable = mkDefault true;
|
|
|
|
|
2017-04-29 17:27:08 +02:00
|
|
|
boot.kernelParams = [
|
2019-01-05 13:47:25 +01:00
|
|
|
# Slab/slub sanity checks, redzoning, and poisoning
|
|
|
|
"slub_debug=FZP"
|
|
|
|
|
|
|
|
# Disable slab merging to make certain heap overflow attacks harder
|
|
|
|
"slab_nomerge"
|
|
|
|
|
2017-04-30 01:22:32 +02:00
|
|
|
# Overwrite free'd memory
|
|
|
|
"page_poison=1"
|
|
|
|
|
2017-04-29 17:27:08 +02:00
|
|
|
# Disable legacy virtual syscalls
|
|
|
|
"vsyscall=none"
|
2019-01-05 13:50:36 +01:00
|
|
|
|
|
|
|
# Enable PTI even if CPU claims to be safe from meltdown
|
|
|
|
"pti=on"
|
2017-04-29 17:27:08 +02:00
|
|
|
];
|
|
|
|
|
2017-09-03 01:49:01 +02:00
|
|
|
boot.blacklistedKernelModules = [
|
|
|
|
# Obscure network protocols
|
|
|
|
"ax25"
|
|
|
|
"netrom"
|
|
|
|
"rose"
|
|
|
|
];
|
|
|
|
|
2017-04-06 14:54:45 +02:00
|
|
|
# Restrict ptrace() usage to processes with a pre-defined relationship
|
|
|
|
# (e.g., parent/child)
|
|
|
|
boot.kernel.sysctl."kernel.yama.ptrace_scope" = mkOverride 500 1;
|
|
|
|
|
|
|
|
# Restrict access to kernel ring buffer (information leaks)
|
|
|
|
boot.kernel.sysctl."kernel.dmesg_restrict" = mkDefault true;
|
|
|
|
|
|
|
|
# Hide kptrs even for processes with CAP_SYSLOG
|
|
|
|
boot.kernel.sysctl."kernel.kptr_restrict" = mkOverride 500 2;
|
|
|
|
|
|
|
|
# Unprivileged access to bpf() has been used for privilege escalation in
|
|
|
|
# the past
|
|
|
|
boot.kernel.sysctl."kernel.unprivileged_bpf_disabled" = mkDefault true;
|
|
|
|
|
|
|
|
# Disable bpf() JIT (to eliminate spray attacks)
|
|
|
|
boot.kernel.sysctl."net.core.bpf_jit_enable" = mkDefault false;
|
|
|
|
|
|
|
|
# ... or at least apply some hardening to it
|
|
|
|
boot.kernel.sysctl."net.core.bpf_jit_harden" = mkDefault true;
|
2017-04-30 14:41:56 +02:00
|
|
|
|
2017-08-13 00:17:43 +02:00
|
|
|
# Raise ASLR entropy for 64bit & 32bit, respectively.
|
|
|
|
#
|
|
|
|
# Note: mmap_rnd_compat_bits may not exist on 64bit.
|
|
|
|
boot.kernel.sysctl."vm.mmap_rnd_bits" = mkDefault 32;
|
|
|
|
boot.kernel.sysctl."vm.mmap_rnd_compat_bits" = mkDefault 16;
|
2017-09-03 01:48:46 +02:00
|
|
|
|
|
|
|
# Allowing users to mmap() memory starting at virtual address 0 can turn a
|
|
|
|
# NULL dereference bug in the kernel into code execution with elevated
|
|
|
|
# privilege. Mitigate by enforcing a minimum base addr beyond the NULL memory
|
|
|
|
# space. This breaks applications that require mapping the 0 page, such as
|
|
|
|
# dosemu or running 16bit applications under wine. It also breaks older
|
|
|
|
# versions of qemu.
|
|
|
|
#
|
|
|
|
# The value is taken from the KSPP recommendations (Debian uses 4096).
|
|
|
|
boot.kernel.sysctl."vm.mmap_min_addr" = mkDefault 65536;
|
2017-04-06 14:54:45 +02:00
|
|
|
}
|