Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/13505'
Browse files Browse the repository at this point in the history
Fixes #13505.

(cherry picked from commit eb5a897)
  • Loading branch information
fpletz committed Mar 8, 2016
1 parent 3a5a26e commit 613dfd5
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 95 deletions.
28 changes: 6 additions & 22 deletions nixos/modules/security/grsecurity.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,12 @@ in
'';
};

stable = mkOption {
type = types.bool;
default = false;
kernelPatch = mkOption {
type = types.attrs;
default = pkgs.kernelPatches.grsecurity_latest;
example = pkgs.kernelPatches.grsecurity_4_1;
description = ''
Enable the stable grsecurity patch, based on Linux 3.14.
'';
};

testing = mkOption {
type = types.bool;
default = false;
description = ''
Enable the testing grsecurity patch, based on Linux 4.0.
Grsecurity patch to use.
'';
};

Expand Down Expand Up @@ -219,16 +212,7 @@ in

config = mkIf cfg.enable {
assertions =
[ { assertion = cfg.stable || cfg.testing;
message = ''
If grsecurity is enabled, you must select either the
stable patch (with kernel 3.14), or the testing patch (with
kernel 4.0) to continue.
'';
}
{ assertion = !(cfg.stable && cfg.testing);
message = "Select either one of the stable or testing patch";
}
[
{ assertion = (cfg.config.restrictProc -> !cfg.config.restrictProcWithGroup) ||
(cfg.config.restrictProcWithGroup -> !cfg.config.restrictProc);
message = "You cannot enable both restrictProc and restrictProcWithGroup";
Expand Down
25 changes: 9 additions & 16 deletions pkgs/build-support/grsecurity/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ with lib;

let
cfg = {
stable = grsecOptions.stable or false;
testing = grsecOptions.testing or false;
kernelPatch = grsecOptions.kernelPatch;
config = {
mode = "auto";
sysctl = false;
Expand All @@ -22,18 +21,13 @@ let

vals = rec {

mkKernel = kernel: patch:
assert patch.kversion == kernel.version;
{ inherit kernel patch;
inherit (patch) grversion revision;
mkKernel = patch:
{
inherit patch;
inherit (patch) kernel patches grversion revision;
};

test-patch = with pkgs.kernelPatches; grsecurity_unstable;
stable-patch = with pkgs.kernelPatches; grsecurity_stable;

grKernel = if cfg.stable
then mkKernel pkgs.linux_3_14 stable-patch
else mkKernel pkgs.linux_4_3 test-patch;
grKernel = mkKernel cfg.kernelPatch;

## -- grsecurity configuration ---------------------------------------------

Expand Down Expand Up @@ -90,8 +84,8 @@ let

# Disable restricting links under the testing kernel, as something
# has changed causing it to fail miserably during boot.
restrictLinks = optionalString cfg.testing
"GRKERNSEC_LINK n";
#restrictLinks = optionalString cfg.testing
# "GRKERNSEC_LINK n";
in ''
GRKERNSEC y
${grsecMainConfig}
Expand All @@ -109,7 +103,6 @@ let
GRKERNSEC_CHROOT_CHMOD ${boolToKernOpt cfg.config.denyChrootChmod}
GRKERNSEC_DENYUSB ${boolToKernOpt cfg.config.denyUSB}
GRKERNSEC_NO_RBAC ${boolToKernOpt cfg.config.disableRBAC}
${restrictLinks}
${cfg.config.kernelExtraConfig}
'';
Expand All @@ -136,7 +129,7 @@ let

mkGrsecKern = grkern:
lowPrio (overrideDerivation (grkern.kernel.override (args: {
kernelPatches = args.kernelPatches ++ [ grkern.patch pkgs.kernelPatches.grsec_fix_path ];
kernelPatches = args.kernelPatches ++ [ grkern.patch ] ++ grkern.patches;
argsOverride = {
modDirVersion = "${grkern.kernel.modDirVersion}${localver grkern}";
};
Expand Down
25 changes: 8 additions & 17 deletions pkgs/build-support/grsecurity/flavors.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
let
mkOpts = ver: prio: sys: virt: swvirt: hwvirt:
mkOpts = prio: sys: virt: swvirt: hwvirt:
{ config.priority = prio;
config.system = sys;
config.virtualisationConfig = virt;
config.hardwareVirtualisation = hwvirt;
config.virtualisationSoftware = swvirt;
} // builtins.listToAttrs [ { name = ver; value = true; } ];
};
in
{
# Stable kernels
linux_grsec_stable_desktop =
mkOpts "stable" "performance" "desktop" "host" "kvm" true;
linux_grsec_stable_server =
mkOpts "stable" "security" "server" "host" "kvm" true;
linux_grsec_stable_server_xen =
mkOpts "stable" "security" "server" "guest" "xen" true;

# Testing kernels
linux_grsec_testing_desktop =
mkOpts "testing" "performance" "desktop" "host" "kvm" true;
linux_grsec_testing_server =
mkOpts "testing" "security" "server" "host" "kvm" true;
linux_grsec_testing_server_xen =
mkOpts "testing" "security" "server" "guest" "xen" true;
desktop =
mkOpts "performance" "desktop" "host" "kvm" true;
server =
mkOpts "security" "server" "host" "kvm" true;
server_xen =
mkOpts "security" "server" "guest" "xen" true;
}
18 changes: 18 additions & 0 deletions pkgs/os-specific/linux/kernel/grsecurity-path-4.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/kernel/kmod.c b/kernel/kmod.c
index a689506..30747b4 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -294,11 +294,8 @@ static int ____call_usermodehelper(void *data)
out the path to be used prior to this point and are now operating
on that copy
*/
- if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
- strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
- strncmp(sub_info->path, "/usr/libexec/", 13) && strncmp(sub_info->path, "/usr/bin/", 9) &&
- strncmp(sub_info->path, "/usr/sbin/", 10) &&
- strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/nix/store/", 11) &&
+ strncmp(sub_info->path, "/run/current-system/systemd/lib/", 32)) || strstr(sub_info->path, "..")) {
printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of permitted system paths\n", sub_info->path);
retval = -EPERM;
goto out;
19 changes: 19 additions & 0 deletions pkgs/os-specific/linux/kernel/linux-grsecurity-3.14.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ stdenv, fetchurl, perl, buildLinux, ... } @ args:

import ./generic.nix (args // rec {
version = "3.14.51";
extraMeta.branch = "3.14";

src = fetchurl {
url = "mirror://kernel/linux/kernel/v3.x/linux-${version}.tar.xz";
sha256 = "1gqsd69cqijff4c4br4ydmcjl226d0yy6vrmgfvy16xiraavq1mk";
};

kernelPatches = args.kernelPatches;

features.iwlwifi = true;
features.efiBootStub = true;
features.needsCifsUtils = true;
features.canDisableNetfilterConntrackHelpers = true;
features.netfilterRPFilter = true;
} // (args.argsOverride or {}))
19 changes: 19 additions & 0 deletions pkgs/os-specific/linux/kernel/linux-grsecurity-4.1.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ stdenv, fetchurl, perl, buildLinux, ... } @ args:

import ./generic.nix (args // rec {
version = "4.1.7";
extraMeta.branch = "4.1";

src = fetchurl {
url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
sha256 = "0g1dnvak0pd03d4miy1025bw64wq71w29a058dzspdr6jcf9qwbn";
};

kernelPatches = args.kernelPatches;

features.iwlwifi = true;
features.efiBootStub = true;
features.needsCifsUtils = true;
features.canDisableNetfilterConntrackHelpers = true;
features.netfilterRPFilter = true;
} // (args.argsOverride or {}))
19 changes: 19 additions & 0 deletions pkgs/os-specific/linux/kernel/linux-grsecurity-4.4.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ stdenv, fetchurl, perl, buildLinux, ... } @ args:

import ./generic.nix (args // rec {
version = "4.4.2";
extraMeta.branch = "4.4";

src = fetchurl {
url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
sha256 = "09l6y0nb8yv7l16arfwhy4i5h9pkxcbd7hlbw0015n7gm4i2mzc2";
};

kernelPatches = args.kernelPatches;

features.iwlwifi = true;
features.efiBootStub = true;
features.needsCifsUtils = true;
features.canDisableNetfilterConntrackHelpers = true;
features.netfilterRPFilter = true;
} // (args.argsOverride or {}))
49 changes: 35 additions & 14 deletions pkgs/os-specific/linux/kernel/patches.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, fetchurl }:
{ stdenv, fetchurl, pkgs }:

let

Expand All @@ -18,11 +18,14 @@ let
};
};

grsecPatch = { grversion ? "3.1", kversion, revision, branch, sha256 }:
grsecPatch = { grversion ? "3.1", kernel, patches, kversion, revision, branch ? "test", sha256 }:
assert kversion == kernel.version;
{ name = "grsecurity-${grversion}-${kversion}";
inherit grversion kversion revision;
inherit grversion kernel patches kversion revision;
patch = fetchurl {
url = "https://github.com/slashbeast/grsecurity-scrape/blob/master/${branch}/grsecurity-${grversion}-${kversion}-${revision}.patch?raw=true";
url = if branch == "stable"
then "https://github.com/kdave/grsecurity-patches/blob/master/grsecurity_patches/grsecurity-${grversion}-${kversion}-${revision}.patch?raw=true"
else "https://github.com/slashbeast/grsecurity-scrape/blob/master/${branch}/grsecurity-${grversion}-${kversion}-${revision}.patch?raw=true";
inherit sha256;
};
features.grsecurity = true;
Expand Down Expand Up @@ -79,23 +82,41 @@ rec {
sha256 = "00b1rqgd4yr206dxp4mcymr56ymbjcjfa4m82pxw73khj032qw3j";
};

grsecurity_stable = grsecPatch
{ kversion = "3.14.51";
grsecurity_3_14 = grsecPatch
{ kernel = pkgs.grsecurity_base_linux_3_14;
patches = [ grsecurity_fix_path_3_14 ];
kversion = "3.14.51";
revision = "201508181951";
branch = "stable";
sha256 = "1sp1gwa7ahzflq7ayb51bg52abrn5zx1hb3pff3axpjqq7vfai6f";
};

grsecurity_unstable = grsecPatch
{ kversion = "4.3.4";
revision = "201601231215";
branch = "test";
sha256 = "1dacld4zlp8mk6ykc0f1v5crppvq3znbdw9rwfrf6qi90984x0mr";
grsecurity_4_1 = grsecPatch
{ kernel = pkgs.grsecurity_base_linux_4_1;
patches = [ grsecurity_fix_path_3_14 ];
kversion = "4.1.7";
revision = "201509201149";
sha256 = "1agv8c3c4vmh5algbzmrq2f6vwk72rikrlcbm4h7jbrb9js6fxk4";
};

grsec_fix_path =
{ name = "grsec-fix-path";
patch = ./grsec-path.patch;
grsecurity_4_4 = grsecPatch
{ kernel = pkgs.grsecurity_base_linux_4_4;
patches = [ grsecurity_fix_path_4_4 ];
kversion = "4.4.2";
revision = "201602182048";
sha256 = "0dm0nzzja6ynzdz2k5h0ckys7flw307i3w0k1lwjxfj80civ73wr";
};

grsecurity_latest = grsecurity_4_4;

grsecurity_fix_path_3_14 =
{ name = "grsecurity-fix-path-3.14";
patch = ./grsecurity-path-3.14.patch;
};

grsecurity_fix_path_4_4 =
{ name = "grsecurity-fix-path-4.4";
patch = ./grsecurity-path-4.4.patch;
};

crc_regression =
Expand Down
Loading

0 comments on commit 613dfd5

Please sign in to comment.