@@ -3,20 +3,42 @@
33with lib;
44
55let
6− virtualbox = config.boot.kernelPackages.virtualbox;
6+ cfg = config.services.virtualboxHost;
7+ virtualbox = config.boot.kernelPackages.virtualbox.override {
8+ inherit (cfg) enableHardening;
9+ };
10+
711in
812
913{
10− options = {
11− services.virtualboxHost.enable = mkEnableOption "VirtualBox Host support";
12− services.virtualboxHost.addNetworkInterface = mkOption {
14+ options.services.virtualboxHost = {
15+ enable = mkEnableOption "VirtualBox Host support";
16+
17+ addNetworkInterface = mkOption {
18+ type = types.bool;
19+ default = true;
20+ description = ''
21+ Automatically set up a vboxnet0 host-only network interface.
22+ '';
23+ };
24+
25+ enableHardening = mkOption {
1326 type = types.bool;
1427 default = true;
15− description = "Automatically set up a vboxnet0 host-only network interface.";
28+ description = ''
29+ Enable hardened VirtualBox, which ensures that only the binaries in the
30+ system path get access to the devices exposed by the kernel modules
31+ instead of all users in the vboxusers group.
32+
33+ <important><para>
34+ Disabling this can put your system's security at risk, as local users
35+ in the vboxusers group can tamper with the VirtualBox device files.
36+ </para></important>
37+ '';
1638 };
1739 };
1840
19− config = mkIf config.services.virtualboxHost.enable (mkMerge [{
41+ config = mkIf cfg.enable (mkMerge [{
2042 boot.kernelModules = [ "vboxdrv" "vboxnetadp" "vboxnetflt" ];
2143 boot.extraModulePackages = [ virtualbox ];
2244 environment.systemPackages = [ virtualbox ];
@@ -28,11 +50,11 @@ in
2850 group = "vboxusers";
2951 setuid = true;
3052 };
31− in map mkVboxStub [
53+ in mkIf cfg.enableHardening (map mkVboxStub [
3254 "VBoxHeadless"
3355 "VBoxSDL"
3456 "VirtualBox"
35− ];
57+ ]);
3658
3759 users.extraGroups.vboxusers.gid = config.ids.gids.vboxusers;
3860
@@ -48,7 +70,7 @@ in
4870 '';
4971
5072 # Since we lack the right setuid binaries, set up a host-only network by default.
51− } (mkIf config.services.virtualboxHost.addNetworkInterface {
73+ } (mkIf cfg.addNetworkInterface {
5274 systemd.services."vboxnet0" =
5375 { description = "VirtualBox vboxnet0 Interface";
5476 requires = [ "dev-vboxnetctl.device" ];