···11-{ config, lib, pkgs, ... }:
11+{ config, pkgs, lib, ... }:
2233with lib;
4455let
66 cfg = config.security.grsecurity;
77+ grsecLockPath = "/proc/sys/kernel/grsecurity/grsec_lock";
7888- customGrsecPkg =
99- (import ../../../pkgs/build-support/grsecurity {
1010- grsecOptions = cfg;
1111- inherit pkgs lib;
1212- }).grsecPackage;
99+ # Ascertain whether ZFS is required for booting the system; grsecurity is
1010+ # currently incompatible with ZFS, rendering the system unbootable.
1111+ zfsNeededForBoot = filter
1212+ (fs: (fs.neededForBoot
1313+ || elem fs.mountPoint [ "/" "/nix" "/nix/store" "/var" "/var/log" "/var/lib" "/etc" ])
1414+ && fs.fsType == "zfs")
1515+ (attrValues config.fileSystems) != [];
1316in
1717+1418{
1515- options = {
1616- security.grsecurity = {
1717- enable = mkOption {
1818- type = types.bool;
1919- default = false;
2020- description = ''
2121- Enable grsecurity support. This enables advanced exploit
2222- hardening for the Linux kernel, and adds support for
2323- administrative Role-Based Acess Control (RBAC) via
2424- <literal>gradm</literal>. It also includes traditional
2525- utilities for PaX.
2626- '';
2727- };
1919+ options.security.grsecurity = {
28202929- kernelPatch = mkOption {
3030- type = types.attrs;
3131- example = lib.literalExample "pkgs.kernelPatches.grsecurity_4_1";
3232- description = ''
3333- Grsecurity patch to use.
3434- '';
3535- };
2121+ enable = mkEnableOption "Grsecurity/PaX";
36223737- config = {
3838- mode = mkOption {
3939- type = types.enum [ "auto" "custom" ];
4040- default = "auto";
4141- description = ''
4242- grsecurity configuration mode. This specifies whether
4343- grsecurity is auto-configured or otherwise completely
4444- manually configured.
4545- '';
4646- };
2323+ lockTunables = mkOption {
2424+ type = types.bool;
2525+ example = false;
2626+ default = true;
2727+ description = ''
2828+ Whether to automatically lock grsecurity tunables
2929+ (<option>boot.kernel.sysctl."kernel.grsecurity.*"</option>). Disable
3030+ this to allow configuration of grsecurity features while the system is
3131+ running. The lock can be manually engaged by activating the
3232+ <literal>grsec-lock</literal> service unit.
3333+ '';
3434+ };
47354848- priority = mkOption {
4949- type = types.enum [ "security" "performance" ];
5050- default = "security";
5151- description = ''
5252- grsecurity configuration priority. This specifies whether
5353- the kernel configuration should emphasize speed or
5454- security.
5555- '';
5656- };
3636+ };
57375858- system = mkOption {
5959- type = types.enum [ "desktop" "server" ];
6060- default = "desktop";
6161- description = ''
6262- grsecurity system configuration.
6363- '';
6464- };
3838+ config = mkIf cfg.enable {
65396666- virtualisationConfig = mkOption {
6767- type = types.nullOr (types.enum [ "host" "guest" ]);
6868- default = null;
6969- description = ''
7070- grsecurity virtualisation configuration. This specifies
7171- the virtualisation role of the machine - that is, whether
7272- it will be a virtual machine guest, a virtual machine
7373- host, or neither.
7474- '';
7575- };
4040+ # Allow the user to select a different package set, subject to the stated
4141+ # required kernel config
4242+ boot.kernelPackages = mkDefault pkgs.linuxPackages_grsec_nixos;
76437777- hardwareVirtualisation = mkOption {
7878- type = types.nullOr types.bool;
7979- default = null;
8080- example = true;
8181- description = ''
8282- grsecurity hardware virtualisation configuration. Set to
8383- <literal>true</literal> if your machine supports hardware
8484- accelerated virtualisation.
8585- '';
8686- };
8787-8888- virtualisationSoftware = mkOption {
8989- type = types.nullOr (types.enum [ "kvm" "xen" "vmware" "virtualbox" ]);
9090- default = null;
9191- description = ''
9292- Configure grsecurity for use with this virtualisation software.
9393- '';
9494- };
9595-9696- sysctl = mkOption {
9797- type = types.bool;
9898- default = false;
9999- description = ''
100100- If true, then set <literal>GRKERN_SYSCTL y</literal>. If
101101- enabled then grsecurity can be controlled using sysctl
102102- (and turned off). You are advised to *never* enable this,
103103- but if you do, make sure to always set the sysctl
104104- <literal>kernel.grsecurity.grsec_lock</literal> to
105105- non-zero as soon as all sysctl options are set. *THIS IS
106106- EXTREMELY IMPORTANT*!
107107- '';
108108- };
109109-110110- denyChrootChmod = mkOption {
111111- type = types.bool;
112112- default = false;
113113- description = ''
114114- If true, then set <literal>GRKERN_CHROOT_CHMOD
115115- y</literal>. If enabled, this denies processes inside a
116116- chroot from setting the suid or sgid bits using
117117- <literal>chmod</literal> or <literal>fchmod</literal>.
118118-119119- By default this protection is disabled - it makes it
120120- impossible to use Nix to build software on your system,
121121- which is what most users want.
122122-123123- If you are using NixOps to deploy your software to a
124124- remote machine, you're encouraged to enable this as you
125125- won't need to compile code.
126126- '';
127127- };
128128-129129- denyChrootCaps = mkOption {
130130- type = types.bool;
131131- default = false;
132132- description = ''
133133- Whether to lower capabilities of all processes within a chroot,
134134- preventing commands that require <literal>CAP_SYS_ADMIN</literal>.
135135-136136- This protection is disabled by default because it breaks
137137- <literal>nixos-rebuild</literal>. Whenever possible, it is
138138- highly recommended to enable this protection.
139139- '';
140140- };
141141-142142- denyUSB = mkOption {
143143- type = types.bool;
144144- default = false;
145145- description = ''
146146- If true, then set <literal>GRKERNSEC_DENYUSB y</literal>.
4444+ system.requiredKernelConfig = with config.lib.kernelConfig;
4545+ [ (isEnabled "GRKERNSEC")
4646+ (isEnabled "PAX")
4747+ (isYES "GRKERNSEC_SYSCTL")
4848+ (isYES "GRKERNSEC_SYSCTL_DISTRO")
4949+ ];
14750148148- This enables a sysctl with name
149149- <literal>kernel.grsecurity.deny_new_usb</literal>. Setting
150150- its value to <literal>1</literal> will prevent any new USB
151151- devices from being recognized by the OS. Any attempted
152152- USB device insertion will be logged.
5151+ # Crashing on an overflow in kernel land is user unfriendly and may prevent
5252+ # the system from booting, which is too severe for our use case.
5353+ boot.kernelParams = [ "pax_size_overflow_report_only" ];
15354154154- This option is intended to be used against custom USB
155155- devices designed to exploit vulnerabilities in various USB
156156- device drivers.
157157- '';
158158- };
5555+ # Install PaX related utillities into the system profile. Eventually, we
5656+ # also want to include gradm here.
5757+ environment.systemPackages = with pkgs; [ paxctl pax-utils ];
15958160160- restrictProc = mkOption {
161161- type = types.bool;
162162- default = false;
163163- description = ''
164164- If true, then set <literal>GRKERN_PROC_USER
165165- y</literal>. This restricts non-root users to only viewing
166166- their own processes and restricts network-related
167167- information, kernel symbols, and module information.
168168- '';
169169- };
5959+ # Install rules for the grsec device node
6060+ services.udev.packages = [ pkgs.gradm ];
17061171171- restrictProcWithGroup = mkOption {
172172- type = types.bool;
173173- default = true;
174174- description = ''
175175- If true, then set <literal>GRKERN_PROC_USERGROUP
176176- y</literal>. This is similar to
177177- <literal>restrictProc</literal> except it allows a special
178178- group (specified by <literal>unrestrictProcGid</literal>)
179179- to still access otherwise classified information in
180180- <literal>/proc</literal>.
181181- '';
182182- };
6262+ # This service unit is responsible for locking the Grsecurity tunables. The
6363+ # unit is always defined, but only activated on bootup if lockTunables is
6464+ # toggled. When lockTunables is toggled, failure to activate the unit will
6565+ # enter emergency mode. The intent is to make it difficult to silently
6666+ # enter multi-user mode without having locked the tunables. Some effort is
6767+ # made to ensure that starting the unit is an idempotent operation.
6868+ systemd.services.grsec-lock = {
6969+ description = "Lock grsecurity tunables";
18370184184- unrestrictProcGid = mkOption {
185185- type = types.int;
186186- default = config.ids.gids.grsecurity;
187187- description = ''
188188- If set, specifies a GID which is exempt from
189189- <literal>/proc</literal> restrictions (set by
190190- <literal>GRKERN_PROC_USERGROUP</literal>). By default,
191191- this is set to the GID for <literal>grsecurity</literal>,
192192- a predefined NixOS group, which the
193193- <literal>root</literal> account is a member of. You may
194194- conveniently add other users to this group if you need
195195- access to <literal>/proc</literal>
196196- '';
197197- };
7171+ wantedBy = optional cfg.lockTunables "multi-user.target";
19872199199- disableRBAC = mkOption {
200200- type = types.bool;
201201- default = false;
202202- description = ''
203203- If true, then set <literal>GRKERN_NO_RBAC
204204- y</literal>. This disables the
205205- <literal>/dev/grsec</literal> device, which in turn
206206- disables the RBAC system (and <literal>gradm</literal>).
207207- '';
208208- };
7373+ wants = [ "local-fs.target" "systemd-sysctl.service" ];
7474+ after = [ "local-fs.target" "systemd-sysctl.service" ];
7575+ conflicts = [ "shutdown.target" ];
20976210210- disableSimultConnect = mkOption {
211211- type = types.bool;
212212- default = false;
213213- description = ''
214214- Disable TCP simultaneous connect. The TCP simultaneous connect
215215- feature allows two clients to connect without either of them
216216- entering the listening state. This feature of the TCP specification
217217- is claimed to enable an attacker to deny the target access to a given
218218- server by guessing the source port the target would use to make the
219219- connection.
7777+ restartIfChanged = false;
22078221221- This option is OFF by default because TCP simultaneous connect has
222222- some legitimate uses. Enable this option if you know what this TCP
223223- feature is for and know that you do not need it.
224224- '';
225225- };
7979+ script = ''
8080+ if ${pkgs.gnugrep}/bin/grep -Fq 0 ${grsecLockPath} ; then
8181+ echo -n 1 > ${grsecLockPath}
8282+ fi
8383+ '';
22684227227- verboseVersion = mkOption {
228228- type = types.bool;
229229- default = false;
230230- description = "Use verbose version in kernel localversion.";
231231- };
8585+ unitConfig = {
8686+ ConditionPathIsReadWrite = grsecLockPath;
8787+ DefaultDependencies = false;
8888+ } // optionalAttrs cfg.lockTunables {
8989+ OnFailure = "emergency.target";
9090+ };
23291233233- kernelExtraConfig = mkOption {
234234- type = types.str;
235235- default = "";
236236- description = "Extra kernel configuration parameters.";
237237- };
9292+ serviceConfig = {
9393+ Type = "oneshot";
9494+ RemainAfterExit = true;
23895 };
23996 };
240240- };
24197242242- config = mkIf cfg.enable {
243243- assertions =
244244- [
245245- { assertion = (cfg.config.restrictProc -> !cfg.config.restrictProcWithGroup) ||
246246- (cfg.config.restrictProcWithGroup -> !cfg.config.restrictProc);
247247- message = "You cannot enable both restrictProc and restrictProcWithGroup";
248248- }
249249- { assertion = config.boot.kernelPackages.kernel.features ? grsecurity
250250- && config.boot.kernelPackages.kernel.features.grsecurity;
251251- message = "grsecurity enabled, but kernel doesn't have grsec support";
252252- }
253253- { assertion = (cfg.config.mode == "auto" && (cfg.config.virtualisationConfig != null)) ->
254254- cfg.config.hardwareVirtualisation != null;
255255- message = "when using auto grsec mode with virtualisation, you must specify if your hardware has virtualisation extensions";
256256- }
257257- { assertion = (cfg.config.mode == "auto" && (cfg.config.virtualisationConfig != null)) ->
258258- cfg.config.virtualisationSoftware != null;
259259- message = "grsecurity configured for virtualisation but no virtualisation software specified";
260260- }
261261- ];
262262-263263- security.grsecurity.kernelPatch = lib.mkDefault pkgs.kernelPatches.grsecurity_latest;
264264-265265- systemd.services.grsec-lock = mkIf cfg.config.sysctl {
266266- description = "grsecurity sysctl-lock Service";
267267- wants = [ "systemd-sysctl.service" ];
268268- after = [ "systemd-sysctl.service" ];
269269- wantedBy = [ "multi-user.target" ];
270270- serviceConfig.Type = "oneshot";
271271- serviceConfig.RemainAfterExit = "yes";
272272- unitConfig.ConditionPathIsReadWrite = "/proc/sys/kernel/grsecurity/grsec_lock";
273273- script = ''
274274- locked=`cat /proc/sys/kernel/grsecurity/grsec_lock`
275275- if [ "$locked" == "0" ]; then
276276- echo 1 > /proc/sys/kernel/grsecurity/grsec_lock
277277- echo grsecurity sysctl lock - enabled
278278- else
279279- echo grsecurity sysctl lock already enabled - doing nothing
280280- fi
281281- '';
9898+ # Configure system tunables
9999+ boot.kernel.sysctl = {
100100+ # Removed under grsecurity
101101+ "kernel.kptr_restrict" = mkForce null;
102102+ } // optionalAttrs config.nix.useSandbox {
103103+ # chroot(2) restrictions that conflict with sandboxed Nix builds
104104+ "kernel.grsecurity.chroot_caps" = mkForce 0;
105105+ "kernel.grsecurity.chroot_deny_chroot" = mkForce 0;
106106+ "kernel.grsecurity.chroot_deny_mount" = mkForce 0;
107107+ "kernel.grsecurity.chroot_deny_pivot" = mkForce 0;
108108+ } // optionalAttrs config.boot.enableContainers {
109109+ # chroot(2) restrictions that conflict with NixOS lightweight containers
110110+ "kernel.grsecurity.chroot_deny_chmod" = mkForce 0;
111111+ "kernel.grsecurity.chroot_deny_mount" = mkForce 0;
112112+ "kernel.grsecurity.chroot_restrict_nice" = mkForce 0;
282113 };
283114284284-# systemd.services.grsec-learn = {
285285-# description = "grsecurity learning Service";
286286-# wantedBy = [ "local-fs.target" ];
287287-# serviceConfig = {
288288-# Type = "oneshot";
289289-# RemainAfterExit = "yes";
290290-# ExecStart = "${pkgs.gradm}/sbin/gradm -VFL /etc/grsec/learning.logs";
291291-# ExecStop = "${pkgs.gradm}/sbin/gradm -D";
292292-# };
293293-# };
115115+ assertions = [
116116+ { assertion = !zfsNeededForBoot;
117117+ message = "grsecurity is currently incompatible with ZFS";
118118+ }
119119+ ];
294120295295- system.activationScripts = lib.optionalAttrs (!cfg.config.disableRBAC) { grsec = ''
296296- mkdir -p /etc/grsec
297297- if [ ! -f /etc/grsec/learn_config ]; then
298298- cp ${pkgs.gradm}/etc/grsec/learn_config /etc/grsec
299299- fi
300300- if [ ! -f /etc/grsec/policy ]; then
301301- cp ${pkgs.gradm}/etc/grsec/policy /etc/grsec
302302- fi
303303- chmod -R 0600 /etc/grsec
304304- ''; };
305305-306306- # Enable AppArmor, gradm udev rules, and utilities
307307- security.apparmor.enable = true;
308308- boot.kernelPackages = customGrsecPkg;
309309- services.udev.packages = lib.optional (!cfg.config.disableRBAC) pkgs.gradm;
310310- environment.systemPackages = [ pkgs.paxctl pkgs.pax-utils ] ++ lib.optional (!cfg.config.disableRBAC) pkgs.gradm;
311121 };
312122}
+31-9
nixos/tests/grsecurity.nix
···33import ./make-test.nix ({ pkgs, ...} : {
44 name = "grsecurity";
55 meta = with pkgs.stdenv.lib.maintainers; {
66- maintainers = [ copumpkin ];
66+ maintainers = [ copumpkin joachifm ];
77 };
8899 machine = { config, pkgs, ... }:
1010- { boot.kernelPackages = pkgs.linuxPackages_grsec_testing_server; };
1010+ { security.grsecurity.enable = true;
1111+ boot.kernel.sysctl."kernel.grsecurity.deter_bruteforce" = 0;
1212+ security.apparmor.enable = true;
1313+ };
11141212- testScript =
1313- ''
1414- $machine->succeed("uname -a") =~ /grsec/;
1515- # FIXME: this seems to hang the whole test. Unclear why, but let's fix it
1616- # $machine->succeed("${pkgs.paxtest}/bin/paxtest blackhat");
1717- '';
1818-})
1515+ testScript = ''
1616+ subtest "grsec-lock", sub {
1717+ $machine->succeed("systemctl is-active grsec-lock");
1818+ $machine->succeed("grep -Fq 1 /proc/sys/kernel/grsecurity/grsec_lock");
1919+ $machine->fail("echo -n 0 >/proc/sys/kernel/grsecurity/grsec_lock");
2020+ };
19212222+ subtest "paxtest", sub {
2323+ # TODO: running paxtest blackhat hangs the vm
2424+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/anonmap") =~ /Killed/ or die;
2525+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/execbss") =~ /Killed/ or die;
2626+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/execdata") =~ /Killed/ or die;
2727+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/execheap") =~ /Killed/ or die;
2828+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/execstack") =~ /Killed/ or die;
2929+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/mprotanon") =~ /Killed/ or die;
3030+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/mprotbss") =~ /Killed/ or die;
3131+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/mprotdata") =~ /Killed/ or die;
3232+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/mprotheap") =~ /Killed/ or die;
3333+ $machine->succeed("${pkgs.paxtest}/lib/paxtest/mprotstack") =~ /Killed/ or die;
3434+ };
3535+3636+ subtest "tcc", sub {
3737+ $machine->execute("echo -e '#include <stdio.h>\nint main(void) { puts(\"hello\"); return 0; }' >main.c");
3838+ $machine->succeed("${pkgs.tinycc.bin}/bin/tcc -run main.c");
3939+ };
4040+ '';
4141+})
+7
pkgs/applications/virtualization/qemu/default.nix
···6060 ++ optional stdenv.isDarwin "--enable-cocoa"
6161 ++ optional stdenv.isLinux "--enable-linux-aio";
62626363+ postFixup =
6464+ ''
6565+ for exe in $out/bin/qemu-system-* ; do
6666+ paxmark m $exe
6767+ done
6868+ '';
6969+6370 postInstall =
6471 ''
6572 # Add a ‘qemu-kvm’ wrapper for compatibility/convenience.
+27-152
pkgs/build-support/grsecurity/default.nix
···11-{ grsecOptions, lib, pkgs }:
11+{ stdenv
22+, overrideDerivation
2333-with lib;
44+# required for gcc plugins
55+, gmp, libmpc, mpfr
4655-let
66- cfg = {
77- kernelPatch = grsecOptions.kernelPatch;
88- config = {
99- mode = "auto";
1010- sysctl = false;
1111- denyChrootCaps = false;
1212- denyChrootChmod = false;
1313- denyUSB = false;
1414- restrictProc = false;
1515- restrictProcWithGroup = true;
1616- unrestrictProcGid = 121; # Ugh, an awful hack. See grsecurity NixOS gid
1717- disableRBAC = false;
1818- disableSimultConnect = false;
1919- redistKernel = true;
2020- verboseVersion = false;
2121- kernelExtraConfig = "";
2222- } // grsecOptions.config;
2323- };
2424-2525- vals = rec {
2626-2727- mkKernel = patch:
2828- {
2929- inherit patch;
3030- inherit (patch) kernel patches grversion revision;
3131- };
3232-3333- grKernel = mkKernel cfg.kernelPatch;
3434-3535- ## -- grsecurity configuration ---------------------------------------------
3636-3737- grsecPrioCfg =
3838- if cfg.config.priority == "security" then
3939- "GRKERNSEC_CONFIG_PRIORITY_SECURITY y"
4040- else
4141- "GRKERNSEC_CONFIG_PRIORITY_PERF y";
77+# the base kernel
88+, kernel
4294343- grsecSystemCfg =
4444- if cfg.config.system == "desktop" then
4545- "GRKERNSEC_CONFIG_DESKTOP y"
4646- else
4747- "GRKERNSEC_CONFIG_SERVER y";
1010+, grsecPatch
1111+, kernelPatches ? []
48124949- grsecVirtCfg =
5050- if cfg.config.virtualisationConfig == null then
5151- "GRKERNSEC_CONFIG_VIRT_NONE y"
5252- else if cfg.config.virtualisationConfig == "host" then
5353- "GRKERNSEC_CONFIG_VIRT_HOST y"
5454- else
5555- "GRKERNSEC_CONFIG_VIRT_GUEST y";
1313+, localver ? "-grsec"
1414+, modDirVersion ? "${kernel.version}${localver}"
1515+, extraConfig ? ""
1616+, ...
1717+} @ args:
56185757- grsecHwvirtCfg = if cfg.config.virtualisationConfig == null then "" else
5858- if cfg.config.hardwareVirtualisation == true then
5959- "GRKERNSEC_CONFIG_VIRT_EPT y"
6060- else
6161- "GRKERNSEC_CONFIG_VIRT_SOFT y";
1919+assert (kernel.version == grsecPatch.kver);
62206363- grsecVirtswCfg =
6464- let virtCfg = opt: "GRKERNSEC_CONFIG_VIRT_"+opt+" y";
6565- in
6666- if cfg.config.virtualisationConfig == null then ""
6767- else if cfg.config.virtualisationSoftware == "xen" then virtCfg "XEN"
6868- else if cfg.config.virtualisationSoftware == "kvm" then virtCfg "KVM"
6969- else if cfg.config.virtualisationSoftware == "vmware" then virtCfg "VMWARE"
7070- else virtCfg "VIRTUALBOX";
7171-7272- grsecMainConfig = if cfg.config.mode == "custom" then "" else ''
7373- GRKERNSEC_CONFIG_AUTO y
7474- ${grsecPrioCfg}
7575- ${grsecSystemCfg}
7676- ${grsecVirtCfg}
7777- ${grsecHwvirtCfg}
7878- ${grsecVirtswCfg}
7979- '';
8080-8181- grsecConfig =
8282- let boolToKernOpt = b: if b then "y" else "n";
8383- # Disable RANDSTRUCT under virtualbox, as it has some kind of
8484- # breakage with the vbox guest drivers
8585- #randstruct = optionalString config.virtualisation.virtualbox.guest.enable
8686- # "GRKERNSEC_RANDSTRUCT n";
8787-8888- # Disable restricting links under the testing kernel, as something
8989- # has changed causing it to fail miserably during boot.
9090- #restrictLinks = optionalString cfg.testing
9191- # "GRKERNSEC_LINK n";
9292- in ''
9393- GRKERNSEC y
9494- ${grsecMainConfig}
9595-9696- # Disable features rendered useless by redistributing the kernel
9797- ${optionalString cfg.config.redistKernel ''
9898- GRKERNSEC_RANDSTRUCT n
9999- GRKERNSEC_HIDESYM n
100100- ''}
101101-102102- # The paxmarks mechanism relies on ELF header markings, but the default
103103- # grsecurity configuration only enables xattr markings
104104- PAX_PT_PAX_FLAGS y
105105-106106- ${if cfg.config.restrictProc then
107107- "GRKERNSEC_PROC_USER y"
108108- else
109109- optionalString cfg.config.restrictProcWithGroup ''
110110- GRKERNSEC_PROC_USERGROUP y
111111- GRKERNSEC_PROC_GID ${toString cfg.config.unrestrictProcGid}
112112- ''
113113- }
114114-115115- GRKERNSEC_SYSCTL ${boolToKernOpt cfg.config.sysctl}
116116- GRKERNSEC_CHROOT_CAPS ${boolToKernOpt cfg.config.denyChrootCaps}
117117- GRKERNSEC_CHROOT_CHMOD ${boolToKernOpt cfg.config.denyChrootChmod}
118118- GRKERNSEC_DENYUSB ${boolToKernOpt cfg.config.denyUSB}
119119- GRKERNSEC_NO_RBAC ${boolToKernOpt cfg.config.disableRBAC}
120120- GRKERNSEC_NO_SIMULT_CONNECT ${boolToKernOpt cfg.config.disableSimultConnect}
121121-122122- ${cfg.config.kernelExtraConfig}
123123- '';
124124-125125- ## -- grsecurity kernel packages -------------------------------------------
126126-127127- localver = grkern:
128128- "-grsec" + optionalString cfg.config.verboseVersion
129129- "-${grkern.grversion}-${grkern.revision}";
130130-131131- grsecurityOverrider = args: grkern: {
132132- # additional build inputs for gcc plugins, required by some PaX/grsec features
133133- nativeBuildInputs = args.nativeBuildInputs ++ (with pkgs; [ gmp libmpc mpfr ]);
134134-135135- preConfigure = (args.preConfigure or "") + ''
136136- echo ${localver grkern} > localversion-grsec
137137- '';
138138- };
139139-140140- mkGrsecKern = grkern:
141141- lowPrio (overrideDerivation (grkern.kernel.override (args: {
142142- kernelPatches = args.kernelPatches ++ [ grkern.patch ] ++ grkern.patches;
143143- argsOverride = {
144144- modDirVersion = "${grkern.kernel.modDirVersion}${localver grkern}";
145145- };
146146- extraConfig = grsecConfig;
147147- features.grsecurity = true;
148148- ignoreConfigErrors = true; # Too lazy to model the config options that work with grsecurity and don't for now
149149- })) (args: grsecurityOverrider args grkern));
150150-151151- mkGrsecPkg = grkern: pkgs.linuxPackagesFor grkern (mkGrsecPkg grkern);
152152-153153- ## -- Kernel packages ------------------------------------------------------
154154-155155- grsecKernel = mkGrsecKern grKernel;
156156- grsecPackage = mkGrsecPkg grsecKernel;
157157- };
158158-in vals
2121+overrideDerivation (kernel.override {
2222+ inherit modDirVersion;
2323+ kernelPatches = [ { inherit (grsecPatch) name patch; } ] ++ kernelPatches ++ (kernel.kernelPatches or []);
2424+ features = (kernel.features or {}) // { grsecurity = true; };
2525+ inherit extraConfig;
2626+ ignoreConfigErrors = true;
2727+}) (attrs: {
2828+ nativeBuildInputs = [ gmp libmpc mpfr ] ++ (attrs.nativeBuildInputs or []);
2929+ preConfigure = ''
3030+ echo ${localver} >localversion-grsec
3131+ ${attrs.preConfigure or ""}
3232+ '';
3333+})
···261261 # Security related features.
262262 STRICT_DEVMEM y # Filter access to /dev/mem
263263 SECURITY_SELINUX_BOOTPARAM_VALUE 0 # Disable SELinux by default
264264- ${optionalString (!(features.grsecurity or false)) ''
265265- DEVKMEM n # Disable /dev/kmem
266266- ''}
264264+ DEVKMEM n # Disable /dev/kmem
267265 ${if versionOlder version "3.14" then ''
268266 CC_STACKPROTECTOR? y # Detect buffer overflows on the stack
269267 '' else ''
···422420423421 # Virtualisation.
424422 PARAVIRT? y
425425- ${optionalString (!(features.grsecurity or false))
426426- (if versionAtLeast version "3.10" then ''
427427- HYPERVISOR_GUEST y
428428- '' else ''
429429- PARAVIRT_GUEST? y
430430- '')
431431- }
423423+ ${if versionAtLeast version "3.10" then ''
424424+ HYPERVISOR_GUEST y
425425+ '' else ''
426426+ PARAVIRT_GUEST? y
427427+ ''}
432428 KVM_APIC_ARCHITECTURE y
433429 KVM_ASYNC_PF y
434430 ${optionalString (versionOlder version "3.7") ''
···443439 ${optionalString (versionAtLeast version "4.0") ''
444440 KVM_GENERIC_DIRTYLOG_READ_PROTECT y
445441 ''}
446446- ${optionalString (!features.grsecurity or true) ''
447447- KVM_GUEST y
448448- ''}
442442+ KVM_GUEST y
449443 KVM_MMIO y
450444 ${optionalString (versionAtLeast version "3.13") ''
451445 KVM_VFIO y
···11+{ stdenv }:
22+33+with stdenv.lib;
44+55+''
66+GRKERNSEC y
77+PAX y
88+99+GRKERNSEC_CONFIG_AUTO y
1010+GRKERNSEC_CONFIG_DESKTOP y
1111+GRKERNSEC_CONFIG_VIRT_HOST y
1212+GRKERNSEC_CONFIG_VIRT_EPT y
1313+GRKERNSEC_CONFIG_VIRT_KVM y
1414+GRKERNSEC_CONFIG_PRIORITY_SECURITY y
1515+1616+PAX_PT_PAX_FLAGS y
1717+PAX_XATTR_PAX_FLAGS n
1818+PAX_EI_PAX n
1919+2020+GRKERNSEC_PROC_GID 0
2121+2222+PAX_LATENT_ENTROPY n
2323+PAX_SIZE_OVERFLOW n
2424+GRKERNSEC_HIDESYM n
2525+GRKERNSEC_RANDSTRUCT n
2626+GRKERNSEC_PROC n
2727+GRKERNSEC_SYSFS_RESTRICT n
2828+GRKERNSEC_KMEM n
2929+GRKERNSEC_MODHARDEN n
3030+GRKERNSEC_NO_SIMULT_CONNECT n
3131+3232+PAX_KERNEXEC_PLUGIN_METHOD_BTS y
3333+3434+GRKERNSEC_ACL_HIDEKERN y
3535+GRKERNSEC_IO y
3636+3737+GRKERNSEC_AUDIT_PTRACE y
3838+GRKERNSEC_FORKFAIL y
3939+4040+GRKERNSEC_SYSCTL y
4141+GRKERNSEC_SYSCTL_DISTRO y
4242+GRKERNSEC_SYSCTL_ON y
4343+''