2017-04-06 14:54:45 +02:00
|
|
|
# A profile with most (vanilla) hardening options enabled by default,
|
2021-01-04 16:03:29 +01:00
|
|
|
# potentially at the cost of stability, features and performance.
|
|
|
|
#
|
|
|
|
# This profile enables options that are known to affect system
|
|
|
|
# stability. If you experience any stability issues when using the
|
|
|
|
# profile, try disabling it. If you report an issue and use this
|
|
|
|
# profile, always mention that you do.
|
2017-04-06 14:54:45 +02:00
|
|
|
|
2020-08-23 12:17:53 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2017-04-06 14:54:45 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
2018-10-15 00:18:33 +02:00
|
|
|
meta = {
|
2020-04-05 00:58:54 +02:00
|
|
|
maintainers = [ maintainers.joachifm maintainers.emily ];
|
2018-10-15 00:18:33 +02:00
|
|
|
};
|
|
|
|
|
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-11-19 10:26:49 +01:00
|
|
|
environment.memoryAllocator.provider = mkDefault "scudo";
|
|
|
|
environment.variables.SCUDO_OPTIONS = mkDefault "ZeroContents=1";
|
|
|
|
|
2017-04-29 22:46:20 +02:00
|
|
|
security.lockKernelModules = mkDefault true;
|
|
|
|
|
2018-12-16 10:37:36 +01:00
|
|
|
security.protectKernelImage = mkDefault true;
|
|
|
|
|
2018-12-26 22:24:04 +01:00
|
|
|
security.allowSimultaneousMultithreading = mkDefault false;
|
|
|
|
|
2019-07-30 02:24:56 +02:00
|
|
|
security.forcePageTableIsolation = mkDefault true;
|
|
|
|
|
2020-08-23 12:17:53 +02:00
|
|
|
# This is required by podman to run containers in rootless mode.
|
|
|
|
security.unprivilegedUsernsClone = mkDefault config.virtualisation.containers.enable;
|
|
|
|
|
2019-07-19 15:49:37 +02:00
|
|
|
security.virtualisation.flushL1DataCache = mkDefault "always";
|
2018-12-26 22:22:55 +01:00
|
|
|
|
2017-04-06 14:54:45 +02:00
|
|
|
security.apparmor.enable = mkDefault true;
|
2021-03-01 00:24:54 +01:00
|
|
|
security.apparmor.killUnconfinedConfinables = mkDefault true;
|
2017-04-06 14:54:45 +02:00
|
|
|
|
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"
|
|
|
|
|
2017-04-30 01:22:32 +02:00
|
|
|
# Overwrite free'd memory
|
|
|
|
"page_poison=1"
|
|
|
|
|
2019-08-15 18:24:24 +02:00
|
|
|
# Enable page allocator randomization
|
|
|
|
"page_alloc.shuffle=1"
|
2017-04-29 17:27:08 +02:00
|
|
|
];
|
|
|
|
|
2017-09-03 01:49:01 +02:00
|
|
|
boot.blacklistedKernelModules = [
|
|
|
|
# Obscure network protocols
|
|
|
|
"ax25"
|
|
|
|
"netrom"
|
|
|
|
"rose"
|
2019-10-12 12:08:44 +02:00
|
|
|
|
|
|
|
# Old or rare or insufficiently audited filesystems
|
|
|
|
"adfs"
|
|
|
|
"affs"
|
|
|
|
"bfs"
|
|
|
|
"befs"
|
|
|
|
"cramfs"
|
|
|
|
"efs"
|
|
|
|
"erofs"
|
|
|
|
"exofs"
|
|
|
|
"freevxfs"
|
|
|
|
"f2fs"
|
|
|
|
"hfs"
|
|
|
|
"hpfs"
|
|
|
|
"jfs"
|
|
|
|
"minix"
|
|
|
|
"nilfs2"
|
2020-09-27 08:16:58 +02:00
|
|
|
"ntfs"
|
|
|
|
"omfs"
|
2019-10-12 12:08:44 +02:00
|
|
|
"qnx4"
|
|
|
|
"qnx6"
|
|
|
|
"sysv"
|
|
|
|
"ufs"
|
2017-09-03 01:49:01 +02:00
|
|
|
];
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
# Hide kptrs even for processes with CAP_SYSLOG
|
|
|
|
boot.kernel.sysctl."kernel.kptr_restrict" = mkOverride 500 2;
|
|
|
|
|
|
|
|
# Disable bpf() JIT (to eliminate spray attacks)
|
|
|
|
boot.kernel.sysctl."net.core.bpf_jit_enable" = mkDefault false;
|
|
|
|
|
2019-07-04 18:50:48 +02:00
|
|
|
# Disable ftrace debugging
|
|
|
|
boot.kernel.sysctl."kernel.ftrace_enabled" = mkDefault false;
|
2019-07-04 18:51:06 +02:00
|
|
|
|
2019-08-11 13:32:24 +02:00
|
|
|
# Enable strict reverse path filtering (that is, do not attempt to route
|
|
|
|
# packets that "obviously" do not belong to the iface's network; dropped
|
|
|
|
# packets are logged as martians).
|
2019-07-04 18:51:06 +02:00
|
|
|
boot.kernel.sysctl."net.ipv4.conf.all.log_martians" = mkDefault true;
|
2019-08-11 13:32:24 +02:00
|
|
|
boot.kernel.sysctl."net.ipv4.conf.all.rp_filter" = mkDefault "1";
|
2019-07-04 18:51:06 +02:00
|
|
|
boot.kernel.sysctl."net.ipv4.conf.default.log_martians" = mkDefault true;
|
2019-08-11 13:32:24 +02:00
|
|
|
boot.kernel.sysctl."net.ipv4.conf.default.rp_filter" = mkDefault "1";
|
2019-07-04 18:51:06 +02:00
|
|
|
|
|
|
|
# Ignore broadcast ICMP (mitigate SMURF)
|
|
|
|
boot.kernel.sysctl."net.ipv4.icmp_echo_ignore_broadcasts" = mkDefault true;
|
|
|
|
|
|
|
|
# Ignore incoming ICMP redirects (note: default is needed to ensure that the
|
|
|
|
# setting is applied to interfaces added after the sysctls are set)
|
|
|
|
boot.kernel.sysctl."net.ipv4.conf.all.accept_redirects" = mkDefault false;
|
|
|
|
boot.kernel.sysctl."net.ipv4.conf.all.secure_redirects" = mkDefault false;
|
|
|
|
boot.kernel.sysctl."net.ipv4.conf.default.accept_redirects" = mkDefault false;
|
|
|
|
boot.kernel.sysctl."net.ipv4.conf.default.secure_redirects" = mkDefault false;
|
|
|
|
boot.kernel.sysctl."net.ipv6.conf.all.accept_redirects" = mkDefault false;
|
|
|
|
boot.kernel.sysctl."net.ipv6.conf.default.accept_redirects" = mkDefault false;
|
|
|
|
|
|
|
|
# Ignore outgoing ICMP redirects (this is ipv4 only)
|
|
|
|
boot.kernel.sysctl."net.ipv4.conf.all.send_redirects" = mkDefault false;
|
|
|
|
boot.kernel.sysctl."net.ipv4.conf.default.send_redirects" = mkDefault false;
|
2017-04-06 14:54:45 +02:00
|
|
|
}
|