paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.85k stars 674 forks source link

Research more PVF worker hardening methods #618

Closed eskimor closed 8 months ago

eskimor commented 1 year ago

E.g. basic things like stack layout randomization or Kernel space layout randomization or the currently being deployed landlock and seccomp up to full virtualization. Just to name some examples, surely more hardening options exist. Compiling a list and checking what would be useful for us would make sense. Kernel space layout randomization is something to go into the wiki for operators to enable, others might be implementable by us. In any case, we should make exploits as hard as reasonably possible - an exhaustive list of options should be a good start. Then exploring those, downsides, implementation effort, feasibility, security impact, ..

https://en.wikipedia.org/wiki/Address_space_layout_randomization

burdges commented 1 year ago

Isn't this imposed by modern linux?

eskimor commented 1 year ago

Could be, I did not do any deep research. The resources I found, suggested it might not. Anyhow, this just serves as an example. Point being, I think it is worth looking into what is available in general and deploy anything that is easy/uncontroversial for us and makes attacks harder.

sandreim commented 1 year ago

Maybe we could also look into recommending certain Linux distros that have better security posture/features enabled by default. It would be easier than taking whatever distro anyone installs and customizing it to meet our recommendations.

burdges commented 1 year ago

You can warn if cat /proc/sys/kernel/randomize_va_space reports less than 2. https://stackoverflow.com/questions/11238457/disable-and-re-enable-address-space-layout-randomization-only-for-myself

There are some details here like whether the kernel itself has address space layout randomization and likely more, not really sure.

koute commented 1 year ago

Here's some more Linux-specific hardening options we could use, besides the currently attempted seccomp (which for now is still wholly incomplete):

(Source: I've recently been working on sandboxing for our new upcoming RISC-V smart contracts VM where I'm doing all of this by default.)

mrcnski commented 1 year ago

Nice ticket. I've previously looked into ASLR. rustc tries to emit hardened binaries where possible: https://doc.rust-lang.org/rustc/exploit-mitigations.html

Still, could be worth running an extra check for it: https://github.com/paritytech/polkadot-sdk/issues/637

(Source: I've recently been working on sandboxing for our new upcoming RISC-V smart contracts VM where I'm doing all of this by default.)

Nice, will try to implement these measures.

mrcnski commented 1 year ago

Maybe we could also look into recommending certain Linux distros that have better security posture/features enabled by default. It would be easier than taking whatever distro anyone installs and customizing it to meet our recommendations.

Could be a discussion worth having. One problem is it would be a big change to impose on validators. And lots of them run on cloud providers and have limited options for distro, kernel version, security features, etc.

koute commented 1 year ago

Nice, will try to implement these measures.

I will be releasing the sources to my VM soon-ish (still need to finish some refactoring); I'll ping you once I do and maybe you could reuse some of my code.

Could be a discussion worth having. One problem is it would be a big change to impose on validators. And lots of them run on cloud providers and have limited options for distro, kernel version, security features, etc.

Yeah, I don't think it would be acceptable to have a hard requirement of a very new kernel and/or userland. That said, there's a balance to be struck here. I essentially see five levels of "old" here:

Some useful links:

koute commented 1 year ago

I've also found a huge list of other potential system-wide mitigations: https://madaidans-insecurities.github.io/guides/linux-hardening.html

Not everything there is necessarily a good idea (in fact, some of the stuff there we don't want), but we could use some of that info to write our own guide.

mrcnski commented 1 year ago

@koute that looks really good! BTW, we do seem to have our own guide already here, though I'm not sure how many users follow it.

Also, we should perhaps be careful not to burden validators too much with requirements. I mean, the rabbithole of security is never-ending, and we should decide what is the cutoff for acceptable security and not impose more on validators beyond that. Maybe providing a pre-configured image is an option?

koute commented 1 year ago

Maybe providing a pre-configured image is an option?

Hm, well, how would that work in practice? People usually just rent a VM with an already installed system and don't install it themselves.

Maybe having an e.g. a sanctioned supported Linux distribution (e.g. Debian or Ubuntu) and providing a setup script for that distro which would automatically harden it would be the way to go here? Because doing all of this stuff manually is not going to be doable for the majority of people, but picking a specific distro and running a single script would.

Of course this should not be a hard requirement; in the end it's the end user's responsibility over what they're running, and we shouldn't unduly burden those people who don't want to (or can't) harden their systems. But we could e.g. detect which exact mitigations are enabled and which aren't and print out a warn!ing or something like that.