Sign kernel modules and enable kernel lockdown #88
Labels
No labels
bug
dependency
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
review-next
security
stub
tool
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: raito/lanzaboote#88
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Once secureboot is enabled, it is possible to lock down the kernel, although module signing is disabled by default ( https://github.com/NixOS/nixpkgs/blob/nixos-22.11/pkgs/os-specific/linux/kernel/common-config.nix#L514-L517 ). Furthermore, it is possible to feed a custom key for signing the kernel and its modules ( https://www.kernel.org/doc/html/v4.15/admin-guide/module-signing.html ), which we could use the secureboot keys for. It would also allow for the signature of other kernel modules (e.g. virtualbox's kernel modules).
If we can separate module signing in to a separate derivation, we could probably implement a signing derivation and a verification derivation here.
Wouldn't signing the modules as part of a derivation leave the signing key exposed in the Nix store? Ideally we would find a way to sign the kernel modules on
nixos-rebuild
.This could be signed outside the
nix-store
andnix-store --import
ed into it.My remark was thinking also about the case where NixOS starts shipping kernel binaries with signed modules.
I think it would be good to enable verification of those when substituting them.
We can leak the signing key through an ugly
builtins.getEnv
and impure env vars, protected behind arequiredFeatures
to enable specific machines to perform the signature with the help of a local TPM or whatever.I think your idea @baloo is not mutually exclusive, we can requireFile, but we need to know hashes (in advance, right?) because this is a FOD then.
Debian does it this way: https://salsa.debian.org/ftp-team/code-signing/-/blob/master/secure-boot-code-sign.py#L163-L201
From the code it almost looks like they support detached signatures. That would be neat, because we could sign everything at
nixos-rebuild
time. But the docs imply that the signatures are embedded.The other 💩 is that the public key that Linux trusts needs to be baked into the kernel at build time. It would be really neat to hand this over from the boot loader.
Could we generate detached module signatures using kmodsign outside the store, import them into the store and concatenate them with existing modules? kmodsign.1
Can't we use a machine owner key to sign the modules locally?
Mmh. Ideally, I would like to have detached signatures and we don't have to reimport anything into the nix store. But I'm not sure this is feasible. In any case, I currently don't really have time to play around with this. But if someone else is willing to produce a PoC of signed kernel modules and kernel lockdown that would really help things along here.
I think secure boot keys are also trusted. See the logic in https://github.com/torvalds/linux/blob/master/security/integrity/platform_certs/load_uefi.c.
Signatures are simply concatenated to the .ko file. It might be possible to patch
kmod
to support detached signatures.Oh great, then, we are reduced to solve the problem of passing the Secure Boot signer in the Nix derivation for the kernel for those who really want to use signed kernel modules. That's nice!
debian had a patch on modprobe (I think that was modprobe, could be another one) for a while to support detached signature.
A solution we will be able to make use of is sitting in a patch series in the kernel MLs: https://lore.kernel.org/all/20250120-module-hashes-v2-0-ba1184e27b7f@weissschuh.net/.
Does that solution allow adding additional hashes at signing time for out-of-tree modules?
In principle it's just an array of module hashes, anything can go into it. However, the current patch-series embeds only the hashes of modules built as part of the Linux kernel into that array...
I also played with externallay signed modules in order to enable lockdown and fips mode together with out-of-tree modules. Feel free to comment on my rough sketch in https://github.com/NixOS/nixpkgs/pull/401493. This can't be enabled by default due to reproducibility issues but is nevertheless sometimes useful IMHO.