Skip to content

Commit cf1934c

Browse files
make-initrd-ng: fix file permissions (#405190)
2 parents b22909a + ed70f00 commit cf1934c

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

nixos/tests/all-tests.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ in
12961296
systemd-initrd-luks-unl0kr = handleTest ./systemd-initrd-luks-unl0kr.nix { };
12971297
systemd-initrd-modprobe = handleTest ./systemd-initrd-modprobe.nix { };
12981298
systemd-initrd-shutdown = handleTest ./systemd-shutdown.nix { systemdStage1 = true; };
1299-
systemd-initrd-simple = handleTest ./systemd-initrd-simple.nix { };
1299+
systemd-initrd-simple = runTest ./systemd-initrd-simple.nix;
13001300
systemd-initrd-swraid = handleTest ./systemd-initrd-swraid.nix { };
13011301
systemd-initrd-vconsole = handleTest ./systemd-initrd-vconsole.nix { };
13021302
systemd-initrd-networkd = handleTest ./systemd-initrd-networkd.nix { };

nixos/tests/systemd-initrd-simple.nix

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import ./make-test-python.nix (
2-
{ lib, pkgs, ... }:
3-
{
4-
name = "systemd-initrd-simple";
5-
6-
nodes.machine =
7-
{ pkgs, ... }:
8-
{
9-
testing.initrdBackdoor = true;
10-
boot.initrd.systemd.enable = true;
11-
virtualisation.fileSystems."/".autoResize = true;
12-
};
13-
14-
testScript = ''
1+
{
2+
name = "systemd-initrd-simple";
3+
4+
nodes.machine =
5+
{ pkgs, ... }:
6+
{
7+
testing.initrdBackdoor = true;
8+
boot.initrd.systemd.enable = true;
9+
virtualisation.fileSystems."/".autoResize = true;
10+
};
11+
12+
testScript =
13+
# python
14+
''
1515
import subprocess
1616
1717
with subtest("testing initrd backdoor"):
@@ -50,6 +50,8 @@ import ./make-test-python.nix (
5050
newAvail = machine.succeed("df --output=avail / | sed 1d")
5151
5252
assert int(oldAvail) < int(newAvail), "File system did not grow"
53+
54+
with subtest("no warnings from systemd about write permissions"):
55+
machine.fail("journalctl -b 0 | grep 'is marked world-writable, which is a security risk as it is executed with privileges'")
5356
'';
54-
}
55-
)
57+
}

pkgs/build-support/kernel/make-initrd-ng/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn copy_file<
212212
}
213213

214214
// Remove writable permissions
215-
permissions.set_mode(permissions.mode() ^ 0o222);
215+
permissions.set_mode(permissions.mode() & 0o555);
216216
fs::set_permissions(&target, permissions)
217217
.wrap_err_with(|| format!("failed to remove writable permissions for {:?}", target))?;
218218
};

0 commit comments

Comments
 (0)