kernel recompilation for better hardening

Quote Whonix Collaboration · Issue #1 · dapperlinux/dapper-secure-kernel-patchset · GitHub

As for some patches, there is a portable and ready to use version of PAX_RAP, a
gcc plugin that implements forward and backword edge control flow integrity
sitting in the VMware Photon repo:

https://github.com/vmware/photon/blob/master/SPECS/linux/0003-Added-rap_plugin.patch

They have some other stuff too, like PAX_RANDKSTACK:

https://github.com/vmware/photon/blob/master/SPECS/linux/0002-Added-PAX_RANDKSTACK.patch

All their stuff is worth checking out:

photon/SPECS/linux at master · vmware/photon · GitHub

Funny you should mention ClipOS. I remember when it first came out, since they
were using the grsecurity 4.9 patchset. They also had a bunch of cool patches,
although most of them got archived when they dropped grsecurity from their
primary repo. They also never switched to using my
dapper-secure-kernel-patchset-stable either, although its easy to see why,
since its difficult to trust some random developer with something security
critical as a kernel hardening patchset.

Anyway, I haven’t read much of the things they carry in their repos these days.
Its probably pretty good though.

Other things you can easily put into your kernel are the GRKERNSEC_CHROOT_*
features. Those patches are self contained and can be easily extracted from
a grsecurity patchset. They are low risk, stable, and provide good additional
hardening of chroots, although I suppose no one trusts the security of
chroots these days, and we all use namespaces instead.

Other than that, try and enable all the GCC plugins, and set lockdown to
confidentiality and integrity mode.

1 Like

The vboxvideo module wasn’t removed. Read the pull request description.

This won’t break anything.

We distrust these for initial entropy (CONFIG_RANDOM_TRUST_CPU). Being built-in/module doesn’t trust/credit it more.

The same advantage as building in the jitterentropy module. Entropy starts being generated earlier rather than need to wait for it to be loaded.

Yes.

See CONFIG_RANDOM_TRUST_CPU.

1 Like

CONFIG_RANDOM_TRUST_CPU / random.trust_cpu is for CPU, not for hardware rng?

2 Likes

Ah, I assumed the HWRNG was in the CPU but it turns out these ones are on the motherboard (see linux/Kconfig at master · torvalds/linux · GitHub) so it is probably trusted.

Either way, the entropy would be trusted regardless if it’s built-in/module. The only difference is that being built-in means it generates entropy earlier.

2 Likes

For these might be better to load later than earlier. Or keep defaults Could even consider distrusting / not crediting. If that is even possible. Could even consider blacklisting. Requires more research.

2 Likes

How? It’d just be delaying entropy.

The “real” HWRNGs are the only ones that would need to be distrusted. virtio-rng isn’t an actual HWRNG.

The best solution seems to be to have them all built-in but distrust the real HWRNGs.

Btw can you merge the staging drivers pull request? I’m going to make more changes but they might conflict.

1 Like

I think these HWRNGs actually are in the CPU.

https://www.amd.com/system/files/TechDocs/amd-random-number-generator.pdf

In the kernel it’s only described as “AMD Random Number Generator” and the only things I can find about this RNG is in the CPU.

Hence, CONFIG_RANDOM_TRUST_CPU does distrust these HWRNGs and we can use them without worry.

2 Likes

Delay yes but also give better chance that initial entropy after boot is from more trustworthy sources. Or at least following what most are doing (compile as module). And not going a special way. The potential issues over weight the potential gain here.

Reverted for now until we have more input. For something as sensitive as this, shouldn’t move fast.

virtio-rng is non-controversial indeed. Built-in seems a good idea.

Need more time for review.

Wondering how much hardware support would break and how important these devices are. Breaking a popular wifi device would not be great (if that is the case).

Also the threat model. Is it mostly about preventing untrusted root from loading potentially vulnerable modules to exploit these?

1 Like

It’s distrusted via CONFIG_RANDOM_TRUST_CPU anyway. See above. The HWRNGs seem to be in the CPU.

They aren’t popular. Hence why they’re staging drivers and not ordinary drivers. They might not even work anyway.

No, the modules can probably be auto-loaded too. These modules are low quality, are more likely to contain security vulnerabilities and likely won’t be used by an average user.

1 Like

We need higher certainty here.

Linux Kernel Driver DataBase: CONFIG_HW_RANDOM: Hardware Random Number Generator Core support says motherboards, not CPUs:

The configuration item CONFIG_HW_RANDOM:

This driver provides kernel-side support for the Random Number Generator hardware found on Intel i8xx-based motherboards, AMD 76x-based motherboards, and

Autoload for those who have such hardware only or autoload thorough some kind of trick by anyone?

I guess for some this is true for sure such as Linux Kernel Driver DataBase: CONFIG_COMEDI: Data acquisition support (comedi) is not popular indeed. Never heard before.

CONFIG_RTL8192U popular?

1 Like

For baremetal yes, however it makes no sense for VM.

2 Likes

https://www.kernel.org/doc/html/latest/admin-guide/hw_random.html

The hw_random framework is software that makes use of a special hardware feature on your CPU or motherboard, a Random Number Generator (RNG).

The only things I can find about Intel/AMD RNGs are in the CPU.

Not sure. There may be tricks people can use to make it autoload but we can’t really be sure. Would be best to just remove unneeded modules.

Dunno. If it was popular, it probably wouldn’t be a staging driver.

1 Like

Quote Questions on seeeding, value of similar utilities · Issue #16 · smuellerDD/jitterentropy-library · GitHub

Patrick Schleizer:

Hi Patrick,

Would it be useful for our upcoming hardened-kernel / or generally to enable kernel config options CONFIG_CRYPTO_ANSI_CPRNG? (CONFIG_CRYPTO_ANSI_CPRNG=y)

This cipher is not really relevant any more - it is the ANSI X9.31 Appendix A2.4 RNG. The SP800-90A DRBGs are superior to the ANSI equivalent due to covering reseed requirements and similar. I see no reason to have that RNG enabled. Ciao Stephan

How would I know if popular or not?

Yes, makes little sense in VM indeed.

(I wouldn’t say no sense at all maybe one day Whonix-Workstation could serve as a torified WiFi hotspot but since that doesn’t exist it is not important enough to consider.)

CONFIG_HW_RANDOM_VIA (was included in pull request) is in the motherboard.

Quote Linux Kernel Driver DataBase: CONFIG_HW_RANDOM_VIA: VIA HW Random Number Generator support

This driver provides kernel-side support for the Random Number Generator hardware found on VIA based motherboards.

One good point:

If unsure, say Y.

Asked just now if that would be a good idea:

Questions on seeeding, value of similar utilities · Issue #16 · smuellerDD/jitterentropy-library · GitHub

1 Like

Got reply.

smuellerDD:

Am Dienstag, 25. Februar 2020, 07:36:52 CET schrieb Patrick Schleizer:

Hi Patrick,

We are using kernel command line random.trust_cpu=off to distrust / not
credit randomness sourced from CPU’s RDRAND.
(rationale)

Now we are wondering about the following kernel compile configuration
changes:

Old:

CONFIG_HW_RANDOM=m
CONFIG_HW_RANDOM_INTEL=m
CONFIG_HW_RANDOM_AMD=m
CONFIG_HW_RANDOM_VIA=m

New:

CONFIG_HW_RANDOM=y
CONFIG_HW_RANDOM_INTEL=y
CONFIG_HW_RANDOM_AMD=y
CONFIG_HW_RANDOM_VIA=y

Would that be a good idea?

For starters, this is the hardware RNG framework making hardware RNGs
accessible via /dev/hwrand (code residing in drivers/char/hw_random).

The Intel RNG is a different RNG than RDRAND, but I am not fully sure which
hardware component would provide it (I guess some form of chipset that even
provides the QAT hardware crypto system).

If a HW RNG driver sets the struct hwrng->quality integer (which defines that
it provides entropy), the HW RNG framework will deliver entropy via
add_hwgenerator_randomness to /dev/random. Otherwise the /dev/random is not
affected by the HW RNG framework and its drivers.

Just do a grep quality in the drivers dir to see which drivers set a value and
thus would increase the entropy in /dev/random. Then decide for yourself
whether you want that.

(Presumption is: “don’t trust/credit hwrng such as RDRAND but mix it into
the randomness pool”.
([rationale](Entropy, Randomness, /dev/random vs /dev/urandom, Entropy Sources, Entropy Gathering Daemons, RDRAND
om)))

Would that contradict random.trust_cpu=off?

As stated above, it would not contradict it as the noise source would be
completely different (dedicated hardware).

Does random.trust_cpu=off cover hardware random generators that are
located at the motherboard and not inside the CPU? (CONFIG_HW_RANDOM_VIA
says it is on the motherboard.)

No.

Is CONFIG_HW_RANDOM_INTEL “same as” RDRAND?

No, see above.

In other words, would
CONFIG_HW_RANDOM_INTEL=n result in disabling RDRAND? (I am not
suggesting to configure CONFIG_HW_RANDOM_INTEL=n. This is just for better
understanding.)

My worry is that by having these hardware random generators load earlier
than the module could be load could result in the initial random seeding to
be more likely compromised if these hardware randomness generators are
flawed / predictable / backdoored.

Ciao
Stephan

2 Likes

Anecdotally I am seeing Realtek Wifi in a bunch of laptops across different brands.

Also Wikipedia indicates it has major marketshare though those stats are a bit dated :

Notable Realtek products include 10/100M Ethernet controllers (with a global market share of 70% as of 2003) and audio codecs (AC’97 and Intel HD Audio), where Realtek had a 50% market share in 2003 and a 60% market share in 2004, primarily concentrated in the integrated OEM on-board audio market-segment.[3] As of 2013 the ALC892 HD Audio codec and RTL8111 Gigabit Ethernet chip have become particular OEM favorites

1 Like

Just because Realtek in general is popular doesn’t mean the RTL8192U driver is. Realtek makes plenty of chips.

1 Like

CONFIG_EFI_VARS might be good to disable in the host kernel. It exposes a lot of attack surface as it allows you to mess with EFI variables.

linux/Kconfig at master · torvalds/linux · GitHub

There have been cases of people bricking their computers by accidentally deleting EFI variables. An attacker might be able to do far more by writing specific things to them.

CLIP OS disables this.

src_platform_config-linux-hardware/blacklist at master · clipos/src_platform_config-linux-hardware · GitHub

There are also the CONFIG_DEV_COREDUMP, CONFIG_WANT_DEV_COREDUMP and CONFIG_ALLOW_DEV_COREDUMP options.

linux/Kconfig at master · torvalds/linux · GitHub

These seem to add a “device coredump” thing regardless of CONFIG_COREDUMP (which we disable).

1 Like

Also, instead of trying to patch out dmesg, we can try just disabling CONFIG_PRINTK.

1 Like