kernel recompilation for better hardening

https://github.com/Whonix/hardened-kernel/pull/25

https://github.com/Whonix/hardened-kernel/pull/26

madaidan via Whonix Forum:

Disable profiling support by madaidan · Pull Request #25 · Kicksecure/hardened-kernel · GitHub

Merged.

1 Like

madaidan via Whonix Forum:

security-misc enables it after X starts which isn’t as good as having it enabled all the time.

I see. Maybe better add this as a sysctl, in a package that gets only
installed inside VMs? (then it would also be enabled in initramfs
already) Reason is that this would be way more easy to disable / debug /
port.

Do we have other (security) settings too which are VM-only?

Do we have other (security) settings too which are host-only?

Also we yet have to create security-paranoid(opt-in package for settings
which are too experimental for security-misc default package?

1 Like
1 Like

hardened-kernel 0.8-1 on Non-Qubes-Whonix Whonix-Gateway and Whonix-Workstation.

DKMS does not run during linux kernel package upgrade. Therefore after reboot LKRG and tirdad no longer functions.

Jan 15 13:36:06 host modprobe[213]: modprobe: ERROR: could not insert ‘p_lkrg’: Exec format error

Workaround until DKMS will be properly run after kernel package upgrade:

sudo apt install --reinstall lkrg-dkms tirdad-dkms

Tirdad is fixed after that procedure.

DKMS might not run since the package is installed directly by dpkg and not through APT?

Next issue after reboot:

sudo modprobe p_lkrg

modprobe: ERROR: could not insert ‘p_lkrg’: No buffer space available

1 Like

Users can set kernel.panic_on_oops=0 if they need to disable it.

Not really.

That isn’t really needed since we can just add those settings to security-misc but make them opt-in.

madaidan via Whonix Forum:

Fix debug build by madaidan · Pull Request #27 · Kicksecure/hardened-kernel · GitHub

Merged.

1 Like

madaidan via Whonix Forum:

Users can set kernel.panic_on_oops=0 if they need to disable it.

I see. That is good enough.

I was previously (probably falsely) assuming that this value would then
be hardcoded and users would need to recompile the kernel.

That isn’t really needed since we can just add those settings to security-misc but make them opt-in.

I.e. instruct users to copy from one place to another?

1 Like

No, this doesn’t get rid of the kernel.panic_on_oops sysctl.

No, as in telling them to do things like enable certain systemd services (e.g. hide-hardware-info) or uncomment certain lines (e.g. disabling SACK).

1 Like

Randomly found a message from Daniel Micay which talks about what kernel versions to use for security which is pretty relevant.

DanielMicay comments on GrapheneOS - an open source privacy and security oriented mobile OS with Android app compatibility

Relevant parts:

It’s important to follow along with the latest longterm / stable releases of the Linux kernel and the more recent branches are usually better choices because backporting is increasingly incomplete for the older branches. However, new kernel branches also have more attack surface and newer features / code that are less battle hardened. Of the supported upstream kernels (https://www.kernel.org/), I would go with 4.14 and soon 4.19 when it’s a little bit more mature. In terms of out-of-tree drivers, as long as they’re open source (they are), the only real sense it matters is acting as a blocker for migrating to newer LTS branches. Look at which branch grsecurity - Download uses for the production variant.

There are both security advantages (new security features, more bug fixes applied) and disadvantages (more attack surface, more complexity, more new bugs) to using a more recent kernel branch. I think the best choice for overall security is usually the most recent LTS branch, once it has been available for a bit, so the best choice would likely be the 4.19 LTS at the moment. There’s so much churn and so many regressions when following mainline even just in terms of what people run into during regular use and it certainly applies to the underlying security properties of the kernels.

It seems like we’re using the best kernel version (currently 4.19).

2 Likes

This is awesome! Thanks @madaidan! This will help to get more eyes on it and result in wider exposure / better testing.

2 Likes

I had archives in git repository and no download on user’s machine implemented but github crossed out my plans when trying to git push.

remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 980557540f5f13fe7ad779afff4213be
remote: error: See Managing large files - GitHub Docs for more information.
remote: error: File usr/src/hardened-kernel/files/linux-4.19.93.tar is 801.99 MB; this exceeds GitHub’s file size limit of 100.00 MB

Various options come to mind as a solution… No amazing option yet will keep looking…

1 Like

How did you come to that conclusion? I can’t find any documentation by hardened-linux.

2 Likes
git clone --depth=1 https://github.com/anthraxx/linux-hardened.git
cd linux-hardened
git fetch origin tag --depth=1 --no-tags 4.19.96.a
git verify-tag 4.19.96.a
git verify-commit 4.19.96.a^{commit}
git checkout 4.19.96.a
git branch 4.19.96.a

That should be as good as kernel archive from kernel.org + linux-hardened patch? Should b really the same?

Upon reflection… Maybe not fork linux-hardened. Just git clone and checking out the git tag which were are interested in. Then add linux-hardened as a git submodule to our hardened-kernel. That is because linux-hardened has .gitignore folder which contains the /debian folder and make deb-pkg creates the /debian folder. That conflicts with our hardened-kernel packaging. Rather than hack around that it seems better to not touch linux-hardened (except checkout proper version) and use a git submodule. Even though git submodules don’t have the best usability that would get the task done.

2 Likes

Upload the .tar.xz and instead of the .tar file.

madaidan via Whonix Forum:

Upload the .tar.xz and instead of the .tar file.

That might even work for now but it’s not a future proof solution. Linux
tarball seems to be growing. Breaking the 100 MB border soon.

97M linux-4.14.165.tar.xz
105M linux-5.4.12.tar.xz
167M linux-5.5-rc6.tar.gz

That would break with Linux 5.x series. And I’d rather not implement
something that will need changes soon.

kernel recompilation for better hardening - #216 by madaidan

I see. Well, arch linux might have different requirements.

1 Like
2 Likes
1 Like