Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux: provide a pre-made kernel signing key #107524

Closed
wants to merge 1 commit into from

Conversation

Atemu
Copy link
Member

@Atemu Atemu commented Dec 24, 2020

Motivation for this change

Without this, the kernel would generate a random one for us which obviously
isn't reproducible.

nix-build -A linux --check succeeds now!
(Tested at different times with different kernel)

Note: This does not improve or worsen kernel security since we don't enforce
signatures.

Command used to generate key file:

nix run nixpkgs.openssl -c openssl req -new -nodes -utf8 -sha256 -days 36500
-batch -x509 -config x509.genkey -outform PEM -out r13yKey.pem -keyout
r13yKey.pem

x509.genkey:

[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
prompt = no

[ req_distinguished_name ]
O = NixOS
CN = Public reproducibility key, DO NOT TRUST
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@Atemu
Copy link
Member Author

Atemu commented Dec 24, 2020

Not sure why GH thinks @raboof's commit I based off of isn't in staging already but it's the same one that was merged yesterday.

/marvin opt-in
/status needs_reviewer

@marvin-mk2
Copy link

marvin-mk2 bot commented Dec 24, 2020

Hi! I'm an experimental bot. My goal is to guide this PR through its stages, hopefully ending with a merge. You can read up on the usage here.

Without this, the kernel would generate a random one for us which obviously
isn't reproducible.

`nix-build -A linux --check` succeeds now!
(Tested at different times with different kernel)

Note: This does not improve or worsen kernel security since we don't enforce
signatures.

Command used to generate key file:

nix run nixpkgs.openssl -c openssl req -new -nodes -utf8 -sha256 -days 36500 \
-batch -x509 -config x509.genkey -outform PEM -out r13yKey.pem -keyout \
r13yKey.pem

x509.genkey:

```
[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
prompt = no

[ req_distinguished_name ]
O = NixOS
CN = Public reproducibility key, DO NOT TRUST
```
@Atemu
Copy link
Member Author

Atemu commented Dec 24, 2020

Oi, gimme that label back @ofborg.

Looks like the commit was rebased, not merged; rebased.

@ajs124
Copy link
Member

ajs124 commented Dec 24, 2020

I'm not sure I'm in favor of this. I get the reproducibility aspect, but now if someone turns on signature enforcement in their config (e.g. with linuxManualConfig) I'd say it's a reasonable assumption that this would lead to a kernel for which you cannot build modules later and load them. As in, you can only load modules from that kernel build.

As is, this assumption would not be true anymore, in fact anyone could build modules and load them.

Maybe this could be conditional on the relevant signature enforcement options? IIRC the kernel build already uses the module system to do that kind of config matching magic in other places.

@Atemu
Copy link
Member Author

Atemu commented Dec 25, 2020

If your security relies on the kernel build generating a ephemeral key during build, you should enforce its ephermerality rather than assuming it IMO. Perhaps even build your config around CONFIG_MODULE=n.
Also, if you do something custom like that, you're on your own. I can't make sure people's manual configs don't break as an upstream contributor. I can only be expected to make sure Nixpkgs doesn't break.
Might be worth including in the release notes though.

Almost nothing in pkgs uses the module system, linuxManualConfig is passed an attrset of arguments, i.e. features. Most of the kernel config only depends on version and platform with only very few options decided by features' attrs. I could add something there but I think that's meant for big upstream features like Xen or grsecurity.

@raboof
Copy link
Member

raboof commented Dec 25, 2020

Note: This does not improve or worsen kernel security since we don't enforce signatures

I don't think this is strictly speaking true, in theory: we enable SECURITY_LOCKDOWN_LSM by default, and users could be doing "echo 'confidentiality' > /sys/kernel/security/lockdown". Without this PR, this would protect against loading malicious kernel modules. With this PR, it would no longer protect against it, since the attacker could use the private key from the repo to sign their malicious modules.

That said, I think it is also somewhat unlikely people are actually using SECURITY_LOCKDOWN_LSM. Specifically, I think people are unlikely to use SECURITY_LOCKDOWN_LSM on 'regular' NixOS machines: since this feature is intended to protect you even when the attacker has gained root, I think this is a feature you would use on machines where you don't build new kernels on the machine itself, but you'd generate images with something like nixos-generators. In that context you'd probably want to edit your kernel config to only ship the modules you want to be available (and possibly use SECURITY_LOCKDOWN_LSM to protect against loading others, with a private key that doesn't leave the machine that builds images), or indeed just CONFIG_MODULE=n them.

Given this, I think it would be better to disable MODULE_SIG and SECURITY_LOCKDOWN_LSM by default, instead of including a "publicly-known private key" in the repo. I suspect there will be few users actually using the SECURITY_LOCKDOWN_LSM features, and for those who do want it, we can document how to lock down things even better when using Nix. Including a "publicly-known private key" would be surprising for those users, and because of that a dangerous default.

@vikanezrimaya
Copy link
Member

Marvin pinged me, but I don't think this is really ready for review and/or merging, since the discussion around the PR and its consequences is not done yet.

I like the fact that the key explicitly says to not trust it, but should we even introduce potential security pitfalls (as described in earlier comments to this PR) as a sacrifice for reproducibility?

@Atemu does this configuration even boot with signature enforcement? Can an out-of-tree built-by-Nix module (e.g. openrazer drivers) be loaded? Will these modules be signed too? I think this PR needs lots of documentation before it's ready to merge, and before that, I can't say that I would merge this if I had rights to merge. I'll set "awaiting changes" so Marvin wouldn't bother us until the discussion is complete.

/status awaiting_changes

@Atemu
Copy link
Member Author

Atemu commented Dec 26, 2020

By default, there is no security issue here. The kernels built by hydra would be just as insecure as before.
The only potential security issue here exists for people who manually customise and build their own kernels with signature enforcement and rely on the ephermerality of the generated key.
As I said though, it is questionable whether we as upstream should have to worry about breaking such custom configs.

Out of tree module loading should not have changed. I didn't check but logic dictates that, previously, you should not have been able to load OOT modules with signature enforcement because the key required by the kernel was generated during its build process and deleted by the nix-daemon afterwards.
It would theoretically be possible now actually because the key is known and could be passed to the OOT modules' derivations but since enabling signature enforcement wouldn't provide a security benefit anymore, I don't count that.

I'll check if disabling module signatures completely is possible as that is indeed a cleaner solution, builds are running...

@Atemu
Copy link
Member Author

Atemu commented Dec 26, 2020

It works!

I had to disable SECURITY_LOCKDOWN_LSM though, did that do anything on our kernels?

@Atemu
Copy link
Member Author

Atemu commented Dec 26, 2020

Yes it did lock a few things down but, without enforced signatures, you could get access to those anyways because you could insert an arbitrary module so I don't think we'd lose anything.

#107625

@Atemu Atemu mentioned this pull request Dec 26, 2020
10 tasks
@marvin-mk2
Copy link

marvin-mk2 bot commented Dec 29, 2020

Reminder: Please review!

This Pull Request is awaiting review. If you are the assigned reviewer, please have a look. Try to find another reviewer if necessary. If you can't, please say so. If the status is not accurate, please change it. If nothing happens, this PR will be should be put back in the needs_reviewer queue in one day.


Note: This feature is currently broken. The bot will not actually change the status. If you see this message multiple times, please request a status change manually.

@vikanezrimaya
Copy link
Member

I think this is supposed to be closed now, according to the new PR mentioned above, therefore closing.

@Atemu Atemu deleted the r13y/kernel-module-signing-key branch December 31, 2020 07:47
@Atemu Atemu restored the r13y/kernel-module-signing-key branch December 31, 2020 07:47
@Atemu
Copy link
Member Author

Atemu commented Dec 31, 2020

I think it would've gotten closed when staging made it into master.

@Atemu Atemu deleted the r13y/kernel-module-signing-key branch November 26, 2023 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants