summary refs log tree commit diff
path: root/nixos/modules/security/misc.nix
diff options
context:
space:
mode:
authorJoachim Fasting <joachifm@fastmail.fm>2018-12-16 10:37:36 +0100
committerJoachim Fasting <joachifm@fastmail.fm>2018-12-27 15:00:47 +0100
commit84fb8820db6226a6e5333813d47da6d876243064 (patch)
treee213da41f9e8d4e974fe71e724442b8155578bd5 /nixos/modules/security/misc.nix
parent9db84f6fcdb2616471abb6a427a2b21fe8a8255f (diff)
downloadnixpkgs-84fb8820db6226a6e5333813d47da6d876243064.tar
nixpkgs-84fb8820db6226a6e5333813d47da6d876243064.tar.gz
nixpkgs-84fb8820db6226a6e5333813d47da6d876243064.tar.bz2
nixpkgs-84fb8820db6226a6e5333813d47da6d876243064.tar.lz
nixpkgs-84fb8820db6226a6e5333813d47da6d876243064.tar.xz
nixpkgs-84fb8820db6226a6e5333813d47da6d876243064.tar.zst
nixpkgs-84fb8820db6226a6e5333813d47da6d876243064.zip
nixos/security/misc: factor out protectKernelImage
Introduces the option security.protectKernelImage that is intended to control
various mitigations to protect the integrity of the running kernel
image (i.e., prevent replacing it without rebooting).

This makes sense as a dedicated module as it is otherwise somewhat difficult
to override for hardened profile users who want e.g., hibernation to work.
Diffstat (limited to 'nixos/modules/security/misc.nix')
-rw-r--r--nixos/modules/security/misc.nix15
1 files changed, 15 insertions, 0 deletions
diff --git a/nixos/modules/security/misc.nix b/nixos/modules/security/misc.nix
index f3fc6db22ea..b1db0bc8da8 100644
--- a/nixos/modules/security/misc.nix
+++ b/nixos/modules/security/misc.nix
@@ -22,6 +22,14 @@ with lib;
         a user namespace fails with "no space left on device" (ENOSPC).
       '';
     };
+
+    security.protectKernelImage = mkOption {
+      type = types.bool;
+      default = false;
+      description = ''
+        Whether to prevent replacing the running kernel image.
+      '';
+    };
   };
 
   config = mkMerge [
@@ -37,5 +45,12 @@ with lib;
         }
       ];
     })
+
+    (mkIf config.security.protectKernelImage {
+      # Disable hibernation (allows replacing the running kernel)
+      boot.kernelParams = [ "nohibernate" ];
+      # Prevent replacing the running kernel image w/o reboot
+      boot.kernel.sysctl."kernel.kexec_load_disabled" = mkDefault true;
+    })
   ];
 }