kernel recompilation for better hardening

CI build failing.

1 Like

I can’t tell what’s causing this. Can you?

1 Like

Happening when using --debug with environment variable CI=true being set.

+ true 'Sanity test. '\''make oldconfig'\'' should not modify '\''.config'\''.'
+ true https://forums.whonix.org/t/kernel-recompilation-for-better-hardening/7598/317
+ make oldconfig -C /var/lib/hardened-kernel/hardened-vm-kernel/linux-4.19.122/
...
+ diff /home/travis/build/Whonix/hardened-kernel/usr/share/hardened-kernel/hardened-vm-kernel /var/lib/hardened-kernel/hardened-vm-kernel/linux-4.19.122//.config

diff then exits non-zero.

See the diff.

diff /home/travis/build/Whonix/hardened-kernel/usr/share/hardened-kernel/hardened-vm-kernel /var/lib/hardened-kernel/hardened-vm-kernel/linux-4.19.122//.config

.

> # CONFIG_GENERIC_IRQ_DEBUGFS is not set
286a288
> # CONFIG_IOSF_MBI_DEBUG is not set
292a295
> # CONFIG_QUEUED_LOCK_STAT is not set
300a304
> # CONFIG_XEN_DEBUG_FS is not set
302a307
> # CONFIG_KVM_DEBUG_FS is not set
344a350
> # CONFIG_X86_MCE_INJECT is not set
488a495
> # CONFIG_ACPI_CUSTOM_METHOD is not set
496a504
> # CONFIG_ACPI_APEI_EINJ is not set
685c693
< # CONFIG_KPROBES is not set
---
> CONFIG_KPROBES=y
687a696
> CONFIG_OPTPROBES=y
689a699
> CONFIG_KRETPROBES=y
758a769
> # CONFIG_GCOV_KERNEL is not set
802a814,815
> CONFIG_BLK_DEBUG_FS=y
> CONFIG_BLK_DEBUG_FS_ZONED=y
1500a1514
> # CONFIG_ZRAM_MEMORY_TRACKING is not set
2079a2094
> # CONFIG_NETDEVSIM is not set
3718a3734
> # CONFIG_SW_SYNC is not set
3895a3912
> # CONFIG_IOMMU_DEBUGFS is not set
3989a4007
> # CONFIG_RAS_CEC is not set
4019a4038
> # CONFIG_INTEL_TH_DEBUG is not set
4616a4636
> # CONFIG_DYNAMIC_DEBUG is not set
4632c4652
< # CONFIG_DEBUG_FS is not set
---
> CONFIG_DEBUG_FS=y
4733a4754
> CONFIG_FUNCTION_ERROR_INJECTION=y
4749a4771
> # CONFIG_LKDTM is not set
4751a4774
> # CONFIG_KPROBES_SANITY_TEST is not set
4808a4832
> # CONFIG_DEBUG_BOOT_PARAMS is not set

That should not be happening.

Running

make oldconfig -C "$extracted_linux_kernel_sources_folder"

should not be modifying "$extracted_linux_kernel_sources_folder/.config" "${MYDIR}/${kernel_config}" should already be in a state where a later make oldconfig would do nothing. That is to make the process “less magic”. Less auto generated. Easier to review. More predictable. Allow reviewers to review to full kernel configuration. No implicit filling the blanks during compilation. Solution? Run make oldconfig yourself, review, and update config in git. Make make oldconfig out of work.

Build history reveals that this is only happening since Fix issue with compiling host kernel by madaidan · Pull Request #55 · Kicksecure/hardened-kernel · GitHub was merged.

But I don’t see how that pull request could have caused that since it’s opt in and not used on CI.

1 Like

The sanity check runs after the kprobes/ftrace configs are appended: hardened-kernel/usr/share/hardened-kernel/build at 629b62475455ce5ef073e6ba8b970ea76ade88a0 · Kicksecure/hardened-kernel · GitHub

make oldconfig will then shift those configs about to put them in the correct order in the full file. The sanity test must run before those options are added.

The build for that passed though? It seems to fail because of Optionally enable kprobes/ftrace for LKRG support · Kicksecure/hardened-kernel@629b624 · GitHub

1 Like

Indeed.

That sanity test runs if [ "$debug" = "true" ]; then. It is nested in another IF. if [ "$CI" = "true" ]; then. Btw I don’t see why that should be nested. (Perhaps was implemented this way because CI build uses --debug anyhow.)

Could run that sanity test outside of if [ "$debug" = "true" ]; then and earlier. I’ll try that now.

No. On Optionally enable kprobes/ftrace for LKRG support · Kicksecure/hardened-kernel@629b624 · GitHub the red X indicates a failed Travis CI build. I should have noticed this earlier.

Seems like. But I understand how it can be the cause since it added an opt-in. Didn’t changed actual execution on CI.

1 Like

Now I get why this was happening on CI. --debug results in kprobes="true".

That CI issue seems now fixed. Build hasn’t completed yet but it’s past that issue.


Another thing…


if [ "${kprobes}" = "true" ]; then
  cat "${MYDIR}/kprobes-ftrace" >> "$extracted_linux_kernel_sources_folder/.config"
fi

We don’t run make oldconfig -C "$extracted_linux_kernel_sources_folder".


vs


   cat "${MYDIR}/debugging-config" >> "$extracted_linux_kernel_sources_folder/.config"
   if [ "${kernel_config}" = "hardened-host-kernel" ]; then
     cat "${MYDIR}/debugging-config-host" >> "$extracted_linux_kernel_sources_folder/.config"
   fi
   make oldconfig -C "$extracted_linux_kernel_sources_folder"

We do run make oldconfig -C "$extracted_linux_kernel_sources_folder".


Does that look alright?

1 Like

It shouldn’t be too important but running make oldconfig wouldn’t hurt. It’ll rearrange the file properly before build but this isn’t required.

1 Like
1 Like

linux-hardened’s FORTIFY_SOURCE_STRICT_STRING has been implemented upstream.

2 Likes

CONFIG_KFENCE is a Low-Overhead Memory Safety Feature introduced in Linux 5.12 that is more competent than the KASAN. Used for uncovering similar out-of-bounds / use-after-free / invalid-free errors but with no overhead.

2 Likes
1 Like

hi a different function and greater security
some guys shared a topic : firejail / seccomp / More Options for Program Containment
there is a security patch Landlock : Landlock: unprivileged access control

CONFIG_SECURITY_LANDLOCK=y

tried a sandbox inside another sandbox ./landlock1 /bin/sh firejail *application

With the exploits and bypasses that there are lately,
I believe that greater security is necessary

Theory : Apparmor > Landlock > Firejail > Tor browser

Kernel Patch Hardening : https://patchwork.kernel.org/project/kernel-hardening/list/

1 Like

Landlock currently isn’t in mainline; it’s only in linux-next: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/Documentation/userspace-api/landlock.rst?h=next-20210319&id=f00397ee41c79b6155b9b44abd0055b2c0621349

When it does land in mainline, it will be a very long time before it reaches LTS and besides, I don’t see a significant advantage of this over AppArmor + bubblewrap. Landlock is intended for use cases in which the user does not have the adminstrator privileges necessary to configure traditional security policies like AppArmor which does not apply to us.

Combining a whole bunch of different access control mechanisms would be redundant — it’s the same kernel enforcing all of these policies and a single kernel exploit can bypass all of them. Unless Landlock exposes the ability to restrict something that isn’t already covered by our current approach, I don’t see an advantage.

1 Like
1 Like

New CONFIG options in 5.9 we can enable:
https://outflux.net/blog/archives/2021/04/05/security-things-in-linux-v5-9/

Guide on configuring Yama’s ptrace restriction levels:

1 Like

The Landlock LSM is now mainlined in 5.13. I wonder if it can be stacked wit the app sandbox we are working on since it too can restrict unprivileged apps.

1 Like

Ryzen 3 has a PSF feature that causes spectre vulns. Trning it off is supported in 5.13, though it’s optional and won’t be a default.

1 Like

See:

2 Likes

As per Consider Pulling in LKRG · Issue #408 · GrapheneOS/os-issue-tracker · GitHub, I believe we should get rid of the --lkrg option and enable CONFIG_KPROBES by default, while also disabling the config options mentioned in the issue to get rid of the attack surface exposed to user space.

Tirdad also requires kprobes:

1 Like

Will also update documentation to reflect this.

1 Like