Commit Graph

634 Commits

Author SHA1 Message Date
renovate[bot] 03c2f52ee9
fix(deps): update all dependencies 2023-10-30 00:00:50 +00:00
Julian Stecklina a5e89456fc
Merge pull request #244 from phip1611/improvements
linux_loader: improve code quality + bug fix
2023-10-29 12:33:49 +00:00
Philipp Schuster b7f68a50e6 linux_loader: improve code quality
`Option<&T>` has the same ABI layout as `*const T`, so we have some room for
improvement where we get more Rust convenience. Further, a bug is fixed where
INVALID_PARAMETER wasn't returned when the BUFFER_SIZE pointer is NULL.

See UEFI 2.10 13.2.2. EFI_LOAD_FILE2_PROTOCOL.LoadFile() for reference.
2023-10-24 13:23:30 +02:00
Julian Stecklina bb380e1948
Merge pull request #243 from nix-community/renovate/lock-file-maintenance
chore(deps): lock file maintenance
2023-10-23 22:34:16 +00:00
Julian Stecklina 56386ae1c3 fixtures: add snakeoil dbx pem
sbctl 0.12 wants to have the forbidden signatures or fails to enroll
keys.
2023-10-24 00:23:48 +02:00
renovate[bot] e0511f43e7
chore(deps): lock file maintenance 2023-10-23 00:26:27 +00:00
nikstur 4366cd1b4c
Merge pull request #242 from nix-community/generation-name
Consistently Display Generations in systemd-boot
2023-10-21 19:23:18 +02:00
Julian Stecklina ec05d707f3 tool: always include version in PRETTY_NAME
... to give a consistent user experience in systemd-boot.

Fixes #220.
2023-10-20 11:55:53 +02:00
Julian Stecklina 3da3049bef tool: remove unhelpful wrappers and lightly refactor 2023-10-20 11:29:00 +02:00
Julian Stecklina 0c38cbfa6a
Merge pull request #216 from nix-community/renovate/lock-file-maintenance
chore(deps): lock file maintenance
2023-10-19 20:59:26 +00:00
renovate[bot] 853c81eef2
chore(deps): lock file maintenance 2023-10-19 20:29:32 +00:00
Julian Stecklina 56bf9b942c
Merge pull request #241 from nix-community/pin-edk2-202305
Pin EDK2 202305
2023-10-19 20:24:53 +00:00
Julian Stecklina 65003165c8 tests: downgrade from edk2 202308 to 202305 2023-10-19 21:14:45 +02:00
Julian Stecklina 0c7ca2b180 nix: remove unused follows 2023-10-19 19:23:59 +02:00
Julian Stecklina adc7420ece flake.lock: Update
Flake lock file updates:

• Updated input 'crane':
    'github:ipetkov/crane/8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e' (2023-07-07)
  → 'github:ipetkov/crane/bc5fa8cd53ef32b9b827f24b993c42a8c4dd913b' (2023-10-19)
• Removed input 'crane/flake-compat'
• Removed input 'crane/flake-utils'
• Removed input 'crane/rust-overlay'
• Updated input 'flake-compat':
    'github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9' (2023-01-17)
  → 'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04)
• Updated input 'flake-parts':
    'github:hercules-ci/flake-parts/8e8d955c22df93dbe24f19ea04f47a74adbdc5ec' (2023-07-04)
  → 'github:hercules-ci/flake-parts/c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4' (2023-10-03)
• Updated input 'flake-utils':
    'github:numtide/flake-utils/919d646de7be200f3bf08cb76ae1f09402b6f9b4' (2023-07-11)
  → 'github:numtide/flake-utils/ff7b65b44d01cf9ba6a71320833626af21126384' (2023-09-12)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/248a83fffc10b627da67fa6b25d2c13fc7542628' (2023-09-28)
  → 'github:NixOS/nixpkgs/6be2c349a30fcb489a3153dd331e9df387ab6449' (2023-10-19)
• Updated input 'pre-commit-hooks-nix':
    'github:cachix/pre-commit-hooks.nix/eb433bff05b285258be76513add6f6c57b441775' (2023-07-18)
  → 'github:cachix/pre-commit-hooks.nix/42e1b6095ef80a51f79595d9951eb38e91c4e6ca' (2023-10-09)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/7c4f46f0b3597e3c4663285e6794194e55574879' (2023-09-14)
  → 'github:oxalica/rust-overlay/d5977a020c216526144dbf08ab0825b6c1121593' (2023-10-19)
2023-10-19 18:21:36 +02:00
Julian Stecklina 778e21733b
Merge pull request #196 from nix-community/renovate/all
fix(deps): update all dependencies
2023-10-16 09:03:22 +00:00
Julian Stecklina bb5b2de545 stub: pin goblin (again)
... because of #237. Now renovate should ignore this.
2023-10-16 10:53:56 +02:00
Julian Stecklina ace18ed4bd renovate: ignore goblin updates
... because of #237.
2023-10-16 10:51:59 +02:00
Julian Stecklina 0df60a2b2e
Merge pull request #232 from alois31/insecure-boot
stub: improve handling of insecure boot
2023-10-16 08:29:25 +00:00
Julian Stecklina 01b62a1c21
Merge branch 'master' into insecure-boot 2023-10-16 10:28:28 +02:00
renovate[bot] eabbae0e0c
fix(deps): update all dependencies 2023-10-16 01:54:44 +00:00
Julian Stecklina 82530e530b
Merge pull request #238 from nix-community/goblin-update
stub: pin to current goblin version
2023-10-15 14:47:19 +00:00
Alois Wohlschlager b02a7e2a7f
stub: use command line from loader in insecure mode
When booting without Secure Boot active, it is not necessary to defend
against a malicious command line being passed from the loader. So just
use it in this case, to facilitaty some debugging and recovery use
cases.

Fixes: https://github.com/nix-community/lanzaboote/issues/226
2023-10-15 16:04:30 +02:00
Alois Wohlschlager db39223a7c
stub: make handling of insecure boot more explicit
When Secure Boot is not available (unsupported or disabled), Lanzaboote
will attempt to boot kernels and initrds even when they fail the hash
verification. Previously, this would happen by falling back to use
LoadImage on the kernel, which fails if Secure Boot is available, as the
kernel is not signed.
The SecureBoot variable offers a more explicit way of checking whether
Secure Boot is available. If the firmware supports Secure Boot, it
initializes this variable to 1 if it is enabled, and to 0 if it is
disabled. Applications are not supposed to modify this variable, and in
particular, since only trusted applications are loaded when Secure Boot
is active, we can assume it is never changed to 0 or deleted if Secure
Boot is active.
Hence, we can be sure of Secure Boot being inactive if this variable is
absent or set to 0, and thus treat all hash verification errors as
non-fatal and proceed to boot arbitrary kernels and initrds (a warning
is still logged in this case). In all other cases, we treat all hash
verification failures as fatal security violations, as it must be done
in the case where Secure Boot is active (it is expected that this does
not lead to any false positives in practice, unless there are bigger
problems anyway).
2023-10-15 15:58:01 +02:00
Julian Stecklina c56ad52b18 stub: pin to current goblin version
goblin 0.7.1 introduces certification support for PE files. This seems to be broken, because we get:

Parsing PE failed Malformed entity: Unable to extract certificate. Probably cert_size:1599360838 is malformed!

from goblin when trying to parse our PE file in memory.

See #237 for context.
2023-10-15 15:40:57 +02:00
nikstur 62ffd894f0
Merge pull request #236 from Ma27/includeallmodules
Fix build with `documentation.nixos.includeAllModules = true;`
2023-10-14 18:46:52 +02:00
Maximilian Bosch 16c6776763
Fix build with `documentation.nixos.includeAllModules = true;`
This includes the options of all modules used in the evaluation, not
just the ones from `<nixpkgs/nixos>` in the local manual.

Right now this breaks with

    error: attribute 'loader' missing

    at /nix/store/wf59fvxch3l5s7x0pnpfv7b26q6y010x-source/nix/modules/lanzaboote.nix:26:17:

        25|     configurationLimit = mkOption {
        26|       default = config.boot.loader.systemd-boot.configurationLimit;
          |                 ^
        27|       example = 120;

I'm not sure what's up with `config.boot.loader` (had the exact same
issue with `disko`), but using `defaultText` is the common workaround
for that.
2023-10-13 22:35:58 +02:00
nikstur c865873ff5
Merge pull request #235 from nix-community/uefi-update
stub: update to latest uefi crates
2023-10-12 21:36:01 +02:00
Julian Stecklina 17cadf6598 stub: update to latest uefi crates 2023-10-12 12:12:34 +02:00
nikstur ac43ac3024
Merge pull request #204 from alois31/no-overwrite
Stop most overwriting in the ESP
2023-10-04 11:07:38 +02:00
Alois Wohlschlager a78b9682b7
docs: Improve troubleshooting documentation
Due to the temporarily doubled ESP space usage, it is now easier to run
into the out of space issue (once). Document how to proceed in this case
without having to delete any generations.

Furthermore, recovery in case of ESP corruption is now slightly more
involved, because not all files are rewritten all the time. Adjust the
documentation accordingly.
2023-10-04 07:29:35 +02:00
Alois Wohlschlager 90a1adac54
tool: fix atomic write
Atomic write works by first writing a temporary file, then syncing that
temporary file to ensure it is fully on disk before the program can
continue, and in the last step renaming the temporary file to the
target. The middle step was missing, which is likely to lead to a
truncated target file being present after power loss. Add this step.

Furthermore, even with this fix, atomicity is not fully guaranteed,
because FAT32 can become corrupted after power loss due to its design
shortcomings. Even though we cannot really do anything about this case,
adjust the comment to at least acknowledge the situation.
2023-10-04 07:29:35 +02:00
Alois Wohlschlager 4fd37670e2
tool: stop most overwriting in the ESP
Since most files (stubs, kernels and initrds) on the ESP are properly
input-addressed or content-addressed now, there is no point in
overwriting them any more. Hence we detect what generations are already
properly installed, and don't reinstall them any more.

This approach leads to two distinct improvements:
* Rollbacks are more reliable, because initrd secrets and stubs do not
  change any more for existing generations (with the necessary exception
  of stubs in case of signature key rotation). In particular, the risk
  of a newer stub breaking (for example, because of bad interactions
  with certain firmware) old and previously working generations is
  avoided.
* Kernels and initrds that are not going to be (re)installed anyway are
  not read and hashed any more. This significantly reduces the I/O and
  CPU time required for the installation process, particularly when
  there is a large number of generations.

The following drawbacks are noted:
* The first time installation is performed after these changes, most of
  the ESP is re-written at a different path; as a result, the disk usage
  increases to roughly the double until the GC is performed.
* If multiple generations share a bare initrd, but have different
  secrets scripts, the final initrds will now be separated, leading to
  increased disk usage. However, this situation should be rare, and the
  previous behavior was arguably incorrect anyway.
* If the files on the ESP are corrupted, running the installation again
  will not overwrite them with the correct versions. Since the files are
  written atomically, this situation should not happen except in case of
  file system corruption, and it is questionable whether overwriting
  really fixes the problem in this case.
2023-10-04 07:29:21 +02:00
Alois Wohlschlager ca070a9eec
tool: make stubs input-addressed
The stubs on the ESP are now input-addressed, where the inputs are the
system toplevel and the public key used for signature. This way, it is
guaranteed that any stub at a given path will boot the desired system,
even in the presence of one of the two edge-cases where it was not
previously guaranteed:
* The latest generation was deleted at one point, and its generation
  number was reused by a different system configuration. This is
  detected because the toplevel will change.
* The secure boot signing key was rotated, so old stubs would not boot
  at all any more. This is detected because the public key will change.

Avoiding these two cases will allow to skip reinstallation of stubs that
are already in place at the correct path.
2023-10-03 22:08:10 +02:00
Alois Wohlschlager 240914d763
tool: make kernels and initrds content-addressed
Kernels and initrds on the ESP are now content-addressed. By definition,
it is impossible for two different kernels or initrds to ever end up at
the same place, even in the presence of changing initrd secrets or other
unreproducibility.

The basic advantage of this is that installing the kernel or initrd for
a generation can never break another generation. In turn, this enables
the following two improvements:
* All generations can be installed independently. In particular, the
  installation can be performed in one pass, one generation at a time.
  As a result, the code is significantly simplified, and memory usage
  (due to the temporary files) does not grow with the number of
  generations any more.
* Generations that already have their files in place on the ESP do not
  need to be reinstalled. This will be taken advantage of in a
  subsequent commit.
2023-10-03 22:08:03 +02:00
nikstur bccf7738d5
Merge pull request #233 from alois31/troubleshooting-docs
docs: Add troubleshooting documentation
2023-10-03 22:06:18 +02:00
Alois Wohlschlager 7b4d1250b7
docs: Add troubleshooting documentation
Running out of space on the ESP is an error that commonly happens.
Document how to proceed in this case.

Furthermore, in case the ESP gets corrupted, the system needs to be
recovered. Document how to do this.
2023-10-03 21:08:12 +02:00
Ryan Lahfa 8154cef11c
Merge pull request #230 from nix-community/ukify 2023-09-29 23:00:32 +02:00
Ryan Lahfa 9d1f7603ab
Merge pull request #231 from SuperSandro2000/fix-eval-no-aliases 2023-09-29 22:36:22 +02:00
Sandro Jäckel d5e6d91b4f
Fix eval in flakes when aliases are disabled 2023-09-29 22:31:47 +02:00
Raito Bezarius a55db483fb nix/modules/uki: fix ukify build
Previously, we were not on recent enough nixpkgs to see the new `withBootloader` flag
which is required to build ukify.

Fixes the test.
2023-09-29 20:07:42 +02:00
Ryan Lahfa 644dc8a269
Merge pull request #31 from nix-community/aarch64 2023-09-29 02:41:12 +02:00
Raito Bezarius 7951cbc668 flake: bump to get systemd v254
With systemd v254, we get valid AA64 EFI binaries from systemd!
2023-09-29 02:40:26 +02:00
Raito Bezarius 976faf9bf5 flake: use proper uefi target in general
Remove the x86_64 hardcoding.
2023-09-14 16:55:18 +02:00
nikstur 0b5ce324d7 tool: clean up a few minor details 2023-09-14 16:35:53 +02:00
nikstur 3bf55f92b8 test: clean up a few minor details 2023-09-14 16:35:53 +02:00
Raito Bezarius f81c30d7d9 module: use kernel package hostPlatform if nixpkgs.hostPlatform is not available
Sometimes, it is not…
2023-09-14 16:35:53 +02:00
Raito Bezarius 1330292008 tool/systemd: make clippy happy I guess 2023-09-14 16:35:53 +02:00
Raito Bezarius 0107754d62 tool(architecture): make it generic
Architecture is now a generic structure that can be specialized
via an "external" trait for generating the paths you care about
depending on your target bootloader.
2023-09-14 16:35:53 +02:00
Raito Bezarius 609c11f26d tool(systemd-boot): install it once instead of checking for each generation
systemd-boot is now installed once for many generations rather than multiple times.

This means it is not really possible to manage different system in the same "machine", which is a very
obscure usecase, theoretically possible, but not yet encountered.
2023-09-14 16:35:53 +02:00