From 8abcc6ba09d0a8978f901fecf66fe8072de02ab9 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Wed, 21 Jul 2021 15:08:44 +0200 Subject: nixos/pppd: replace CAP_SYS_ADMIN with CAP_BPF The kernel before version 5.7 required CAP_SYS_ADMIN to conduct BPF operations. After that a separate capability CAP_BPF was created, which should be sufficient in this scenario and will further tighten the sandbox around our pppd service. Tested on my personal DSL line. --- nixos/modules/services/networking/pppd.nix | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'nixos') diff --git a/nixos/modules/services/networking/pppd.nix b/nixos/modules/services/networking/pppd.nix index c1cbdb46176..45c841dbea8 100644 --- a/nixos/modules/services/networking/pppd.nix +++ b/nixos/modules/services/networking/pppd.nix @@ -82,13 +82,21 @@ in LD_PRELOAD = "${pkgs.libredirect}/lib/libredirect.so"; NIX_REDIRECTS = "/var/run=/run/pppd"; }; - serviceConfig = { + serviceConfig = let + capabilities = [ + "CAP_BPF" + "CAP_SYS_TTY_CONFIG" + "CAP_NET_ADMIN" + "CAP_NET_RAW" + ]; + in + { ExecStart = "${getBin cfg.package}/sbin/pppd call ${peerCfg.name} nodetach nolog"; Restart = "always"; RestartSec = 5; - AmbientCapabilities = "CAP_SYS_TTY_CONFIG CAP_NET_ADMIN CAP_NET_RAW CAP_SYS_ADMIN"; - CapabilityBoundingSet = "CAP_SYS_TTY_CONFIG CAP_NET_ADMIN CAP_NET_RAW CAP_SYS_ADMIN"; + AmbientCapabilities = capabilities; + CapabilityBoundingSet = capabilities; KeyringMode = "private"; LockPersonality = true; MemoryDenyWriteExecute = true; -- cgit 1.4.1 From ee26807e35e436cd0a29d32a58577a3c01f2e860 Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Wed, 21 Jul 2021 16:38:51 +0200 Subject: nixos/pppd: allow AF_NETLINK The pppd daemon starting with version 2.4.9 uses rtnetlink to configure the ipv6 peer address on the ppp interface. It therefore requires allowing AF_NETLINK sockets. --- nixos/modules/services/networking/pppd.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'nixos') diff --git a/nixos/modules/services/networking/pppd.nix b/nixos/modules/services/networking/pppd.nix index 45c841dbea8..37f44f07ac4 100644 --- a/nixos/modules/services/networking/pppd.nix +++ b/nixos/modules/services/networking/pppd.nix @@ -111,7 +111,17 @@ in ProtectKernelTunables = false; ProtectSystem = "strict"; RemoveIPC = true; - RestrictAddressFamilies = "AF_PACKET AF_UNIX AF_PPPOX AF_ATMPVC AF_ATMSVC AF_INET AF_INET6 AF_IPX"; + RestrictAddressFamilies = [ + "AF_ATMPVC" + "AF_ATMSVC" + "AF_INET" + "AF_INET6" + "AF_IPX" + "AF_NETLINK" + "AF_PACKET" + "AF_PPPOX" + "AF_UNIX" + ]; RestrictNamespaces = true; RestrictRealtime = true; RestrictSUIDSGID = true; -- cgit 1.4.1