From 800151e6afc43fa7fdce28df1638411fb65c79cb Mon Sep 17 00:00:00 2001 From: pennae Date: Wed, 22 Dec 2021 18:21:36 +0100 Subject: [PATCH 1/2] dhcpcd: fix privsep enabling, passthru enablePrivSep dhcpcd automatically enables privsep if it can find a suitably named user on the system, which makes it impossible to build dhcpcd without privsep on a system that's currently running dhcpcd with privsep enabled. also passthru whether privsep is enabled so that the module can check it. --- pkgs/tools/networking/dhcpcd/default.nix | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkgs/tools/networking/dhcpcd/default.nix b/pkgs/tools/networking/dhcpcd/default.nix index d60c87e51ff9..1cd1918e3c87 100644 --- a/pkgs/tools/networking/dhcpcd/default.nix +++ b/pkgs/tools/networking/dhcpcd/default.nix @@ -34,12 +34,16 @@ stdenv.mkDerivation rec { "--sysconfdir=/etc" "--localstatedir=/var" ] - ++ lib.optionals enablePrivSep [ - "--enable-privsep" - # dhcpcd disables privsep if it can't find the default user, - # so we explicitly specify a user. - "--privsepuser=dhcpcd" - ]; + ++ ( + if ! enablePrivSep + then [ "--disable-privsep" ] + else [ + "--enable-privsep" + # dhcpcd disables privsep if it can't find the default user, + # so we explicitly specify a user. + "--privsepuser=dhcpcd" + ] + ); makeFlags = [ "PREFIX=${placeholder "out"}" ]; @@ -50,7 +54,10 @@ stdenv.mkDerivation rec { # Check that the udev plugin got built. postInstall = lib.optionalString (udev != null) "[ -e ${placeholder "out"}/lib/dhcpcd/dev/udev.so ]"; - passthru.tests = { inherit (nixosTests.networking.scripted) macvlan dhcpSimple dhcpOneIf; }; + passthru = { + inherit enablePrivSep; + tests = { inherit (nixosTests.networking.scripted) macvlan dhcpSimple dhcpOneIf; }; + }; meta = with lib; { description = "A client for the Dynamic Host Configuration Protocol (DHCP)"; From 831024e2b93782519b3b5a998473434a0eb5d401 Mon Sep 17 00:00:00 2001 From: pennae Date: Wed, 22 Dec 2021 18:23:48 +0100 Subject: [PATCH 2/2] nixos/dhcpcd: assert if privSep && alternative malloc dhcpcd does not run properly with some of the hardened system mallocs that are currently available. assert when an incompatible configuration is detected, as a switch into such a config from eg auto-update can take hosts offline. --- nixos/modules/services/networking/dhcpcd.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nixos/modules/services/networking/dhcpcd.nix b/nixos/modules/services/networking/dhcpcd.nix index 2c339350acd3..3eb7ca99eafd 100644 --- a/nixos/modules/services/networking/dhcpcd.nix +++ b/nixos/modules/services/networking/dhcpcd.nix @@ -183,6 +183,20 @@ in config = mkIf enableDHCP { + assertions = [ { + # dhcpcd doesn't start properly with malloc ∉ [ libc scudo ] + # see https://github.com/NixOS/nixpkgs/issues/151696 + assertion = + dhcpcd.enablePrivSep + -> elem config.environment.memoryAllocator.provider [ "libc" "scudo" ]; + message = '' + dhcpcd with privilege separation is incompatible with chosen system malloc. + Currently only the `libc` and `scudo` allocators are known to work. + To disable dhcpcd's privilege separation, overlay Nixpkgs and override dhcpcd + to set `enablePrivSep = false`. + ''; + } ]; + systemd.services.dhcpcd = let cfgN = config.networking; hasDefaultGatewaySet = (cfgN.defaultGateway != null && cfgN.defaultGateway.address != "")